I'm having a trouble while getting a GPIO pin state value within an event callback function.
GPIO.input() function seems to work properly in many cases. However the function occasionally returns a wrong value when it is used within a callback. The callback itself was fired correctly when I changed the pin state.
So the problem is, I think, GPIO.input() reads a phantom state when it is performed within a callback function.
Here is a snip from nrgpio.py in Node-RED.
The reason why I showed it is I used this library via Node-RED's rpi-gpio node at first and found the issue.
bounce = int(sys.argv[4]) def handle_callback(chan): sleep(bounce/1000) print GPIO.input(chan) if sys.argv[3].lower() == "up": GPIO.setup(pin,GPIO.IN,GPIO.PUD_UP) elif sys.argv[3].lower() == "down": GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN) else: GPIO.setup(pin,GPIO.IN) print GPIO.input(pin) GPIO.add_event_detect(pin, GPIO.BOTH, callback=handle_callback, bouncetime=bounce)
As long as I read the code, I think there's nothing weird thing associated with the issue.
I also used this library directly on RPi's pyhton console and I got the same output, I mean, GPIO.input() within a callback function returned wrong values.
Tested version : 0.6.2 and 0.6.3
uname -a: Linux raspberrypi 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux
Board: RPi2
Any chance someone could look at this?
There is a similar ticket: https://sourceforge.net/p/raspberry-gpio-python/tickets/157/ but essentially I (any many many users) can't get reliable readings in door-bell scenario (fast press). I sometimes get
on
when I don't press the button andoff
when the button is pressed. I used resistors, consulted the schematics with electrical engineer and it is current.Please fix this ticket and make GPIO accurate and reliable