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)

while True:
        print('wait for motion')
        print('motion detected')
        print('frame captured')
        print('motion ended')

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

  • In the while loop you should try putting a time.sleep() function to the end. To see if the problem is within when it's storing data. That resolution is enough for it to handle. – kuzeyron Jul 23 '19 at 15:59
  • I don't think because pir.wait_for_no_motion() waits some second and I don't trigger pir.wait_for_motion() immediately after, anyway I tried and it didn't work. however why that should cause freezes, it should't just queue writings? – Miky Jul 23 '19 at 16:56
  • Is even pir.wait_for_no_motion() needed? – kuzeyron Jul 23 '19 at 17:16
  • what is the purpose of camera.resolution=(1920,1080) – jsotola Jul 23 '19 at 17:53
  • originally after the capture I start recording a video (at 1920x1080) until pir.wait_for_no_motion() is triggered – Miky Jul 23 '19 at 18:58

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.