Back in college (circa 2004) I bought myself a Canon 300D, which I think was the first of the 'digital rebel' line.  Digital cameras were still relatively expensive back then, in terms of megapixels per dollar spent.  The 300D is only 6.3 megapixels and I remember paying almost $900 for a kit with the basic 18-55mm zoom lens.

canon300d

This was a great camera that somehow survived everything that I put it through.  I went on to own more professional Canon models, so the 300D has mostly been collecting dust. In order to give it a new purpose, I realized that it would be great for shooting time lapse.

Using a digital SLR for time lapse gives a nice cinematic look because the large lens can produce a shallow depth of field. If the subject allows, this can make a shot considerably more artsy.

So how do we get setup to automate this?

Control & Automation with gphoto2

The internet led me to gphoto2

The ability to control the DSLR via a USB cable by issuing commands from the command line sounded like exactly what I was looking for. By connecting the camera to a small/portable host ( a Raspberry Pi ) and issuing commands over SSH, this becomes a remotely operated digital SLR powered by linux!

It turns out that with a minimal amount of configuration and troubleshooting, it is as simple and beautiful of a solution as it sounds.   ( Check whether your camera model is supported )

First: A Sticky Situation

The rubberized coating on the camera body grip had started to revert into a more primitive petroleum product. It was the consistency of tar and quickly stained everything that it touched. I thought that rubbing alcohol might do the trick and it did nicely. All the goo is dissolved leaving clean plastic behind.   While not a technical requirement of this project, it was a disgusting show stopper.  Moving on.

Power Issues

If I want to generate time lapse imagery with this setup, I'll need the camera to stay powered on indefinitely. Unfortunately over the years the rechargeable batteries for the 300D have not held up very well, and at this point I'm not going to spend real money ( $40+? ) for the AC adapter.

( Google << "Canon300D DIY power supply" )

It turns out that it is possible to create a DIY power supply using the shell of one of the batteries and an AC-to-DC adapter of the correct voltage.  It requires some patience and confidence in your ability to provide, test & regulate an appropriate supply voltage.

I was extremely lucky to have a 9V 300ma AC-to-DC supply laying around, so I actually just hooked it up. Otherwise something like an LM7809 voltage regulator would probably work. After removing the rechargable cells there is a lot of room inside the battery shell that would nicely fit a voltage regulator.

powersupply9V

( Please read all the appropriate warnings about frying your camera before trying to do this. Hooking up 12V for example, will probably permanently damage your camera. )

The 300D requires the door to be closed for the power to be on, so you'll have to drill a hole or saw off part of the battery door in order to route the power wire. Take the door off to do this.

door-mod

A small part of the battery door has been removed to make room for wires

So after crossing my fingers and plugging it in, the camera thinks it has a full battery.  I was worried that 300mA wouldn't be enough power, but so far I've only seen it show the full battery indicator. I haven't tried to use the flash, or auto-focus any big lenses - and I may not because I fear it could draw too much power. At this point I don't want to spoil my success.

Now that I have the camera permanently powered, configured to stay on indefinetly and connected to a Raspberry Pi with a USB cable, I'm finally ready to dig into gphoto2.

Installing gphoto2

Depending on the *nix system of your preference, install gphoto2 using a package manager:
(Raspbian Jessie)

pi@raspi1:~ $ sudo apt-get install gphoto2

Assuming installation works and that the camera is connected, it should be detected using:

pi@raspi1:~ $ gphoto2 --auto-detect
Model Port
-----------------------------------------
Canon EOS 300D (normal mode) usb:001,005</pre>

A diagram of the current setup:
300D_setup

NOTE:  I also noticed that if I did not prefix my commands with sudo, I often got this error:
An error occurred in the io-library ('I/O problem'): No error description available

This leads me into my favorite joke:

sudo -- especially useful for times when you forget to use it.

Doing DLSR Stuff

At this point I was interested in how much control I would really have over the camera. I wanted to know if I could do all the things I could do by holding the camera in my own hands.
( See the complete CLI reference )

Accessing the file system
The following commands operate on the current folder on the SD card.

To see all folders, use:

pi@raspi1:~ $ sudo gphoto2 --list-folders

and then select a folder using

pi@raspi1:~ $ sudo gphoto2 --folder FOLDER_NAME

List all the files in all folders

pi@raspi1:~ $ sudo gphoto2 --list-files

