I am trying to run the following script from reboot:
from gpiozero import MotionSensor
from gpiozero import Motor
from picamera import PiCamera
import datetime as dt
from time import sleep
camera = PiCamera()
pir = MotionSensor(4, 1, 100, .6, False)
motor = Motor(3,14) #first number is forwards, second is backwards
recordingTime = 10
#wait for motion, then move the motor back and forth
pir.wait_for_motion()
print("*Experiment* subject is peeing")
#moves motor forward for 3 seconds at 25% speed
motor.forward(.25)
sleep(3)
motor.stop()
sleep(5) #leaves strip out for 5 seconds
#moves motor backward for 3 seconds at 50% speed
motor.backward(.5)
sleep(3)
motor.stop()
#Start recording
filename = dt.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264") #saves file as a date
camera.start_recording(filename) #starts recording and saves it as filename
camera.annotate_text = dt.datetime . now() . strftime("%Y-%m-%d_%H.%M.%S")
start=dt.datetime.now()
#Keep recording until time runs out
while (dt.datetime.now() - start).seconds < recordingTime:
camera.annotate_text = dt.datetime.now(). strftime("%Y-%m-%d_%H.%M.%S")
camera.wait_recording(.2)
camera.stop_recording() #stops recording
I've tried numerous methods, including editing the crontab, creating a shell script that will run automatically, going into the init.d and creating a script there, and nothing works. Instead of running the code above, the motor just keeps on spinning incessantly until I manually go into the code and click 'run'. Also, once the video files are recorded, is there any way for them to automatically upload to my PC on a different network? What should I do? What am I missing? Thank you for the help