I've been working hard on learning how to use and interface with the pi! It's been great so far but I've been unable to get past this issue on my own. I've done online research but can't find anything...
So I'm working on a larger project but in an effort to troubleshoot the issue, I've written a little code to demonstrate the issue. I keep getting the error:
GPIO.add_event_detect(4, GPIO.FALLING, callback=buttonpressed, bouncetime=300)
RuntimeError: Failed to add edge detection
I realise that GPIO04/Pin7 is the GCLK so that could be the issue but I need a way around it because my project is currently using all other available pins (except pins 27 and 28). Below is my code that returns this error.
Please help! Any response is appreciated!
All I'm needing is for the button to interrupt the main thread, do its own thing and then resume the main thread.
Code: Select all
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def buttonpressed(channel):
print("\n")
print('Button Was Pressed')
GPIO.add_event_detect(4, GPIO.FALLING, callback=buttonpressed, bouncetime=300)
while 1:
print('waiting...')
time.sleep(1)
