I'm trying to set up a trap camera using a brand new Pi Zero W with Raspbian Buster but it freezes when I run the python scirpt.
originally the code was a bit complicated with multithreading, email sending, h264 to mp4 video converting etc., but now I simplified it to find out the problem:
from gpiozero import MotionSensor from picamera import PiCamera from time import time from time import sleep from datetime import datetime pir = MotionSensor(26) camera=PiCamera() camera.start_preview() sleep(2) while True: camera.resolution=(2592,1944) print('wait for motion') pir.wait_for_motion() print('motion detected') now=datetime.now().strftime('%Y%m%d_%H%M%S') camera.capture('/home/pi/Desktop/TRAP/'+now+'.jpg',quality=100) print('frame captured') pir.wait_for_no_motion() print('motion ended') camera.resolution=(1920,1080)
when I run it, it works for some iteration and then it freezes:
- I can still see the camera preview
- the clock is stopped
- last output is "wait for motion"
- sometimes a 0 bytes file is created
I think the problem is in the camera because if I comment the capture row it works normally