Digital camera control using Arduino USB Host Shield. Part 1 – basics.

By Oleg Mazurov

I’m starting new series of articles describing exciting field of digital camera control. In modern cameras, USB port can be used not only for transferring images to a PC, but also for sending control commands to the camera. It is often possible to send commands which “press” the shutter button, modify shutter and aperture values, some cameras are even capable of doing focus control.

Digital camera control
Digital camera control

At the same time, new shooting techniques, such as HDR and stacked focus, require that a photographer makes several shots, slightly modifying one or several shooting parameters from shot to shot. Even age-old time lapse technique could use some automation. Since camera manufacturers are, as always slow to implement there cool features, Arduino comes to the rescue.

I am announcing new code developed for Arduino USB Host shield which implements digital camera control functions via PTP. Alex Glushchenko, a developer from my native Russia, recently joined camera control project and code shown here and in the future articles is mainly his. He did most of reverse engineering and code development and my contributions to this project were mainly code testing, camera borrowing, and blogging.

Code is hosted on github separately from USB Host library. Be warned – this source is preliminary and will be changed many times before it becomes stable! It is also expected to grow quite a bit – different cameras use different commands and developing universal code supporting all manufacturers (or even every camera from one manufacturer) is not possible due to the modest resources of Arduino platform. Therefore, several libraries have been developed, each covering specific set of cameras. The cameras supporting functions of a certain library are listed in library’s header file. The list of cameras is currently quite small but I’m hoping to get more cameras supported in the future.

Digital camera as USB peripheral is much more complex and less standard than a keyboard. The complexity starts at the very first level – device configuration. Very often , several different configurations are supported on a device and the default configuration is not the one we need. Therefore, the first step would naturally be learning how to recognize configuration which supports camera control commands.

There are 3 specifications describing USB digital camera works. Still Image Device specifies USB requests, descriptors and endpoints. The protocol structure is described in Media Transfer Protocol (MTP), which is better known by its previous name, “Picture Transfer Protocol” (PTP). The most interesting document, which actually lists commands supported by camera class, is known as “PIMA 15740-2000″. It is available for a fee from I3A, however, second-hand pdf copy can be obtained for free after some googling. Camera manufacturers implement their own functions, expanding PIMA definitions. In addition to that, some older cameras use their proprietary protocols instead of PTP; support for such cameras will be added eventually.

See also  Why Is My ATT Broadband Blinking Red? (7 Easy Fixes To Try)

USB specification defines a class called “Still Image Capture Device”. According to it, such device has ’06′ in “Class” field of interface descriptor of the configuration. Therefore, one way to find necessary configuration is to look at configuration descriptor contents. Let’s take a look at the device descriptor (in case you are curious, it’s an iPhone). When we look at the last line, the number of configurations is 4. Older cameras may have 2 configurations and the first one is often a disk drive – this arrangement was made in pre-PTP times so you could offload pictures to a PC even if you didn’t have a driver for the camera installed. Modern cameras rely on PTP to transfer files to PC and often come with just one configuration – so far, all cameras used so to check the PTP code for the shield were of this variety.

Device descriptor:
Descriptor Length:      12
Descriptor type:        01
USB version:            0200
Device class:           00
Device Subclass:        00
Device Protocol:        00
Max.packet size:        40
Vendor  ID:             05AC
Product ID:             1292
Revision ID:            0001
Mfg.string index:       01
Prod.string index:      02
Serial number index:    03
Number of conf.:        04

A sketch which prints device descriptor was posted several articles back, make yourself a copy of it if you haven’t already. A sketch printing configuration descriptor was also posted not long ago; however, it was written to output only first configuration of the device – don’t use it. Instead, download this multiple configuration capable sketch from examples section of USB_Host_Shield repo. The following table shows all four configurations of the iPhone:

