Time-Lapse Project

The following is a collect bits and bobs I have pulled together for my wifes simple time-lapse camera request.

One of the issues is that it needs to be able to work in a field on battery power. so to be clear that it is working I have added a heartbeat by flashing the green on-board LED.

In normal operation there is just a external memory stick connected, this the captured pictures being transferred during the night from the SD card – ie when it is in not taking pictures

I have used a very basic batch file + CRON entry to take the pictures, using the instructions from the RPI foundation website [ July 16 note – these instructions have been updated to a new version using  PiCamera – link below to updated version]

https://www.raspberrypi.org/learning/timelapse-setup/worksheet.md

But with the Cron entry changed to [ to edit Cron – sudo crontab -e ]

*/10 7-18 * * * /home/pi/camera.sh 2>&1

This takes a picture every 10 minutes between 7am and 6pm

The I used for getting the led flashing is below, -thanks to TaskofOhm for this blog post

https://tasksofohm.wordpress.com/hardware/heartbeat-for-the-raspberry-pi/

A couple of bits that are not made clear in the instructions

  • you need to use modprobe [ sudo chmod +x heartbeat ] to make the batch-file executable
  • update-rc.d heartbeat defaults – needs be run as sudo

Then restart and you should have a nice double flashing heartbeat

To save just a bit more power I also have turned off the Red power LED

# Set the PWR LED to GPIO mode (set 'off' by default).
echo gpio | sudo tee /sys/class/leds/led1/trigger

see the following link for the full source info of this, thanks to  jeff-geerling

My final script look like this – (/etc/init.d/heartbeat)

#!/bin/sh -e
### BEGIN INIT INFO
# Provides: hearbeat
# Required-Start: udev $local_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Set LED at GPIO16 in hearbeat mode
# Description: Set LED at GPIO16 in hearbeat mode
### END INIT INFO

N=/etc/init.d/hearbeat
case "$1" in
 start)
  # make sure privileges don't persist across reboots
  if [ -f /sys/class/leds/led0/trigger ]
  then
    echo heartbeat >/sys/class/leds/led0/trigger
    # Set the PWR LED to GPIO mode (set 'off' by default).
    echo gpio | sudo tee /sys/class/leds/led1/trigger
    
    # to save a bit more power turn on pwr led
    # Set the PWR LED to GPIO mode (set 'off' by default).
    echo gpio | sudo tee /sys/class/leds/led1/trigger
  fi
  ;;
 stop|reload|restart|force-reload|status)
  ;;
 *)
  echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
  exit 1
  ;;
esac
exit 0

To remove the LED heartbeat use the following

sudo update-rc.d heartbeat remove