from gpiozero import Button
from signal import pause

def say_hello():

button = Button(2)

button.when_pressed = say_hello


The above code works nicely in when I run it in the terminal by python ./button.py. It also works nicely in mu-editor in the first run in mu-editor. But when I stop the programme in mu-editor and rerun the same script, it prompts the error RuntimeError: Failed to add edge detection. Am I wrong in some settings?


I found a solution.

[SOLVED] gpiozero Button - Runtime Error - edge detection - Raspberry Pi Forums

I think I've fixed it in the latest development RPi.GPIO. It turns out that the GPIOs weren't getting cleaned up properly under Thonny and a recent bugfix to RPi.GPIO unmasked the problem.

I will release RPi.GPIO 0.6.5 in the next few days. If you can't wait that long then install the latest development RPi.GPIO (in Raspbian Squeeze):

$ sudo apt-get install python-dev python3-dev
$ sudo apt-get install mercurial
$ sudo apt-get install python-pip python3-pip
$ sudo apt-get remove python-rpi.gpio python3-rpi.gpio
$ sudo pip install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
$ sudo pip3 install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO

To revert back to the default version in Raspbian:

$ sudo pip uninstall RPi.GPIO
$ sudo pip3 uninstall RPi.GPIO
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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