Configuration: 0 Configuration descriptor: Total length: 0027 Num.intf: 01 Conf.value: 01 Conf.string: 05 Attr.: C0 Max.pwr: FA Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 03 Class: 06 Subclass: 01 Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 02 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 81 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 03 Max.pkt size: 0040 Polling interval: 40Configuration: 1 Configuration descriptor: Total length: 0095 Num.intf: 03 Conf.value: 02 Conf.string: 06 Attr.: C0 Max.pwr: FA Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 00 Class: 01 Subclass: 01 Protocol: 00 Intf.string: 00 Unknown descriptor: Length: 09 Type: 24 Contents: 0100011E0001010C24 Unknown descriptor: Length: 0C Type: 24 Contents: 020101020202030000000924 Unknown descriptor: Length: 09 Type: 24 Contents: 030201010101000904 Interface descriptor: Intf.number: 01 Alt.: 00 Endpoints: 00 Class: 01 Subclass: 02 Protocol: 00 Intf.string: 00 Interface descriptor: Intf.number: 01 Alt.: 01 Endpoints: 01 Class: 01 Subclass: 02 Protocol: 00 Intf.string: 00 Unknown descriptor: Length: 07 Type: 24 Contents: 01020101002324 Unknown descriptor: Length: 23 Type: 24 Contents: 020102021009401F00112 B00E02E00803E00225600 C05D00007D0044AC0080B B000905 Endpoint descriptor: Endpoint address: 81 Attr.: 01 Max.pkt size: 00C0 Polling interval: 01 Unknown descriptor: Length: 07 Type: 25 Contents: 01010000000904 Interface descriptor: Intf.number: 02 Alt.: 00 Endpoints: 01 Class: 03 Subclass: 00 Protocol: 00 Intf.string: 00 Unknown descriptor: Length: 09 Type: 21 Contents: 110100012260000705 Endpoint descriptor: Endpoint address: 83 Attr.: 03 Max.pkt size: 0040 Polling interval: 01Configuration: 2 Configuration descriptor: Total length: 003E Num.intf: 02 Conf.value: 03 Conf.string: 07 Attr.: C0 Max.pwr: FA Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 03 Class: 06 Subclass: 01 Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 02 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 81 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 03 Max.pkt size: 0040 Polling interval: 40 Interface descriptor: Intf.number: 01 Alt.: 00 Endpoints: 02 Class: FF Subclass: FE Protocol: 02 Intf.string: 00 Endpoint descriptor: Endpoint address: 04 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 85 Attr.: 02 Max.pkt size: 0040 Polling interval: 00Configuration: 3 Configuration descriptor: Total length: 005E Num.intf: 03 Conf.value: 04 Conf.string: 08 Attr.: C0 Max.pwr: FA Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 03 Class: 06 Subclass: 01 Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 02 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 81 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 03 Max.pkt size: 0040 Polling interval: 40 Interface descriptor: Intf.number: 01 Alt.: 00 Endpoints: 02 Class: FF Subclass: FE Protocol: 02 Intf.string: 00 Endpoint descriptor: Endpoint address: 04 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 85 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Interface descriptor: Intf.number: 02 Alt.: 00 Endpoints: 00 Class: FF Subclass: FD Protocol: 01 Intf.string: 00 Interface descriptor: Intf.number: 02 Alt.: 01 Endpoints: 02 Class: FF Subclass: FD Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 86 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 05 Attr.: 02 Max.pkt size: 0040 Polling interval: 00

The key here is Class field in interface descriptor – we know that still image capture device is identified by class 6. As we can see, configurations 0, 2 and 3 have potential. However, after much testing I found that none of these configurations support camera control commands. Here is another example of “Class 6 device” configuration, taken from Canon XSi camera – :

Configuration: 0
Configuration descriptor:
Total length:     0027
Num.intf:         01
Conf.value:       01
Conf.string:      00
Attr.:            C0
Max.pwr:          01

Interface descriptor:
Intf.number:      00
Alt.:             00
Endpoints:        03
Class:            06
Subclass:         01
Protocol:         01
Intf.string:      00

Endpoint descriptor:
Endpoint address: 81
Attr.:            02
Max.pkt size:     0040
Polling interval: 00

Endpoint descriptor:
Endpoint address: 02
Attr.:            02
Max.pkt size:     0040
Polling interval: 00

Endpoint descriptor:
Endpoint address: 83
Attr.:            03
Max.pkt size:     0008
Polling interval: 20

Number 6 in interface Class field doesn’t guarantee functionality but at least this configuration can then be activated and checked with PTP queries. It’s worth mentioning that in some cameras different configurations can be activated via camera menu and very often configuration which has “PTP” in it’s name is not the one we need. For example, Canon 5D has “PC Connection” configuration containing FF in interface class field and “PTP/Print” one with class 06. Even though both configurations talk PTP, PC Connection configuration is the one that supports remote control. This strangeness can be explained by the fact that Canon had proprietary camera control long before PTP and their first PTP implementation was written in order to be able to interact with third-party picture printers.

See also  How To Turn Off Bedroom Light Without Getting Out Of Bed? (Easy!)

Let’s talk briefly about PTP protocol. A unit of information exchange in PTP protocol is called a transaction. Camera commands, requests and responses travel inside transactions. In turn, transactions are exchanged within sessions – to send something to the camera, a session would have to be opened first (one exception being “Get Device Info” request, more about it later). Many times several responses are given to a single request, the first one meaning camera understood the request, the second one generated when requested command has been executed, and then another one reflecting camera changes resulted in command execution, like image file apperared after a picture has been taken. Some types of responses have specific meaning and are called events. In order to make a shot, program needs to open a session to the camera, set PC connection mode, send shutter release command, wait for “Shutter released” event, then wait until a new file appears on the memory card (another event) and only after that consider the job done and close the session. Data flow of other commands is similar; to change aperture we need to send aperture value and wait for “aperture changed” event. Skipping commands or requests for new events in the sequence usually causes camera to hang – it would execute a command or two and then become unresponsive and would have to be power cycled. Hanging of the camera is harmless and shall be anticipated during development.

