gpiozero / gpiozero

A simple interface to GPIO devices with Raspberry Pi
https://gpiozero.readthedocs.io/
Other
1.92k stars 304 forks source link

Raspbian 12 BookWorm, kernel 6.6.20: RuntimeError: Failed to add edge detection #1136

Open f18m opened 6 months ago

f18m commented 6 months ago

Operating system: Raspbian Bookworm, with kernel 6.6.20+rpt-rpi-v8 Python version: 3.11 Pi model: Pi 4 Model B GPIO Zero version: 2.0.1 Pin factory used: RPi.GPIO 0.7.1

The basic snippet below

import gpiozero
gpiozero.Button(26)  # or any other pin number 

fails with error

Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/devices.py", line 108, in __call__
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     self = super().__call__(*args, **kwargs)
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/input_devices.py", line 412, in __init__
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     super().__init__(
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/mixins.py", line 417, in __init__
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     super().__init__(*args, **kwargs)
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/input_devices.py", line 168, in __init__
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     self.pin.when_changed = self._pin_changed
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     ^^^^^^^^^^^^^^^^^^^^^
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/pins/__init__.py", line 471, in <lambda>
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     lambda self, value: self._set_when_changed(value),
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/pins/pi.py", line 639, in _set_when_changed
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     self._enable_event_detect()
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:   File "/root/ha-alarm-raspy2mqtt-venv/lib/python3.11/site-packages/gpiozero/pins/rpigpio.py", line 220, in _enable_event_detect
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]:     GPIO.add_event_detect(
Mar 29 00:30:28 raspberrypi-ha-alarm python3[1574]: RuntimeError: Failed to add edge detection

A few points:

  1. there are already SIMILAR (but confused IMHO) issues open on this topic. I spent time reading them with no much success, so opening this one that, I hope, will help others

  2. Searching online my understanding is that in latest Linux kernel the sysfs interface for GPIOs has been removed, and most of the GPIO factory libraries are still trying to use it, like RPI.GPIO.

  3. I already managed to work-around the problem by using pigpio library as GPIO factory.

My suggestion: change documentation to clearly state that at this point in time, if you are on Bookworm and using a recent Linux kernel (would be nice to find out the exact Linux version since the sysfs deprecation), you MUST switch to pigpio library.

bennuttall commented 6 months ago

@waveform80 what's the state of play for Pi 4 these days?

lurch commented 6 months ago

See also #1132

keshmaster81 commented 2 months ago

Has a solution to this issue been found? I've run into the exact same problem with the same error messages. I only get this error when running a script that uses any input device. I am able to blink an led fine. I uninstalled gpiozero and RPi.GPIO and then installed gpiozero again with pigpio. Pigpio seems to be really complicated to figure out though. What's the simplest solution here if all I want to do is read a button?

BNNorman commented 2 months ago

Same problem here. I have a third party Dragino HAT which uses the offending GPIO so I can't change it. . I do not want to run the code using sudo nor downgrade (Though I may have to)

warthog618 commented 1 month ago

Any reason not to use lgpio as the pin factory?

Having said that, I have issues with using lgpio for buttons too, and would suggest trying gpiod but it is only at the PR request stage (#1165).

BNNorman commented 1 month ago

I switched to pygpio and that works ok.