We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 5:40 pm

Hello guys,
So I have been trying to do some raspberry pi projects, and I use Raspberry Pi 4 with the latest version of bullseye installed. These days, for some reason, some of my GPIO pins say failed to add edge detection rpigpio.py when used in a program. When I try to install lgpio, I always get an error like failed building wheel. Can anyone help me solve the problem with my gpio pins?

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
rpiMike
Posts: 3603
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 6:49 pm

Why are you using Bullseye? The current version is Bookworm!

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 7:01 pm

rpiMike wrote:
Tue Jul 29, 2025 6:49 pm
Why are you using Bullseye? The current version is Bookworm!
I am using it as I am on Raspberry Pi 4, I cannot install it through noobs, and don't know how to remove Noobs. And I do not have admin privelege on my computer to install the imager.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 7:18 pm

Can you post a short python script that shows this happening?
On my Pi4 running Bullseye 32-bit with all updates, and RPi.GPIO 0.7.0, this works fine:

Code: Select all

from time import sleep
import RPi.GPIO as GPIO
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)

def button_callback(channel):
  print ("\ncallback on ",channel)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
GPIO.add_event_detect(21, GPIO.RISING, callback=button_callback)
n=0
while True:
  print (n,end="")
  sleep(1)
  n=n+1

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 9:00 pm

here is my code:
Image
and here is my physical setup(Pins 3.3v, GPIO4, GND):
Image
Image
Image
Image
Image


My full error is :

Code: Select all