Another piece of PTP device is properties. In digital camera, most properties contain shooting parameters. Typical example of a property is shutter speed value – this property can be changed. Another property is battery level. We won’t be able to change it directly but can request it’s value. There are also properties which both change by itself and can be changed externally; one good example is camera’s real-time clock.

See also  How To Get Crunchyroll On Samsung Smart TV? (Easy Guide!)

Lastly, there are objects contained in storages. For cameras, this is mainly files on memory card and their significance in Arduino-based applications is minor.

It’s now time to start controlling our cameras. The very first piece of software is a sketch that queries PTP device and prints out it’s capabilities. It uses GetDeviceInfo command (or operation) to output device capabilities. GetDeviceInfo is the only PTP operation which can be sent to the device without opening a session first. You will need al 3 files from this directory as well as files from ptp directory copied into %arduino%/hardware/libraries/ptp directory. This sketch is not camera-specific – it shall work with any class 6 device (as well as some proprietary ones, see note about Canon 5D above). Regretfully, this sketch won’t fit into 16K Arduinos – parser strings eat too much memory and more strings will be added in the future when more vendor-specific commands become known.

Here is PTPDevInfo output of an iPhone:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69iPhone Start   Device configured.: 0x0000   0000:ED 00 00 00 02 00 01 10 01 00 00 00 64 00 00 00 0010:00 00 00 00 20 44 00 65 00 76 00 69 00 63 00 65 0020:00 20 00 68 00 61 00 73 00 20 00 6E 00 6F 00 20 0030:00 76 00 65 00 6E 00 64 00 6F 00 72 00 20 00 65 0040:00 78 00 74 00 65 00 6E 00 73 00 69 00 6F 00 6E 0050:00 73 00 00 00 00 00 0E 00 00 00 01 10 02 10 03 0060:10 04 10 05 10 06 10 07 10 08 10 09 10 0A 10 0B 0070:10 14 10 15 10 1B 10 01 00 00 00 06 40 00 00 00 0080:00 03 00 00 00 01 38 0B 38 0D 38 03 00 00 00 01 0090:38 0B 38 0D 38 0B 41 00 70 00 70 00 6C 00 65 00 00A0:20 00 49 00 6E 00 63 00 2E 00 00 00 0D 41 00 70 00B0:00 70 00 6C 00 65 00 20 00 69 00 50 00 68 00 6F 00C0:00 6E 00 65 00 00 00 06 33 00 2E 00 31 00 2E 00 00D0:33 00 00 00 0C 38 00 36 00 38 00 33 00 30 00 50 00E0:00 45 00 32 00 59 00 37 00 48 00 00 00   Std. Ver.: 0x100 Vendor ID: 0x0(Unknown)   Vend.Ext.Ver.: 0x0 Device has no vendor extensionsFunc.Mode: 0x8C7       Operations supported:   1001 GetDeviceInfo 1002 OpenSession 1003 CloseSession 1004 GetStorageIDs 1005 GetStorageInfo 1006 GetNumObjects 1007 GetObjectHandles 1008 GetObjectInfo 1009 GetObject 100A GetThumb 100B DeleteObject 1014 GetDevicePropDesc 1015 GetDevicePropValue 101B GetPartialObject   Events supported:   4006 DevicePropChanged   Device properties supported:   Capture formats:   3801 EXIF_JPEG 380B PNG 380D TIFF   Image Formats:   3801 EXIF_JPEG 380B PNG 380D TIFF   Manufacturer: Apple Inc.   Model: Apple iPhone Device version: 3.1.3 Serial number: 86830PE2Y7H

