Symptom
A script that worked for years stops after apt full-upgrade pulls in kernel 6.6:
RuntimeError: Failed to add edge detection
It comes from GPIO.add_event_detect() in RPi.GPIO. It was reported on a Raspberry Pi 4, so this is not only the known "RPi.GPIO doesn't work on Pi 5" problem.
Cause (as explained by Raspberry Pi engineers)
Raspberry Pi's 6.6 kernel stopped overriding an upstream decision about GPIO numbering. The main GPIO controller no longer starts at global GPIO number 0: GPIO0 now gets global number 512. You can see it with:
sudo cat /sys/kernel/debug/gpio
Libraries that assumed "BCM number = global GPIO number" (the old sysfs interface) break. The firmware side (gpio= lines in config.txt) still uses the plain 0-based numbers.
Fix
Pick one:
-
Keep your RPi.GPIO code, swap the library for
rpi-lgpio, a compatibility module with the same API on top of lgpio. A Raspberry Pi OS maintainer added it to the repository:sudo apt update sudo apt install python3-rpi-lgpio --auto-remove --purgeIt replaces
python3-rpi.gpio. The two can't live in the same Python environment (same module name). In a virtual environment, uninstallRPi.GPIObeforepip install rpi-lgpio. Read the project's "Differences" page for behaviour that isn't identical. -
Port to gpiozero (default pin factory lgpio). This is the long-term path for new code; see the item on GPIO on Raspberry Pi 5.
Pi 5: gpiochip4 became gpiochip0
Code that opened the header GPIOs on a Pi 5 as gpiochip4 (libgpiod, lgpio, C code) was affected by a later change, merged in August 2024: the user-facing GPIO controller is now gpiochip0. gpiozero and rpi-lgpio were updated to find the right chip by driver name, and a udev rule adds a gpiochip4 symlink so older software keeps working. For your own code: look up the chip by label or driver, not by a fixed number.