I can´t get this to work, I'm trying to capture an image using button YELLOW only when button BLUE is held down for the camera preview. The buttons have been tested and are wired correctly, GREEN and RED are not in use.

Here is my code:

import RPi.GPIO as GPIO
import time
import picamera

yellow = 26
blue = 19
green = 20
red = 21

running = True

for pin in [yellow, blue, green, red]:
    GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)

camera = picamera.PiCamera()
hold = False

while running:
    if GPIO.wait_for_edge(blue, GPIO.FALLING):
            hold = 1
            frame = 1
            GPIO.wait_for_edge(blue, GPIO.RISING)
            hold = 0
    while hold == 1:
            GPIO.wait_for_edge(yellow, GPIO.FALLING)
            camera.capture('/home/pi/Desktop/image%03d.jpg' % frame)
            frame += 1
            print("Picture taken!")

Any ideas?


1 Answer 1


According to http://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/ the wait_for_edge method is blocking until it detects the wanted edge transition. So your program stops execution when you call it. There is also an event_detected method that might fit your needs better.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.