The output starts with hex dump of the response and device operations start at line 31. The first operation, 1001 or GetDeviceInfo, it the very operation that was used to retrieve this information. The “OpenSession” and “Close Session”, as you may have guessed, are used to open and close a session with the device, the rest are used for file manipulation – not very useful. Let’s now take a look at GetDeviceInfo of a real camera, in this case, Canon 400D:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128Canon 400D Start Device configured.: 0x0000 Opening session #: : 0x0001 OpenSession: Session opened.: 0x2001 0000:5D 01 00 00 02 00 01 10 02 00 00 00 64 00 0B 00 0010:00 00 C8 00 00 00 00 38 00 00 00 14 10 16 10 15 0020:10 01 10 02 10 03 10 13 90 04 10 05 10 06 10 07 0030:10 08 10 0A 10 09 10 1B 10 0C 10 0D 10 0B 10 01 0040:91 02 91 03 91 04 91 07 91 05 91 17 91 18 91 16 0050:91 0F 91 15 91 10 91 14 91 13 91 06 91 0A 91 0B 0060:91 0C 91 0E 91 1A 91 1B 91 1C 91 1D 91 08 91 1F 0070:91 09 91 1E 91 20 91 21 91 0F 10 01 98 02 98 03 0080:98 04 98 05 98 FE 91 FF 91 1F 90 04 00 00 00 09 0090:40 04 40 05 40 01 C1 06 00 00 00 45 D0 02 D4 07 00A0:D4 06 D4 49 D0 4A D0 01 00 00 00 01 38 09 00 00 00B0:00 01 30 02 30 0A 30 08 30 01 38 01 B1 03 B1 02 00C0:BF 00 38 0B 43 00 61 00 6E 00 6F 00 6E 00 20 00 00D0:49 00 6E 00 63 00 2E 00 00 00 17 43 00 61 00 6E 00E0:00 6F 00 6E 00 20 00 45 00 4F 00 53 00 20 00 34 00F0:00 30 00 30 00 44 00 20 00 44 00 49 00 47 00 49 0100:00 54 00 41 00 4C 00 00 00 08 33 00 2D 00 31 00 0110:2E 00 31 00 2E 00 31 00 00 00 21 30 00 30 00 30 0120:00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 0130:00 30 00 30 00 30 00 30 00 30 00 30 00 30 00 30 0140:00 30 00 30 00 30 00 30 00 30 00 31 00 39 00 61 0150:00 33 00 32 00 37 00 66 00 39 00 00 00   Std.Ver.: 0x100 Vendor Ext. ID: 0xB(Canon)   Vend.Ext.Ver.: 0xC8   Func.Mode: 0x8C7   Operations supported: 1014 GetDevicePropDesc 1016 SetDevicePropValue 1015 GetDevicePropValue 1001 GetDeviceInfo 1002 OpenSession 1003 CloseSession 9013 PS_CheckEvent 1004 GetStorageIDs 1005 GetStorageInfo 1006 GetNumObjects 1007 GetObjectHandles 1008 GetObjectInfo 100A GetThumb 1009 GetObject 101B GetPartialObject 100C SendObjectInfo 100D SendObject 100B DeleteObject 9101 EOS_GetStorageIDs 9102 EOS_GetStorageInfo 9103 Vendor defined 9104 Vendor defined 9107 EOS_GetObject 9105 Vendor defined 9117 Vendor defined 9118 Vendor defined 9116 EOS_GetEvent 910F EOS_Capture 9115 EOS_SetExtendedEventInfo 9110 EOS_SetDevicePropValue 9114 EOS_SetPCConnectMode 9113 Vendor defined 9106 Vendor defined 910A Vendor defined 910B Vendor defined 910C Vendor defined 910E Vendor defined 911A Vendor defined 911B Vendor defined 911C Vendor defined 911D Vendor defined 9108 EOS_GetDeviceInfo 911F Vendor defined 9109 EOS_GetObjectIDs 911E Vendor defined 9120 Vendor defined 9121 Vendor defined 100F FormatStore 9801 GetObjectPropsSupported 9802 GetObjectPropDesc 9803 GetObjectPropValue 9804 SetObjectPropValue 9805 GetObjectPropList 91FE Vendor defined 91FF Vendor defined 901F Vendor defined   Events supported: 4009 RequestObjectTransfer 4004 StoreAdded 4005 StoreRemoved C101 Vendor defined   Device properties supported: D045 Vendor defined D402 Device_Friendly_Name D407 Perceived_Device_Type D406 Session_Initiator_Version_Info D049 Vendor defined D04A Vendor defined   Capture formats: 3801 EXIF_JPEG   Image Formats: 3001 Association 3002 Script 300A AVI 3008 WAV 3801 EXIF_JPEG B101 Vendor defined B103 Vendor defined BF02 Vendor defined 3800 Undefined   Manufacturer: Canon Inc. Model: Canon EOS 400D DIGITAL Device ver.: 3-1.1.1 Serial num.: 00000000000000000000000019a327f9   Closing session #: : 0x0001 Session closed.: 0x2001

This output lists many vendor-specific functions, some of which are used for camera control. Even though standard PTP contains many camera control commands, vendors tend to write their own, sometimes duplicating even non-camera control functions. The functions which name starts with “EOS” are Canon-specific.”Vendor defined” functions are also Canon-specific functions whose purpose is yet unknown.

