I have the camera module for the raspberry pi. I need to know, how do I program the pi to take an image every 30 seconds and save the images to the inserted 64gb SD card.
2 Answers
You could just use the raspistill's built in timelapse option:
raspistill -t 30000 -tl 2000 -o image%04d.jpg
That will take a picture every 2 seconds over a total period of 30 seconds with the files named image1.jpg, image0002.jpg...image0015.jpg. The %04d will be changed into a four-digit number with leading zeros added. I.e. %08d would give you an eight-digit number.
One way is to create a bash script and cron job.
Create a bash script inside /home/pi
directory using your favourite text editor and name it takephoto.sh
for example.
#!/bin/bash
DATE=$(date +"%Y-%m-%d_%H%M")
raspistill -o /home/pi/stills/$DATE.jpg
Then when you saved it you need to set the execute flag on the file with the following command.
chmod +x takephoto.sh
Create a directory, like /home/pi/stills
, the same as in the bash script. Now from /home/pi
you can test the script by executing it using ./takephoto.sh
You should have an image created inside the still folder with the timestamp.
Now you can setup a cron job to execute the script with the interval you require.
-
1Thank you for the responses. This pi setup is going in a weather balloon to take images, saved to sd card. The pi will be powered by a lipo battery. I want to take the sd card out of the pi and upload them to my desktop.– Bra NilCommented Jan 28, 2016 at 20:43
-
1crons minimum resolution is 1 minute so probably simplest to just have a sleep(30) and loop the script continuously.– joanCommented Jan 28, 2016 at 22:07