Just trying to customize some Picamera functionality though this is my first time coding in Python. Basically I am using the GPIO with a button switch to essentially turn just the preview on and off. Ideally i did not want to use wait_for_edge because I wanted the pi to do other stuff in the interim and not be locked up waiting for the button press. Then I submitted to using it after the event detection I set up since its fine that the program waits while in preview mode (for this case).
The issue comes with just trying to use one button. I basically initiate event detection on the button, then remove it once preview mode starts. Then I set it up to wait for the button press again. But I run into:
RuntimeError: Conflicting edge detection already enabled for this GPIO channel
The following is meat of the code thus far:
from time import sleep import picamera import RPi.GPIO as GPIO import datetime today = datetime.datetime.today() captureOn = 25 GPIO.setmode(GPIO.BCM) GPIO.setup(captureOn, GPIO.IN, pull_up_down=GPIO.PUD_UP) startPrev = True def preview(channel): global captureOn global startPrev if GPIO.input(captureOn): print ("Rising Edge detected") sleep(.5) else: if (startPrev == True): with picamera.PiCamera() as camera: camera.resolution = 1920, 1080 camera.framerate = 30 camera.rotation = 0 camera.brightness = 50 camera.start_preview() while True: sleep(1) print('preview started') startPrev = False if GPIO.input(captureOn): break else: ...stop preview code? print('stop preview') GPIO.add_event_detect(captureOn, GPIO.BOTH, callback=preview, bouncetime=1000)
EDIT: It seems that while in my IF statement, the GPIO event detection is disabled or not being called as pressing the button does nothing (no print outs either) FIXED: partially due to a wiring issue but added some code in the while statement above!