User Tools

Site Tools


using_gphoto2_to_control_a_dslr_camera

This is an old revision of the document!


Remote Fire Camera via GPIO

June 2017

This page is work in progress, this message will be deleted when this page is complete!


Introduction


I am looking to buy a new DSLR camera body this year, and one of the grievances I have seen with the model I want, is that it only has a single card slot. Not a problem for me, but for some people who want backups of what they shoot, they see it as an issue (to be honest, most DSLRs have not had this feature, only in the last couple of years, and you never got this with film!)

Anyway, gphoto2 allows you to control your camera via the USB port, the amount of control you get varies between the make and model of camera that you are using.

You can use gphoto2 to take photos (great for making your own intervalometer, which we will try here, but you can also use gphoto2 to pull the images from your camera, and store them on a storage device attached to the Raspberry Pi, this is what I am really interested in.


Overview


For this guide I am using the following:

  • Raspberry Pi Zero
  • Raspbian (I am using Jessie, this should work on any version)
  • 8GB SD Card (will expand this when I am happy that gphoto2 does everything I need)
  • Canon 700D
  • Canon 5DMk2
  • USB type A to USB Mini A Cable (most devices now use the Mini B, like your mobile does, Canon uses the older type)


Now I generally shoot with 16GB cards, I don't see the point in using really large cards, if a card goes bad you can lose so much. So my aim is to use a 128GB storage device on my Raspberry Pi, and have the Raspberry Pi backup the cards periodically (as well as eventually having a manual button).

I do occasionally fill a 16GB card on a day out, but not very often. So having the ability to backup up to 8 cards is pretty good, and even if I was shooting a wedding, or doing some sports photography, I doubt I would fill more than two or three cards.


Topics

Copy All Files From SD Card

To copy all of the files from the SD Card, use the following command:

  gphoto2 --get-all-files


This will start to download the files from the camera. By default, the files will be copied to the present working directory (PWD) of your Raspberry Pi, i.e. the folder that you are in when you execute this command.

Downloading 'IMG_5829.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5829.CR2
Downloading 'IMG_5830.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5830.CR2
Downloading 'IMG_5831.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5831.CR2
Downloading 'IMG_5832.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5832.CR2
Downloading 'IMG_5833.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5833.CR2
Downloading 'IMG_5834.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5834.CR2
Downloading 'IMG_5835.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5835.CR2
Downloading 'IMG_5836.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5836.CR2
Downloading 'IMG_5837.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5837.CR2
Downloading 'IMG_5838.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5838.CR2
Downloading 'IMG_5839.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5839.CR2


Now, lets say I have a few files on my SD Card, lets list them here:

  gphoto2 --list-files
There is no file in folder '/'.
There is no file in folder '/store_00020001'.
There is no file in folder '/store_00020001/DCIM'.
There are 5 files in folder '/store_00020001/DCIM/100CANON'.
#1     IMG_5840.CR2               rd 29955 KB image/x-canon-cr2
#2     IMG_5841.CR2               rd 29998 KB image/x-canon-cr2
#3     IMG_5842.CR2               rd 29907 KB image/x-canon-cr2
#4     IMG_5843.CR2               rd 30151 KB image/x-canon-cr2
#5     IMG_5844.CR2               rd 30089 KB image/x-canon-cr2
There is no file in folder '/store_00020001/MISC'.


So I have 5 files, now I can back them up (I am in a folder on the Raspberry Pi called /home/pi/dcim)

  gphoto2 --get-all-files
total 150116
drwxr-xr-x  2 pi pi     4096 Jun 25 11:05 .
drwxr-xr-x 17 pi pi     4096 Jun 25 11:03 ..
-rw-r--r--  1 pi pi 30673501 Jun 25  2017 IMG_5840.CR2
-rw-r--r--  1 pi pi 30717301 Jun 25  2017 IMG_5841.CR2
-rw-r--r--  1 pi pi 30624254 Jun 25  2017 IMG_5842.CR2
-rw-r--r--  1 pi pi 30873867 Jun 25  2017 IMG_5843.CR2
-rw-r--r--  1 pi pi 30810295 Jun 25  2017 IMG_5844.CR2


If I take some more photos (another five in this example) and I want to back them up, to stop gphoto2 downloading the original five files again, we can use another switch.

   gphoto2 --get-all-files --skip-existing
Skip existing file IMG_5840.CR2
Skip existing file IMG_5841.CR2
Skip existing file IMG_5842.CR2
Skip existing file IMG_5843.CR2
Skip existing file IMG_5844.CR2
Downloading 'IMG_5845.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5845.CR2
Downloading 'IMG_5846.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5846.CR2
Downloading 'IMG_5847.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5847.CR2
Downloading 'IMG_5848.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5848.CR2
Downloading 'IMG_5849.CR2' from folder '/store_00020001/DCIM/100CANON'...
Saving file as IMG_5849.CR2


So here we can see that by using gphoto2 –get-all-files –skip-existing we skipped the first five files that we already had, and only downloaded the five new images.


Live Capture

IMPORTANT! After failing to capture images, I discovered this little gem: gphoto2 is configured by default to capture files to your camera's RAM. You need to set it to capture to the SD Card.

Type in the following from the terminal.

  gphoto2 --get-config capturetarget


You will most likely get the following:

Label: Capture Target Type: RADIO Current: Internal RAM Choice: 0 Internal RAM Choice: 1 Memory card

Here we can see that the capture target is set to Current: Internal RAM and we want it to be Memory Card

Enter the following:

  gphoto2 --set-config capturetarget=1


Now when we check, we should get the following:
Label: Capture Target Type: RADIO Current: Memory card Choice: 0 Internal RAM Choice: 1 Memory card

Now we are set to record captures to the Memory Card

Now, this depends on your camera, and whether gphoto2 supports it on your model. To get the capabilities of your camera, use the following command:

  gphoto2 --summary


Now on my 700D, I see the following:

Camera summary:
Manufacturer: Canon Inc.
Model: Canon EOS 700D
  Version: 3-1.1.3
  Serial Number: 46ff2aa38fba41f88d84eccb8eba8ada
Vendor Extension ID: 0xb (1.0)

Capture Formats: JPEG
Display Formats: Association/Directory, Script, DPOF, MS AVI, MS Wave, JPEG, CRW, Unknown(b103), Unknown(bf02), Defined Type, Unknown(b104), Unknown(b105)

Device Capabilities:
        File Download, File Deletion, File Upload
        No Image Capture, No Open Capture, Canon EOS Capture, Canon EOS Shutter Button

Storage Devices Summary:
store_00020001:
        StorageDescription: SD
        VolumeLabel: None
        Storage Type: Removable RAM (memory card)
        Filesystemtype: Digital Camera Layout (DCIM)
        Access Capability: Read-Write
        Maximum Capability: 31678529536 (30211 MB)
        Free Space (Bytes): 31375130624 (29921 MB)
        Free Space (Images): -1

Device Property Summary:
Property 0xd402:(read only) (type=0xffff) 'Canon EOS 700D'
Property 0xd407:(read only) (type=0x6) 1
Property 0xd406:(readwrite) (type=0xffff) 'Unknown Initiator'
Property 0xd303:(read only) (type=0x2) 1
Battery Level(0x5001):(read only) (type=0x2) Enumeration [100,0,75,0,50] value: 100% (100)


Importantly, I see the following section:

Device Capabilities:

File Download, File Deletion, File Upload
No Image Capture, No Open Capture, Canon EOS Capture, Canon EOS Shutter Button

So my 700D does not allow gphoto2 to capture files. There are two methods that you can use to try, and they are:

  gphoto2 --capture-image
  
  gphoto2 --capture-image-and-download


gphoto2 –capture-image takes a photo and stores it on the SD card. gphoto2 –capture-image-and-download takes a photo and stores it on the SD card and downloads it.

On some cameras the takes a photo and stores it on the SD card takes the image, but does not store it on the SD card (like on my 700D) so you can use gphoto2 –capture-image-and-download and the camera will take the photo and gphoto2 will download it, but it will still not be store on the SD card (does not work on my 700D)

So in summary, I have been able to download files from my camera(s) but not capture from them. So I can make a decent backup solution using gphoto2, but not an intervalometer.

Cameras tested so far:

Canon EOS M (the original)
Canon EOS 550D
Canon EOS 700D
Canon EOS 5DMk2




gphoto2 Trigger Capture

using_gphoto2_to_control_a_dslr_camera.1498395130.txt.gz · Last modified: 2023/03/09 22:35 (external edit)