Friday, May 10, 2013

Automatically taking photos of the sunrise over Mt. Rainier

The view from my bedroom window
I wish I had done this earlier and not when I have 2 more weeks left in the house before I move to a place that does not have a perfect view of Mt. Rainier from the master bedroom window. I've connected this shutter release cable for the 5D to an opto-isolator chip which is then connected to one of the GPIO pins on my pcDuino. Whenever I want to wakeup the camera I set the GPIO pin high for 500ms to wakeup the camera. Then I use gphoto2 to capture the image. The following script will be run at sunrise every morning.
#!/bin/bash

function wakeup {
        echo waking up camera
        #half-press of the shutter button to wake the camera via optoisolator chip connected to shutter release port of camera
        /home/ubuntu/sample/core/gpio_set 7 1
        #hold the button for 500ms
        /bin/sleep .5s
        #release the button
        /home/ubuntu/sample/core/gpio_set 7 0
        #wait for the camera to wake up
        /bin/sleep 2s
}

function takephoto {
        echo taking photo
        /usr/bin/gphoto2 \
        --camera="Canon EOS 5D Mark III" \
        --folder=/store_00010001/DCIM/100EOS5D \
        --capture-image
}


#write images to card
#/usr/bin/gphoto2 --camera="Canon EOS 5D Mark III" --get-config /main/settings/capturetarget
/usr/bin/gphoto2 --camera="Canon EOS 5D Mark III" --set-config /main/settings/capturetarget=1

#loop 90 times and sleep 120 seconds between each photo
x=1
while [ $x -le 90 ]
do
        echo Taking photo $x of 90
        wakeup
        takephoto
        echo Sleeping for 120 seconds
        /bin/sleep 120s
        x=$(( $x + 1 ))
done

#write images to ram
/usr/bin/gphoto2 --camera="Canon EOS 5D Mark III" --set-config /main/settings/capturetarget=0
The output looks like this:
/usr/local/bin/camera.sh
Taking photo 1 of 90
waking up camera
taking photo
New file is in location /store_00010001/DCIM/100EOS5D/3Q1A2080.CR2 on the camera
New file is in location /store_00020001/DCIM/100EOS5D/3Q1A2080.CR2 on the camera
Sleeping for 120 seconds
Taking photo 2 of 90
waking up camera
taking photo
New file is in location /store_00010001/DCIM/100EOS5D/3Q1A2081.CR2 on the camera
New file is in location /store_00020001/DCIM/100EOS5D/3Q1A2081.CR2 on the camera
Sleeping for 120 seconds
Taking photo 3 of 90
waking up camera
taking photo
New file is in location /store_00010001/DCIM/100EOS5D/3Q1A2082.CR2 on the camera
New file is in location /store_00020001/DCIM/100EOS5D/3Q1A2082.CR2 on the camera
Sleeping for 120 seconds
Taking photo 4 of 90
waking up camera
taking photo
New file is in location /store_00010001/DCIM/100EOS5D/3Q1A2083.CR2 on the camera
New file is in location /store_00020001/DCIM/100EOS5D/3Q1A2083.CR2 on the camera
Sleeping for 120 seconds
Taking photo 5 of 90
waking up camera
taking photo
New file is in location /store_00010001/DCIM/100EOS5D/3Q1A2084.CR2 on the camera
New file is in location /store_00020001/DCIM/100EOS5D/3Q1A2084.CR2 on the camera
Sleeping for 120 seconds