0

I'm working on a Raspberry Pi project using Python and the rpi-lgpio library to monitor GPIO events. My setup involves connecting a RadiationD-v1.1 (CAJOE) module to GPIO pin 11 (physical pin 23) on my Raspberry Pi. However, when I run my script, I encounter the following error:

sudo python3 GPIO4.py
Traceback (most recent call last):
 File "/home/raspberry/RADROBOT/GPIO4.py", line 24, in <module>
 GPIO.add_event_detect(11, GPIO.FALLING, callback=countme)
RuntimeError: Failed to add edge detection
Code snippet:
Here’s the relevant portion of my code:
import lgpio as GPIO
GPIO.setmode(GPIO.BOARD) # Using physical pin numbering
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def countme(channel):
 print("Event detected on GPIO pin!")
GPIO.add_event_detect(11, GPIO.FALLING, callback=countme)

What I’ve tried so far:

  1. Verified hardware connections:
  • The module is connected to GPIO 11 (physical pin 23) as per the Raspberry Pi pinout.
  • The wiring is solid and confirmed with a multimeter.
  1. Software and environment setup:
  • Switched from RPi.GPIO to rpi-lgpio to avoid compatibility issues.
  • Installed rpi-lgpio in a virtual environment using pip install rpi-lgpio.
  1. Checked for GPIO conflicts:
  • Killed any processes that might be using the GPIO pins (ps aux | grep python).
  • Ensured no pins are being initialized twice in my script.
  1. Changed pins:
  • Attempted to use GPIO 17 (physical pin 11) instead, but the same error occurs.
  1. Experimented with pull-up/down configuration:
  • Adjusted the pull-up/down settings (PUD_UP and PUD_DOWN) to see if this resolved the issue.

Additional Context:

  • Raspberry Pi Model: Raspberry Pi 4 Model B
  • OS: Raspberry Pi OS (Bookworm)
  • Module: RadiationD-v1.1 (CAJOE)
  • Python Library: rpi-lgpio

My Questions:

  1. Why does GPIO.add_event_detect fail with this error? Could it be a hardware limitation or a software/library issue?
  2. Are there specific configurations required for rpi-lgpio that differ from RPi.GPIO when setting up event detection?
  3. How can I debug this issue further to identify the root cause?

Any advice, insights, or troubleshooting tips would be greatly appreciated. Thank you in advance for your help! 😊

Milliways
62.8k33 gold badges114 silver badges228 bronze badges
asked Dec 12, 2024 at 15:17
1

1 Answer 1

2

I normally avoid answering Questions which only have a code fragment; if you want help post a Minimal, Reproducible Example.

What you have posted is nonsense; you have tagged rpi-gpio which is a "Compatibility shim for lgpio emulating the RPi.GPIO API" BUT you are NOT using it and have import lgpio as GPIO.

The fragment is nonsense for lgpio.

The shim may make sense if you have established code using RPi.GPIO although RPi.GPIO is included in Bookworm and works on a Pi4.

NOTE there are other errors; you use sudo python3 so python will NOT search in your venv but only show system libraries.

answered Dec 12, 2024 at 23:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.