All things Raspberry Pi and Time Lapse

Archive for July 16, 2012

Raspberry Pi – how to set the system clock using a Canon Camera

Now that I have my Raspberry Pi I wrote and tested the script to set the time on the Raspberry Pi using my Canon Powershot A510. This is a follow up of my previous post. This is tested and works with a Canon Powershot A510 but it may work with other Canon Cameras, however some may require a little modification to the script.

#!/bin/bash
# jamesmiller
# 2012-07-16
# this script works with the Canon Powershot A510
# other models may or may not work
#
# use gphoto2 to get the camera time
camera_time=`gphoto2 –summary | grep -i “unix time” | cut -d ” ” -f4`
# for some reason I had to subtract some time to get it to be correct
camera_time=$(($camera_time – 3592))
# convert UNIX time to readable time
time=`date -d @$camera_time`
# the next four (4) lines cut the timestamp into specific parts so
# that it can be used when setting the time
b=`echo $time | cut -d ” ” -f2`
c=`echo $time | cut -d ” ” -f3`
d=`echo $time | cut -d ” ” -f4`
f=`echo $time | cut -d ” ” -f6`
# this sets the variable real_time equal to the values from gphoto2
# and puts them in the correct order
real_time=`echo $c $b $f $d`
# set the system time equal to the time from gphoto2
date -s “$real_time”

And this script is put into a cron job that is set to run at startup using these details here.

@reboot /path/to/script

If the power goes out and the camera and the Raspberry Pi shut down, when the power comes back the camera should startup faster than the Raspberry Pi and when the script runs it can set the time correctly. The camera has a small battery to keep time, and it will last for a long time with no power and still keep time.

Everything is setup outside my window taking pictures of our garden today. This is my chance to test and get all of the bugs worked out before I setup for a long period of time. Already I have changed several things and I updated the scripts post to reflect these changes.

I will probably post pictures of the setup tomorrow along with the time lapse that it is taking today.

Advertisements

Tag Cloud