Every time I run this code to detect a button press I get the error: “RuntimeError: Failed to add edge detection”
The code: import RPi.GPIO as GPIO
import time
BUTTON_PIN = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def button_pressed(channel):
print("Button pressed!")
GPIO.add_event_detect(BUTTON_PIN, GPIO.FALLING, callback=button_pressed, bouncetime=500)
try:
print("Waiting for button press...")
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
How can I resolve this?
The code: import RPi.GPIO as GPIO
import time
BUTTON_PIN = 23
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def button_pressed(channel):
print("Button pressed!")
GPIO.add_event_detect(BUTTON_PIN, GPIO.FALLING, callback=button_pressed, bouncetime=500)
try:
print("Waiting for button press...")
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
How can I resolve this?
Statistics: Posted by E-man105 — Thu Jun 05, 2025 12:28 am