0

Im getting an error "Error waiting for edge"

In this script:

import RPi.GPIO as io
import time
from picamera import PiCamera
from datetime import datetime

#PIR setup
pir_pin = 4
io.setmode(io.BCM)
io.setup(pir_pin, io.IN)

#camera settings
camera = PiCamera()
camera.exposure_mode = 'auto'
camera.image_effect='blur'
camera.resolution = (400, 300)
camera.awb_mode = 'auto'

def motion(pir_pin):
    print("Motion!")
    filename = datetime.strftime(datetime.now(),'%Y-%m-%d-%H-%M-%S')
    piclocation = '/home/pi/Pictures/'+ filename + '.jpg'
    time.sleep(1)
    camera.capture(piclocation)
    camera.close()


print("PIR Module test")
time.sleep(2)
print("Ready")

while True:
    try:
        print ("rpi-ms-camera: Waiting for motion.")
        io.wait_for_edge(pir_pin, io.RISING)
        motion(pir_pin)
        print ("rpi-ms-camera: Sleeping ")
        time.sleep(1)
    except KeyboardInterrupt:
        print ("rpi-ms-camera: Stopping due to keyboard interrupt.")
        camera.close()
        io.cleanup()
        break

Ive tried many versions of the code but always seem to run into this waiting for edge error.

Is there a better way to do this try/except statement? Or am I using wait_for_edge() wrong?

library versions are: RPi.GPIO = 0.6.3 picamera = 1.13

OS: Raspbian, Release 8.0, jessie

  • It works okay for me when I comment out the camera code and just set GPIO low then high. – joan Mar 7 '18 at 21:22
  • Can you try on a different BCM pin, like 17? BCM4 is commonly used for 1-wire; if that's enabled then there may be a conflict with attempting to use it as a general purpose pin – Dave Jones Mar 9 '18 at 13:17
  • @DaveJones I will try with 17 and see how it goes. – glw Mar 9 '18 at 16:21
  • @joan how did you set up your test with the GPIO set to high and low? – glw Mar 9 '18 at 16:22
  • Moving to BCM pin 17 and removing camera.close() in the motion function worked. although my keyboard interrupt is not working - but im not too worried about that at the moment. Thanks! – glw Mar 9 '18 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.