GetDeviceInfo is a powerful tool to compare functionality of different cameras from the same vendor. Functions with the same number often perform identical actions. For example, the following output taken from Canon xSi camera shows the same EOS_Capture command as in 400D (910f, line 64 in 400D output, line 75 in xSi output). Indeed, shutter release code for 400D works identically on xSi.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149Canon xSi Start   Device configured.: 0x0000 Opening session #: : 0x0001 OpenSession: Session opened.: 0x2001   0000:7B 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00 0010:00 00 C8 00 00 00 00 41 00 00 00 14 10 15 10 16 0020:10 01 10 02 10 03 10 06 10 04 10 01 91 05 10 02 0030:91 07 10 08 10 03 91 09 10 04 91 0A 10 1B 10 07 0040:91 0C 10 0D 10 0B 10 05 91 0F 10 06 91 10 91 27 0050:91 0B 91 08 91 09 91 0C 91 0E 91 0F 91 25 91 26 0060:91 15 91 14 91 13 91 16 91 17 91 20 91 F0 91 18 0070:91 21 91 F1 91 1D 91 0A 91 1B 91 1C 91 1E 91 1A 0080:91 53 91 54 91 55 91 57 91 58 91 59 91 1F 91 FE 0090:91 FF 91 01 98 02 98 03 98 04 98 05 98 07 00 00 00A0:00 09 40 04 40 05 40 03 40 02 40 07 40 01 C1 03 00B0:00 00 00 02 D4 07 D4 06 D4 01 00 00 00 01 38 0A 00C0:00 00 00 01 30 02 30 06 30 0A 30 08 30 01 38 01 00D0:B1 03 B1 02 BF 00 38 0B 43 00 61 00 6E 00 6F 00 00E0:6E 00 20 00 49 00 6E 00 63 00 2E 00 00 00 1C 43 00F0:00 61 00 6E 00 6F 00 6E 00 20 00 45 00 4F 00 53 0100:00 20 00 44 00 49 00 47 00 49 00 54 00 41 00 4C 0110:00 20 00 52 00 45 00 42 00 45 00 4C 00 20 00 58 0120:00 53 00 69 00 00 00 08 33 00 2D 00 31 00 2E 00 0130:31 00 2E 00 30 00 00 00 21 62 00 36 00 32 00 31 0140:00 30 00 66 00 66 00 64 00 31 00 32 00 37 00 39 0150:00 34 00 66 00 32 00 63 00 61 00 33 00 61 00 64 0160:00 32 00 33 00 64 00 31 00 32 00 39 00 36 00 63 0170:00 32 00 31 00 35 00 38 00 00 00     Std.Ver.: 0x100 Vendor Ext. ID: 0x6(Microsoft)   Vend.Ext.Ver.: 0xC8   Func.Mode: 0x8C7   Operations supported:   1014 GetDevicePropDesc 1015 GetDevicePropValue 1016 SetDevicePropValue 1001 GetDeviceInfo 1002 OpenSession 1003 CloseSession 1006 GetNumObjects 1004 GetStorageIDs 9101 EOS_GetStorageIDs 1005 GetStorageInfo 9102 EOS_GetStorageInfo 1007 GetObjectHandles 1008 GetObjectInfo 9103 Vendor defined 1009 GetObject 9104 Vendor defined 100A GetThumb 101B GetPartialObject 9107 EOS_GetObject 100C SendObjectInfo 100D SendObject 100B DeleteObject 9105 Vendor defined 100F FormatStore 9106 Vendor defined 9110 EOS_SetDevicePropValue 9127 Vendor defined 910B Vendor defined 9108 EOS_GetDeviceInfo 9109 EOS_GetObjectIDs 910C Vendor defined 910E Vendor defined 910F EOS_Capture 9125 Vendor defined 9126 Vendor defined 9115 EOS_SetExtendedEventInfo 9114 EOS_SetPCConnectMode 9113 Vendor defined 9116 EOS_GetEvent 9117 Vendor defined 9120 Vendor defined 91F0 Vendor defined 9118 Vendor defined 9121 Vendor defined 91F1 Vendor defined 911D Vendor defined 910A Vendor defined 911B Vendor defined 911C Vendor defined 911E Vendor defined 911A Vendor defined 9153 EOS_GetLiveViewPicture 9154 Vendor defined 9155 EOS_MoveFocus 9157 Vendor defined 9158 Vendor defined 9159 Vendor defined 911F Vendor defined 91FE Vendor defined 91FF Vendor defined 9801 GetObjectPropsSupported 9802 GetObjectPropDesc 9803 GetObjectPropValue 9804 SetObjectPropValue 9805 GetObjectPropList   Events supported:   4009 RequestObjectTransfer 4004 StoreAdded 4005 StoreRemoved 4003 ObjectRemoved 4002 ObjectAdded 4007 ObjectInfoChanged C101 Vendor defined   Device properties supported:   D402 Device_Friendly_Name D407 Perceived_Device_Type D406 Session_Initiator_Version_Info   Capture formats:   3801 EXIF_JPEG   Image Formats:   3001 Association 3002 Script 3006 DPOF 300A AVI 3008 WAV 3801 EXIF_JPEG B101 Vendor defined B103 Vendor defined BF02 Vendor defined 3800 Undefined     Manufacturer: Canon Inc. Model: Canon EOS DIGITAL REBEL XSi Device ver.: 3-1.1.0 Serial num.: b6210ffd12794f2ca3ad23d1296c2158   Closing session #: : 0x0001 Session closed.: 0x2001

