0

My code has been having issues, it is possible I may have to reflash the memory card with new OS since it worked previously on another Rasp Pi Zero 2.

But if anyone can help with this problem so it wont happen again I'd be grateful.

The issue comes with trying to use the function to detect a distance wheel rev change using the code as follows:

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
#Distance Wheel
GPIO.setup(4, GPIO.IN)
def increaserev(channel):
 global counter
 counter += 1
GPIO.add_event_detect(4,GPIO.RISING, callback=increaserev)

This is a snippet of the code that still produces the same error when isolated. The full error is shown as:

Traceback (most recent call last) :
 File "/home/pi/test.py", line 12, in <module>
 GPIO.add_event_detect(4,GPIO.RISING, callback=increaserev)
RuntimeError: Failed to add edge detection

I have tried:

  • updating
  • upgrading
  • changing GPIO pin
  • disabling 1-wire system
Rafael Marques
1,8721 gold badge24 silver badges28 bronze badges
asked Jul 19, 2024 at 15:21
3
  • you havent defined counter, so you cannot increase it Commented Jul 19, 2024 at 15:34
  • Ye this is just an extract from my main code to show the issue, but running this snippet of code doesnt have the error of no counter being defined due to the main issue being reported halting the program before the increaserev can be reached. The issue is with the GPIO.add_event_detect Commented Jul 22, 2024 at 10:25
  • This question is similar to: RuntimeError: Failed to add edge detection - On Raspberrypi. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Aug 11, 2024 at 13:45

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

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.