I ran a python script on a Raspberrypi 4 on Raspbian Bookworm for a ups (uninterruptible power supply) quite a while. Since the latest update of bookworm the script fails. Since the script of the ups is somewhat complex i narrowed down the issue to the following code fragment:

import RPi.GPIO as GPIO
import time


def isr(channel):

GPIO.setup(CLOCK_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(PULSE_PIN, GPIO.OUT, initial=1)
GPIO.add_event_detect(CLOCK_PIN, GPIO.FALLING, callback=isr, bouncetime=BOUNCE_TIME)

with this error:

Traceback (most recent call last): File "picofssd.py", line 15, in <module> GPIO.add_event_detect(CLOCK_PIN, GPIO.FALLING, callback=isr, bouncetime=BOUNCE_TIME) RuntimeError: Failed to add edge detection

The code is run in a service as root. Unfortunately i have no idea what can cause the error. Pin 27 should not have another function than gpio and user root should have all access rights.

I found hints that this can be caused when script is run as normal user, but is run as root. Pin has no dual function, so it should also not be a configuration issue.

Any hints what can cause this error?

  • What are these pins connected to? How are you using them?
    – Milliways
    Mar 17 at 10:38
  • Its the driver part for this USV. It worked for a long time, but stopped with last update ( apt-get upgrade)
    – uenz
    Mar 18 at 11:20

1 Answer 1


After doing a lot of research i found a solution myself: It seems that the kernel interface for gpio access changed from library gpio to lgpio. Switching the python package rpi-gpio to rpi-lgpio as provider for the RPi.GPIO include solved the issue without any changes in code.

  • This is nonsense. RPi.GPIO never used "the kernel interface" it directly accessed registers.
    – Milliways
    Mar 21 at 11:30
  • @Milliways Maybe the wording is nonsense, but not the message. Python cannot access the CPU Registers by itself. It relies on a library. The library provided with rpi-gpio stopped working on by bookworm installation with the above mentioned error. Replacing the rpi-gpio library by the rpi-lgpio library did the trick for my installation. May explanation was taken from the description of rpi-lgpio.
    – uenz
    Mar 22 at 14:23

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.