Modern Canon EOS cameras have function set similar to the one above. However, if we look into older cameras, they give very different output. Below is GetDeviceInfo output from my old trusty Canon 5D. As you can see, it has no resemblance to xSi or 400D. In fact, it looks like Canon Powershot A640 output, which is posted just below this one.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123Canon 5D Start Device configured.: 0x0000 Opening session #: : 0x0001 OpenSession: Session opened.: 0x2001 0000:0B 01 00 00 02 00 01 10 02 00 00 00 01 00 0B 00 0010:00 00 64 00 00 00 00 1D 00 00 00 14 10 15 10 16 0020:10 17 10 01 10 02 10 03 10 13 90 04 10 05 10 06 0030:10 07 10 08 10 09 10 0A 10 1B 10 0C 10 0D 10 0B 0040:10 01 90 02 90 06 90 0E 90 1B 90 1C 90 1E 90 21 0050:90 0F 10 1F 90 16 00 00 00 01 40 02 40 03 40 04 0060:40 05 40 06 40 07 40 08 40 09 40 0A 40 0C 40 0D 0070:40 01 C0 05 C0 06 C0 07 C0 08 C0 09 C0 0A C0 0B 0080:C0 0C C0 0D C0 10 00 00 00 45 D0 02 D0 03 D0 2C 0090:D0 2D D0 49 D0 32 D0 31 D0 34 D0 33 D0 2E D0 2F 00A0:D0 46 D0 47 D0 30 D0 4A D0 01 00 00 00 01 38 08 00B0:00 00 00 02 30 06 30 0A 30 08 30 01 38 01 B1 03 00C0:B1 02 BF 0B 43 00 61 00 6E 00 6F 00 6E 00 20 00 00D0:49 00 6E 00 63 00 2E 00 00 00 0D 43 00 61 00 6E 00E0:00 6F 00 6E 00 20 00 45 00 4F 00 53 00 20 00 35 00F0:00 44 00 00 00 0A 33 00 2D 00 30 00 2E 00 30 00 0100:2E 00 30 00 2E 00 31 00 00 00 00   Std.Ver.: 0x1 Vendor Ext. ID: 0xB(Canon)   Vend.Ext.Ver.: 0x64   Func.Mode: 0x8C7   Operations supported: 1014 GetDevicePropDesc 1015 GetDevicePropValue 1016 SetDevicePropValue 1017 ResetDevicePropValue 1001 GetDeviceInfo 1002 OpenSession 1003 CloseSession 9013 PS_CheckEvent 1004 GetStorageIDs 1005 GetStorageInfo 1006 GetNumObjects 1007 GetObjectHandles 1008 GetObjectInfo 1009 GetObject 100A GetThumb 101B GetPartialObject 100C SendObjectInfo 100D SendObject 100B DeleteObject 9001 PS_GetObjectSize 9002 Vendor defined 9006 Vendor defined 900E Vendor defined 901B PS_GetPartialObject 901C Vendor defined 901E Vendor defined 9021 PS_GetFolderEntries 100F FormatStore 901F Vendor defined   Events supported: 4001 CancelTransaction 4002 ObjectAdded 4003 ObjectRemoved 4004 StoreAdded 4005 StoreRemoved 4006 DevicePropChanged 4007 ObjectInfoChanged 4008 DeviceInfoChanged 4009 RequestObjectTransfer 400A StoreFull 400C StorageInfoChanged 400D CaptureComplete C001 Vendor defined C005 Vendor defined C006 Vendor defined C007 Vendor defined C008 Vendor defined C009 Vendor defined C00A Vendor defined C00B Vendor defined C00C Vendor defined C00D Vendor defined   Device properties supported: D045 Vendor defined D002 Vendor defined D003 Vendor defined D02C Vendor defined D02D Vendor defined D049 Vendor defined D032 Vendor defined D031 Vendor defined D034 Vendor defined D033 Vendor defined D02E Vendor defined D02F Vendor defined D046 Vendor defined D047 Vendor defined D030 Vendor defined D04A Vendor defined   Capture formats: 3801 EXIF_JPEG   Image Formats: 3002 Script 3006 DPOF 300A AVI 3008 WAV 3801 EXIF_JPEG B101 Vendor defined B103 Vendor defined BF02 Vendor defined   Manufacturer: Canon Inc. Model: Canon EOS 5D Device ver.: 3-0.0.0.1 Serial num.:   Closing session #: : 0x0001 Session closed.: 0x2001
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173Canon Powershot A640 Start Device configured.: 0x0000 Opening session #: : 0x0001 OpenSession: Session opened.: 0x2001 0000:AD 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00 0010:00 00 64 00 00 00 00 3E 00 00 00 14 10 15 10 16 0020:10 17 10 01 10 02 10 03 10 13 90 1F 90 04 10 05 0030:10 06 10 07 10 08 10 09 10 0A 10 1B 10 0C 10 0D 0040:10 0B 10 0F 10 12 10 01 90 21 90 1B 90 1E 90 19 0050:90 06 90 1C 90 02 90 2C 90 2D 90 2E 90 24 90 25 0060:90 0E 90 0F 90 10 90 11 90 28 90 23 90 29 90 2A 0070:90 2B 90 34 90 0E 10 08 90 1A 90 09 90 0B 90 1D 0080:90 0D 90 0C 90 14 90 15 90 18 90 12 90 01 98 02 0090:98 03 98 04 98 05 98 1A 00 00 00 01 40 02 40 03 00A0:40 04 40 05 40 06 40 07 40 08 40 09 40 0A 40 0B 00B0:40 0C 40 0D 40 0E 40 01 C0 05 C0 08 C0 09 C0 0A 00C0:C0 0B C0 0C C0 0D C0 0E C0 0F C0 11 C0 13 C0 13 00D0:00 00 00 45 D0 4A D0 2E D0 2F D0 02 D0 03 D0 34 00E0:D0 47 D0 46 D0 2D D0 48 D0 2C D0 30 D0 49 D0 32 00F0:D0 33 D0 31 D0 02 D4 07 D4 01 00 00 00 01 38 08 0100:00 00 00 01 30 02 30 06 30 0A 30 08 30 01 38 01 0110:B1 01 BF 0B 43 00 61 00 6E 00 6F 00 6E 00 20 00 0120:49 00 6E 00 63 00 2E 00 00 00 15 43 00 61 00 6E 0130:00 6F 00 6E 00 20 00 50 00 6F 00 77 00 65 00 72 0140:00 53 00 68 00 6F 00 74 00 20 00 41 00 36 00 34 0150:00 30 00 00 00 0A 31 00 2D 00 33 00 2E 00 32 00 0160:2E 00 31 00 2E 00 30 00 00 00 21 46 00 32 00 31 0170:00 44 00 42 00 35 00 38 00 31 00 44 00 46 00 37 0180:00 44 00 34 00 38 00 30 00 43 00 39 00 41 00 34 0190:00 32 00 33 00 37 00 37 00 39 00 43 00 39 00 38 01A0:00 46 00 33 00 39 00 38 00 32 00 00 00   Std.Ver.: 0x100 Vendor Ext. ID: 0x6(Microsoft)   Vend.Ext.Ver.: 0x64   Func.Mode: 0x8C7   Operations supported: 1014 GetDevicePropDesc 1015 GetDevicePropValue 1016 SetDevicePropValue 1017 ResetDevicePropValue 1001 GetDeviceInfo 1002 OpenSession 1003 CloseSession 9013 PS_CheckEvent 901F Vendor defined 1004 GetStorageIDs 1005 GetStorageInfo 1006 GetNumObjects 1007 GetObjectHandles 1008 GetObjectInfo 1009 GetObject 100A GetThumb 101B GetPartialObject 100C SendObjectInfo 100D SendObject 100B DeleteObject 100F FormatStore 1012 SetObjectProtection 9001 PS_GetObjectSize 9021 PS_GetFolderEntries 901B PS_GetPartialObject 901E Vendor defined 9019 Vendor defined 9006 Vendor defined 901C Vendor defined 9002 Vendor defined 902C Vendor defined 902D Vendor defined 902E Vendor defined 9024 Vendor defined 9025 Vendor defined 900E Vendor defined 900F Vendor defined 9010 Vendor defined 9011 Vendor defined 9028 Vendor defined 9023 Vendor defined 9029 Vendor defined 902A Vendor defined 902B Vendor defined 9034 Vendor defined 100E InitiateCapture 9008 PS_StartShootingMode 901A PS_InitiateCaptureInMemory 9009 PS_EndShootingMode 900B PS_ViewfinderOn 901D PS_GetViewfinderImage 900D PS_ReflectChanges 900C PS_ViewfinderOff 9014 PS_FocusLock 9015 PS_FocusUnlock 9018 Vendor defined 9012 Vendor defined 9801 GetObjectPropsSupported 9802 GetObjectPropDesc 9803 GetObjectPropValue 9804 SetObjectPropValue 9805 GetObjectPropList   Events supported: 4001 CancelTransaction 4002 ObjectAdded 4003 ObjectRemoved 4004 StoreAdded 4005 StoreRemoved 4006 DevicePropChanged 4007 ObjectInfoChanged 4008 DeviceInfoChanged 4009 RequestObjectTransfer 400A StoreFull 400B DeviceReset 400C StorageInfoChanged 400D CaptureComplete 400E UnreportedStatus C001 Vendor defined C005 Vendor defined C008 Vendor defined C009 Vendor defined C00A Vendor defined C00B Vendor defined C00C Vendor defined C00D Vendor defined C00E Vendor defined C00F Vendor defined C011 Vendor defined C013 Vendor defined   Device properties supported: D045 Vendor defined D04A Vendor defined D02E Vendor defined D02F Vendor defined D002 Vendor defined D003 Vendor defined D034 Vendor defined D047 Vendor defined D046 Vendor defined D02D Vendor defined D048 Vendor defined D02C Vendor defined D030 Vendor defined D049 Vendor defined D032 Vendor defined D033 Vendor defined D031 Vendor defined D402 Device_Friendly_Name D407 Perceived_Device_Type   Capture formats: 3801 EXIF_JPEG   Image Formats: 3001 Association 3002 Script 3006 DPOF 300A AVI 3008 WAV 3801 EXIF_JPEG B101 Vendor defined BF01 Vendor defined   Manufacturer: Canon Inc. Model: Canon PowerShot A640 Device ver.: 1-3.2.1.0 Serial num.: F21DB581DF7D480C9A423779C98F3982   Closing session #: : 0x0001 Session closed.: 0x2001

