1

I have a python script which have a pyqt5 Gui and I want in this Gui to know if a certain pin is toggeld. I did use

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN)
GPIO.add_event_detect(7, GPIO.RISING, callback = change, bouncetime=3)
def change(channel):
    channel_is_on =GPIO.input(channel)
    print(channel_is_on)

so what I received after I hooked the jumper was always 1 even I didn't turn it on. first how can I read just the toggle when it happen? what is the problem that the pin read high when it been hooked up?

1 Answer 1

1

The callback is only set up for rising edges. Change it to wait for both edges.

4
  • may be it's the solution but I still get the 1s after hooking the jumper , therefore I cannot confirm it
    – Izo
    Oct 7, 2020 at 13:28
  • What is connected to the GPIO? If nothing is connected it will randomly return 0 or 1. Add a pull.
    – joan
    Oct 7, 2020 at 14:49
  • I do actually connect it to pulse generator. I used Pull down resistance and it worked and but even that I'm using the GPIO.BOTH it return just 0 have you an idea how can solve it
    – Izo
    Oct 7, 2020 at 15:22
  • 2
    No. You need to add all clarifications to your question. It is almost always a mistake to read a GPIO level in a callback.
    – joan
    Oct 7, 2020 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.