Edge detection callback fails silently after upgrading RPi.GPIO to 0.7+
0 reputation · 06 Jun 2025, 11:08 UTC
0 reputation · 06 Jun 2025, 11:08 UTC
An existing Python script uses RPi.GPIO edge detection callbacks to monitor a button press on GPIO 17 (BCM). After upgrading the library from 0.6.x to 0.7.1, the callback function no longer executes when the button is pressed, even though the script starts without errors and the pin reads correctly via polling.
Determine why the falling-edge callback registered with GPIO.add_event_detect() stops firing under RPi.GPIO 0.7+ while the same code worked on 0.6.x.
GPIO.setmode(GPIO.BCM) and configures the pin as input with pull-up.add_event_detect() or add_event_callback().add_event_callback that was omitted from the release notes?34775 reputation · 06 Jun 2025, 12:04 UTC
RPi.GPIO 0.7+ does not require a different callback signature. The callable passed to GPIO.add_event_callback() must still accept exactly one positional argument—the GPIO channel number—just as it did in 0.6.x. There is no separate documented migration step for add_event_callback. The silent failure after upgrading is most often explained by two behavioral changes in 0.7+: edge events are dispatched from a background daemon thread, and detection timing can interact differently with mechanical switch bounce when bouncetime is omitted.
Confirmed across versions: the callback contract is unchanged. A valid registration looks like this:
def button_callback(channel):
print("Edge detected on GPIO", channel)
GPIO.add_event_detect(17, GPIO.FALLING,
callback=button_callback,
bouncetime=200)
Likely explanation (verify locally): if your callback is currently a lambda, a nested function, or a bound method, test it as a module-level function first. RPi.GPIO invokes the callable directly from its event thread, so scope should not matter in principle, but the 0.7+ threading refactor makes a module-level function the safest baseline to confirm. A second common cause is a missing bouncetime; without it, a mechanical button can generate multiple rapid edges that the detector may coalesce or drop, making the callback appear silent.
channel parameter.bouncetime=200 (milliseconds) to add_event_detect to debounce the switch.GPIO.FALLING edge.Is the callback currently defined as a lambda or inside another function? If yes, moving it to module level is the first change to test. If it is already module-level, the next step is to add bouncetime and verify that the main thread is not exiting before the edge occurs.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.