When analyzing output posted above, we can see that this camera actually supports standard PTP “Initiate Capture” command (100E, line 87) as well as “Capture Complete” event (400D, line 118).

Here is a bonus for those who managed to get to this point – a sketch that performs shutter release on Canon EOS camera. It had been tested on 400D and xSi and will most likely work on cameras with the same 910f EOS_Capture command listed in GetDeviceInfo output. The sketch is available in the PTP examples on github, and copied below for your viewing pleasure:
[EDIT] This code doesn’t work with current PTP/EOS library. The correct code is here

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51/* EOS Capture Example. Works on cameras listed in canoneos.h */ #include <inttypes.h> #include <avr/pgmspace.h>   #include <spi.h> #include <max3421e.h> #include <max3421e_constants.h> #include <max_LCD.h> #include <usb.h>   #include <ptp.h> #include <canoneos.h>   #define DEV_ADDR 1   // Canon EOS 400D #define DATA_IN_EP 1 #define DATA_OUT_EP 2 #define INTERRUPT_EP 3 #define CONFIG_NUM 1   #define MAX_USB_STRING_LEN 64   void setup(); void loop(); void ptpmain();   CanonEOS Eos(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, (PTPMAIN)&ptpmain);   void setup() { Serial.begin( 9600 ); Serial.println(“Start”); Eos.Setup(); delay( 200 ); }   void loop() { Eos.Task(); }   void ptpmain() { if (Eos.OpenSession() == PTP_RC_OK) { Eos.Initialize(true); Eos.Capture(); delay(2000); Eos.Initialize(false); Eos.CloseSession(); } }

