Timelapse Camera
Raspberry Pi Time Lapse Camera
The following Python script will capture a picture from the Raspberry Pi camera every time it is called. The filename of the picture will be date and time stamped and saved to the '/home/pi/pictures' folder.
#!/usr/bin/env python import os import time import commands from datetime import datetime d = datetime.now() initYear = "%04d" % (d.year) initMonth = "%02d" % (d.month) initDate = "%02d" % (d.day) initHour = "%02d" % (d.hour) initMins = "%02d" % (d.minute) filePath = '/home/pi/pictures/' fileName = time.strftime("%Y-%m-%d_%H%M.jpg"); fullPath = filePath + fileName cameraCommand = 'raspistill -o ' fullCommand = cameraCommand + fullPath os.system(fullCommand)
To capture images at regular intervals the script can be loaded as a cron job.
To edit the cron table type:
crontab -e
The format of the cron table is:
m h dom mon dow command
where m = minute past the hour, h = hour of the day, dom = day of the month, mon = month of the year and dow = day of week. So to run a script every day at 0735 hours would look like this
35 7 * * * script_name.py
For the timelapse camera the crontab was configured to run the script every 10 minutes.
crontab -e
Add the following line to the bottom of the text file.
0,10,20,30,40,50 * * * * python scripname.py
Save the file.
To check the contents of the cron table type.
crontab -l
You should see the script in the table.