Traceback (most recent call last):
  File "/home/procidic/LightSensor.py", line 2, in <module>
    ldr = LightSensor(4)
  File "/home/procidic/.local/lib/python3.9/site-packages/gpiozero/devices.py", line 108, in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/home/procidic/.local/lib/python3.9/site-packages/gpiozero/input_devices.py", line 679, in __init__
    self.pin.when_changed = self._cap_charged
  File "/home/procidic/.local/lib/python3.9/site-packages/gpiozero/pins/__init__.py", line 432, in <lambda>
    lambda self, value: self._set_when_changed(value),
  File "/home/procidic/.local/lib/python3.9/site-packages/gpiozero/pins/pi.py", line 319, in _set_when_changed
    self._enable_event_detect()
  File "/home/procidic/.local/lib/python3.9/site-packages/gpiozero/pins/rpigpio.py", line 226, in _enable_event_detect
    GPIO.add_event_detect(
RuntimeError: Failed to add edge detection
This happens with GPIO #4 and GPIO 14 as of now with my Raspberry Pi 4B

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 9:56 pm

Add Device to the import

Code: Select all

from gpiozero import LightSensor, Buzzer, Device
and add this line to your script *after ldr=.." to see which "pin factory" it is using

Code: Select all

print ("factory=",Device.pin_factory)
My Pi4 running that script does not give an error and shows:

Code: Select all

factory= <gpiozero.pins.rpigpio.RPiGPIOFactory object at 0xf730dda8>

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Tue Jul 29, 2025 9:58 pm

neilgl wrote:
Tue Jul 29, 2025 9:56 pm
Add Device to the import

Code: Select all

from gpiozero import LightSensor, Buzzer, Device
and add this line to your script *after ldr=.." to see which "pin factory" it is using

Code: Select all

print ("factory=",Device.pin_factory)
My Pi4 running that script does not give an error and shows:

Code: Select all

factory= <gpiozero.pins.rpigpio.RPiGPIOFactory object at 0xf730dda8>
it says factory: none

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Wed Jul 30, 2025 10:05 am

What happens if you run this script, which sets the "pin factory"

Code: Select all

from gpiozero import LightSensor, Device
from gpiozero.pins.rpigpio import RPiGPIOFactory
Device.pin_factory = RPiGPIOFactory()
ldr = LightSensor(4)
print ("factory=",Device.pin_factory)
print (ldr.value)

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Wed Jul 30, 2025 10:35 pm

neilgl wrote:
Wed Jul 30, 2025 10:05 am
What happens if you run this script, which sets the "pin factory"

Code: Select all

from gpiozero import LightSensor, Device
from gpiozero.pins.rpigpio import RPiGPIOFactory
Device.pin_factory = RPiGPIOFactory()
ldr = LightSensor(4)
print ("factory=",Device.pin_factory)
print (ldr.value)
Still says failed to add edge detection.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 1:46 am

Guys, I decided to install bookworm on my Raspberry Pi. I rewrote the OS to bookworm, so the gpio pins would work. If it does work, I will let you know.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 11:40 am

Ok bookworm or bullseye on the Pi4 should work fine.

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 3:38 pm

neilgl wrote:
Thu Jul 31, 2025 11:40 am
Ok bookworm or bullseye on the Pi4 should work fine.
The Error is Gone, and now I have lgpio, but now it says GPIO busy instead, even though I never ran any gpio applications beforehand.
I was installing Argonone configuration at the time of running the script.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 7:48 pm

On Pi4 running Bookworm 64-bit, running this script (LightSensor.py) in Thonny does not give any error:

Code: Select all

from gpiozero import LightSensor
ldr = LightSensor(4)
print (ldr.value)
I do not have an Argon case.
So maybe that "Argonone configuration" is doing something to affect the GPIO e.g. fan control or some other service running in the background?
What is that "Argonone configuration" = maybe a script downloaded from the argon site?

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 8:26 pm

neilgl wrote:
Thu Jul 31, 2025 7:48 pm
On Pi4 running Bookworm 64-bit, running this script (LightSensor.py) in Thonny does not give any error:

Code: Select all

from gpiozero import LightSensor
ldr = LightSensor(4)
print (ldr.value)
I do not have an Argon case.
So maybe that "Argonone configuration" is doing something to affect the GPIO e.g. fan control or some other service running in the background?
What is that "Argonone configuration" = maybe a script downloaded from the argon site?
It wasn't the case. I ran it today, as the script was done downloading, but it still said GPIO Busy. This occured on Pin 4 and 14.
I'm not sure what is wrong. I use the extention pins on my argon case.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 9:21 pm

If you get time, install Bookworm again, then without any Argon downloads, run the gpiozero script.

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Thu Jul 31, 2025 11:27 pm

neilgl wrote:
Thu Jul 31, 2025 9:21 pm
If you get time, install Bookworm again, then without any Argon downloads, run the gpiozero script.
I need the argon script for my fan.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Fri Aug 01, 2025 8:36 am

Yes you can install the Argon script later, after checking that the gpiozero script works before the argon install (and maybe not after)

ghp
Posts: 4413
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Failed To Add Edge Detection, GPIOZERO

Fri Aug 01, 2025 9:01 am

There is a similar error reported for a some time now.
https://github.com/gpiozero/gpiozero/issues/1135

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Fri Aug 01, 2025 1:11 pm

That old issue does not seem to be present now?
Anyway, with a fresh install of Bookworm 64-bit, do all updates, run the script (as above)

Code: Select all

python LightSensor.py
0.0
No errors of the type "Failed To Add Edge Detection"

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Fri Aug 01, 2025 2:43 pm

It wasn't specific for Light Sensor. It was for any electronic component I pluggged into GPIO 4 and 14. It no longer is Failed to add edge detection, but rather GPIO Busy.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Fri Aug 01, 2025 2:56 pm

Seems to be the Argon script causing the issue.
On the Pi4 with Bookworm 64-bit, LightSensor.py was working OK (GPIO 4). Then download and run the Argon script (curl.... | bash)
The same script now fails with "gpio busy"
Note I have not (yet) done 'argon-config'

I might look at the cause when I get a minute...

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Sat Aug 02, 2025 11:29 am

Later, the argon script argonpowerbutton.py (which is run automatically from argononed.py service) uses GPIO4:

Code: Select all

LINE_SHUTDOWN=4
So that explains why we get a "GPIO Busy" error.

Workaround - use a different pin for the LDR (GPIO 21 worked for me)

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Sat Aug 02, 2025 4:01 pm

neilgl wrote:
Sat Aug 02, 2025 11:29 am
Later, the argon script argonpowerbutton.py (which is run automatically from argononed.py service) uses GPIO4:

Code: Select all

LINE_SHUTDOWN=4
So that explains why we get a "GPIO Busy" error.

Workaround - use a different pin for the LDR (GPIO 21 worked for me)
worked for me. GPIO 14 had a similar issue. Im buying a raspberry pi build hat, so when I use it, Imma uninstall the script as my pi would not be in the case.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

Procid
Posts: 20
Joined: Tue Jul 29, 2025 5:36 pm
Location: Montgomery County, Maryland, United States

Re: Failed To Add Edge Detection, GPIOZERO

Sat Aug 02, 2025 4:02 pm

neilgl Thank you for your help.

Code: Select all

def signature():
     name = input("sign: ")
     print("name")
                  
signature() 

User avatar
neilgl
Posts: 11167
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Failed To Add Edge Detection, GPIOZERO

Tue Aug 12, 2025 6:57 pm

OK it was interesting.

Return to “Python”