GrovePi reading either 0 or 1 on digitalRead

grovepi
faq

#1

Hello,

For some time now I have been playing with using a GrovePi and The Switchdoc Labs Grove Weather Board, for the most part they work very well together. However I getting some strange behaviour when trying to grovepi.digitalRead ports, when running this test script python.

import time
import grovepi

while True:
	try:
		for d in range(2, 9):
			print("Digital Port no_", d, grovepi.digitalRead(d))
			time.sleep(.5)
	except IOError:
		print("Error")

The results I get are below
('Digital Port no_', 2, 1)
('Digital Port no_', 3, 0)
('Digital Port no_', 4, 0)
('Digital Port no_', 5, 1)
('Digital Port no_', 6, 1)
('Digital Port no_', 7, 1)
('Digital Port no_', 8, 0)
('Digital Port no_', 2, 1)
('Digital Port no_', 3, 0)
('Digital Port no_', 4, 0)
('Digital Port no_', 5, 0)
('Digital Port no_', 6, 1)
('Digital Port no_', 7, 0)
('Digital Port no_', 8, 0)

Why do I get mixed results when they should all read 0, with no sensors connect.
SwitchDoc cannot help
Can anyone offer any advise, this only happens with the weatherboad connected

Michael


#2

Hi @whimickrh,

Could you use the pinMode function before calling digitalRead function and then report how it went?
The pinMode function is used in the following example:

Waiting to see if this solved the issue for you.

Cheers!


#3

Hi Robert,

Thanks for your recent reply; I have tried the other method you suggested,
pinMode function before calling digitalRead function, and this produced the same results.
I was hoping to borrow my friend’s board to test that as well, unfortunately I was not able to do so.

Have you any further thoughts?
Michael


#4

HI Robert,

I was able to borrow my friends Grove Weatherboard, and the results were the same

when I used this script.

#!/usr/bin/python

import time
import grovepi
import smbus
import RPi.GPIO as GPIO

rev = GPIO.RPI_REVISION
if rev == 2 or rev == 3:
	bus = smbus.SMBus(1)
else:
	bus = smbus.SMBus(0)

GPIO.setwarnings(False)

while True:
	try:
		for d in range(2, 9):
			print("Digital Port no_", d, grovepi.digitalRead(d))
			time.sleep(.5)
			grovepi.pinMode(d, "INPUT")
			print("Digital Port no_", d, grovepi.digitalRead(d))
	except IOError:
		print("Error")

The only way to get 0’s was to completely remove the Board, and then it still read 1’s for about 20 seconds before returning 0’s

Have you any thoughts out the problem?

Happy Christmas
Michael


#5

Hi

Happy new year

Have you had time to look at this problem?

Many Thanks
Michael


#6

Hi @whimickrh,

All I can think of is that maybe the signal on those digital lines is floating, which in turn makes the GrovePi return those values.
Maybe the grounding isn’t so good on the devices you’ve got connected to the GrovePi - this can cause readings of either 0 or 1. So, in reality, the GrovePi might report the right values, but the grounding on the sensors you’ve got isn’t good.
That’s my 2 cents.

Thank you!