Dear experts,
I am running CentOS7 with kernel 5.4.206-v8.1.el7 on a RPi4 and I am trying to setup edge detection on GPIO with RPi.GPIO-0.7.1-py3.9
I am getting the following error whatever the pin I try to configure:
RPi.GPIO.add_event_detect(self.pin, RPi.GPIO.BOTH, self._on_event)
RuntimeError: Failed to add edge detection
I also get it when I run in sudo. I previously tuned the permissions to get :
[blabla@hostname]$ ls -l /dev/gpiomem
crw-rw----. 1 root gpio 246, 0 Jan 1 1970 /dev/gpiomem
so that GPIO in output mode (to blink a LED for instance) works fine.
Running my basic RPi.GPIO-based edge detection code with strace I noticed a few suspicious lines:
faccessat(AT_FDCWD, "/sys/class/gpio/gpio6", F_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/class/gpio/export", O_WRONLY) = -1 EACCES (Permission denied)
1) I thought RPi.GPIO was now based on GPIO character and not sysfs anymore? Although I am far from being an expert so I may be wrong / confused
2) I looked a bit into /sys/class/gpio on my RPi:
[blabla@hostname]$ ls /sys/class/gpio/
export gpiochip446 gpiochip454 unexport
It seems to me that attempting to create /sys/class/gpio/gpio6 makes no sense here, one should read the base of the controller and do base+6 ? Wouldn't that explain the Permission denied?
Sorry again I am far from being an expert so maybe just confused myself, any help to unblock the situation would be great!
Thanks a lot
Best wishes
msaimper
Hello,
I ended up migrating to gpiod, where things work out of the box.
Best
msaimper
I am getting the same error as above, using RPi.GPIO 0.7.1 and Python 3.11. Is there any fix or workaround?
Looks like /sys/class/gpio has been deprecated:
https://www.thegoodpenguin.co.uk/blog/stop-using-sys-class-gpio-its-deprecated/
And now it's not present in the latest Ubuntu Server OS, which is what I'm running. Any plans to migrate away from /sys/class/gpio?
It seems /sys/class/gpio is only used for edge detection. It only appears in event_gpio.c.
The immediate problem is that starting with kernel 6.5, BCM GPIO numbering in /sys/class/gpio doesn't start with 0 any more. It starts with 512 on my Raspberry Pi 2 B running Raspbian Bullseye with kernel 6.6.20+rpt-rpi-v7 but don't know if it is safe to hard code 512. Regardless of that, I created a quick fix which adds 512 to numbers when using /sys/class/gpio and increases size of buffers used for this. I'm using this with ha-rpi_gpio for Home Assistant, which now works. I am attaching a patch.
Will this be fixed and published for easier update?