As you can see, the sketch is quite short for the amount of work it is doing and simple to understand thanks to Alex’s library structure design. Main functionality is presented on lines 41-51 – Open Session, Capture, Close Session. Delay is inserted to give camera time to save captured image; in real life applications it’s necessary to poll camera for “Object Created” event instead.

Due to the amount of material, writing about camera control can be challenging. Many things are much easier to the writer to present rather than explain; presentation style is also easier for the reader to digest. I’m currently working on simple camera controller design consisting of USB Host Shield, LCD display, rotary encoder plus a button or two and will be using it to present ways to use the library in various automatic shooting applications. I’m hoping to finish it in the next week or two, weather permitting, and publish the next program. Stay tuned!

Oleg.

Related posts:

  1. Digital camera control from Arduino-hosted webpage
  2. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
  3. Arduino USB Host – USB Descriptors.
  4. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2
  5. Arduino USB Host – Peripherals.
  6. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1
  7. Arduino USB Host Shield build log. Part 2.
  8. Arduino USB Host Shield build log. Part 4.
  9. USB Host Shield for Arduino – first prototype.
  10. Arduino USB Host Shield build log. Part 1.

Original Article:
https://www.circuitsathome.com/camera-control/digital-camera-control-using-arduino-usb-host-shield-part-1-basics

Similar Posts