I had started (finally) to getting deeper to gpiozero library so I started to test different scenarios and do things in different ways when I encountered a problem with instances of "Button" object!
the first time I assign a pin to a button it works. second time (sometimes maybe third time, I am not fully aware of this) it doesn't work showing the below traceback and the last error says RuntimeError: Failed to add edge detection
The strange thing is that when I change the button pin it works, then the issue happens again with the new pin! strange! it looks to me like I should gracefully close the button after using it! I tried to add an exception of a keyboard interrupt to close the button and now the button lasted longer when I am working, but it eventually triggered the same error.
I am using RPi 3B with python3. I used Thonny - primarily- when I faced the issue. but when It happens it shows same thing on IDLE as well.
Below is the exact lines that appeared on my screen. any assistance is appreciated.
p.s: i googled and found couple of threads about root permissions issues! my research found that this is a different issue and it is related only to button class!
Code: Select all
Traceback (most recent call last): File "LED_Button.py", line 11, in <module> button=Button(27) File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/devices.py", line 95, in __call__ self = super(GPIOMeta, cls).__call__(*args, **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/input_devices.py", line 303, in __init__ pin, pull_up, bounce_time, pin_factory=pin_factory File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/mixins.py", line 338, in __init__ super(HoldMixin, self).__init__(*args, **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/input_devices.py", line 100, in __init__ self.pin.when_changed = self._fire_events File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/pins/__init__.py", line 388, in <lambda> lambda self, value: self._set_when_changed(value), File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/pins/pi.py", line 289, in _set_when_changed self._enable_event_detect() File "/home/pi/.local/lib/python3.5/site-packages/gpiozero/pins/rpigpio.py", line 219, in _enable_event_detect bouncetime=self._bounce) RuntimeError: Failed to add edge detection