Detected a 'Canon:EOS 300D (normal mode)'.
There is no file in folder '/'.
There is no file in folder '/DCIM'.
There is 1 file in folder '/DCIM/284CANON'.
#1 IMG_8452.JPG rd 1260 KB image/jpeg
There is no file in folder '/DCIM/CANONMSC'.
There is no file in folder '/MISC'.
There is no file in folder '/TRASHE~1'.

Download all files in the current folder:

pi@raspi1:~ $ sudo gphoto2 --get-all-files

Detected a 'Canon:EOS 300D (normal mode)'.
Downloading 'IMG_8452.JPG' from folder '/DCIM/284CANON'...
Saving file as IMG_8452.JPG

* more specific commands are available for downloading only certain files, or by range.  See the docs.

Capturing New Images
Creating new exposures remotely is probably the most exciting use of this setup. There are a few options for whether you want to capture & download in one command, and whether the created image should be retained on the cameras storage.

pi@raspi1:~ $ sudo gphoto2 --capture-image

Detected a 'Canon:EOS 300D (normal mode)'.
New file is in location /DCIM/284CANON/IMG_8453.JPG on the camera

// an image is captured to the camera's storage

Alternatively, you can capture and download and let the image be removed from the camera automatically

pi@raspi1:~ $ sudo gphoto2 --capture-image-and-download

Detected a 'Canon:EOS 300D (normal mode)'.
New file is in location /DCIM/284CANON/IMG_8453.JPG on the camera
Downloading 'IMG_8453.JPG' from folder '/DCIM/284CANON'...
Saving file as IMG_8453.JPG
Deleting file /DCIM/284CANON/IMG_8453.JPG on the camera
Deleting 'IMG_8453.JPG' from folder '/DCIM/284CANON'...

// an image is captured, downloaded to current working directory of gphoto2, then deleted from the camera storage

When using --capture-image-and-download it removes the file from the camera storage by default, unless the  --keep flag is added.

IMG_8454

Changing camera settings

Setting configuration like the ISO, shutter speed, or aperture is as easy as identifying which property to change, and to what value.

To find all configurable 'properties' of the camera:

pi@raspi1:~ $ sudo gphoto2 --list-config

/main/settings/ownername
/main/settings/capturesizeclass
/main/settings/iso
/main/settings/shootingmode
/main/settings/shutterspeed
/main/settings/zoom
/main/settings/aperture
/main/settings/exposurecompensation
/main/settings/imageformat
/main/settings/focusmode
/main/settings/flashmode
/main/settings/beep
/main/actions/syncdatetime
/main/status/model
/main/status/datetime
/main/status/firmwareversion
/main/status/driver
/main/Driver/list_all_files

And then to have it elaborate on all the options for a particular property, ex 'shutterspeed':
( abridged for brevity )

pi@raspi1:~ $ sudo gphoto2 --get-config shutterspeed

Label: Shutter Speed
Type: MENU
Current: 0.4
Choice: 0 Bulb     // 'bulb' exposure - not how/if this works with gphoto2
Choice: 1 30       // 30 seconds
Choice: 2 25
Choice: 3 20
...
Choice: 13 2       // 2 seconds
...
Choice: 19 0.5     // half a second
...
Choice: 25 1/8     // fractional seconds
...
Choice: 31 1/30
...
Choice: 36 1/100
Choice: 37 1/125
...
Choice: 43 1/500
...
Choice: 46 1/1000

These options can be set either by index (choice #), or the actual value.

So, setting the shutter speed to 1/1000th can be accomplished in one of two ways:

pi@raspi1:~ $ sudo gphoto2 --set-config-index shutterspeed=46
// or
pi@raspi1:~ $ sudo gphoto2 --set-config-value shutterspeed=1/1000

Detected a 'Canon:EOS 300D (normal mode)'.
Shutter speed changed

Conclusion / Next Steps

I'm really impressed with gphoto2, I only wish I had started using it years ago. I was really impressed with how well it 'just worked', and with all the configuration possibilities. I'm looking forward to creating some more complex time-lapses, or at least ones in higher resolution.

300D-rig

I also want to see what I can do with the --hook-script argument, which allows an executable to be called after a gphoto2 command. It would be interesting to try to do some image processing on a captured image.

I'll probably set this up to watch my tomato plants sprout and grow. A future post will cover the steps of post-processing.