Capturing a time lapse from a Raspbery Pi camera

After running into a bug with VLC capturing images from an RTSP stream in Linux, I decided to go a different route for capturing time lapses from my 3D printer and that was to use a local script on the PI that can be run with command line parameters to set the interval and duration of the capture and have the images output to a network share, this should satisfy the same goal as the RTSP stream by not having the PI store or write data to the SD card and so prolong its life

I went about the process in this order:

  • Setup a share on my workstation
  • On the pi “sudo apt-get install samba-common smbclient samba-common-bin smbclient cifs-utils”
  • Add the share to /etc/fstab by appending “//<server>/Timelapse /mnt/timelapse cifs guest,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0”
  • Reboot the Pi to ensure the mount is permanent

After that I wrote a simple script to allow for timelapse capture:

#Timelapse from an RPi Camera
if [ $# == 0 ]
echo “usage: $0 [runtime] [interval] [destination]”
echo ‘All times are in seconds (3600 seconds per hour)’
echo “example:  $0 3600 60 ~/images/timelapse”
if [ $# -gt 2 ]
while [ $SECONDS -lt $runtime ]
datetime=$(date +”%FT%H%M%S”)
raspistill -vf -hf -o $store_path/$datetime.jpg
sleep $interval
echo ‘time lapse complete’

Unfortunately I ran into trouble where whenever calling raspistill I would get an ENOSPC error and it would fail to do any capturing, I ran a firmware update and that led me down a rabbit hole where it looks like the rpi-update is broken on older Pis such as my Rpi 1B, this required downloading the files manually and forcing the update without a download as per the below:

curl -L -o master.tar.gz
cd /root/.rpi-firmware
sudo tar -xvzf /home/pi/master.tar.gz –strip-components=1
sudo SKIP_DOWNLOAD=1 rpi-update

Finally, with all of that complete I tried again and it failed, reason being I still had my streaming script running from the previous article! I went through and disabled the service I had setup previously:

systemctl disable

And tested and successfully got an image off the camera, I tested my script, and it worked!

I can now grab high resolution time lapses of my 3D printer by SSHing into my Pi and running a single command string!


Leave a Reply

Your email address will not be published. Required fields are marked *