Posts

Generic PTP control of digital cameras

Development of Arduino_Camera_Control library (which runs on top of USB_Host_Shield library written to support USB Host Shield ) continues at steady pace. Nikon point-and-shooters has been on a test bench for the last couple of weeks and they are already talking. Even more exiting is the fact that they are talking the language we already know – the plain old PIMA 15740-2000.

Arduino-controlled Nikon P100

Arduino-controlled Nikon P100

It also looks like that PTP protocol implementation in all Nikons is very close to the standard with very few vendor extensions and it will be possible to use the same code base for both point-and-shoot cameras and DSLRs. In this article, I’m showing a lightweight implementation of Capture command for Nikon cameras. Unlike its’ sister sketches, EOSCapture and PSCapture, this one can’t really be called NikonCapture – keep reading to find out why.

The InitiateCapture command, which is part of standard PTP command set can be seen in PTPDevInfo output of several Canon PowerShot and all Nikon cameras – see, for example, Canon A640 section, line 82 or Nikon Coolpix S4000, line 47. Regrettably, PowerShots seem to require setting D045 vendor-defined property before this command will be accepted by the camera; therefore, PowerShot-specific class would have to be instantiated, adding significantly to program size. On the other hand, Nikons are happily executing InitiateCapture as-is.

The following sketch does what other “…Capture” sketches do – it takes a shot once a second second in an endless loop. What makes it different is that it doesn’t use any vendor-specific code, compiles in ~9K and can be loaded into Atmega168-based boards leaving plenty of room for another functions.

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
#include <inttypes.h>
#include <avr/pgmspace.h>
 
#include <Max3421e.h>
#include <Max3421e_constants.h>
#include <Max_LCD.h>
#include <Usb.h>
 
#include <ptp.h>
 
#define DEV_ADDR        1
 
// Nikon CoolPix P100
#define DATA_IN_EP      2
#define DATA_OUT_EP     1
#define INTERRUPT_EP    3
#define CONFIG_NUM      1
 
// Canon 
//#define DATA_IN_EP      1
//#define DATA_OUT_EP     2
//#define INTERRUPT_EP    3
//#define CONFIG_NUM      1
 
#define MAX_USB_STRING_LEN 64
 
class CamStateHandlers : public PTPStateHandlers
{
      bool stateConnected;
 
public:
      CamStateHandlers() : stateConnected(false) {};
 
      virtual void OnDeviceDisconnectedState(PTP *ptp);
      virtual void OnDeviceInitializedState(PTP *ptp);
} CamStates;
 
PTP  Ptp(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);
 
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
{
    if (stateConnected)
    {
        stateConnected = false;
        Notify(PSTR("Camera disconnected\r\n"));
    }
}
 
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
{
    if (!stateConnected)
    {
        stateConnected = true;
 
        Ptp.CaptureImage();
        delay(1000);
    }
}
 
void setup() {
  Serial.begin( 115200 );
  Serial.println("Start");
  Ptp.Setup();
  delay( 200 );
}
 
void loop() 
{
    Ptp.Task();
}

The sketch uses application interface outlined in Canon EOS library description. The action occurs on line 55, where Ptp.CaptureImage() is called. The sketch also prints some useful information on the terminal, which has to be set to 115200. Full text of the sketch is hosted on GitHub together with the rest of PTP library.

This code has not been tested with many cameras. It works with Nikon Coolpix P100 and confirmed not to work with Canon A640. It should work without modifications with any PTP-capable Nikon – please let me know if it doesn’t work with yours!. I’m especially interested to see it working with little S-series – if you have one, please run this sketch and let me know the results (you’ll need to define both bulk-IN and bulk-OUT endpoints as 1 for S-series camera).

Oleg.

41 comments to Generic PTP control of digital cameras

  • kengu

    oleg:
    How to set PTP mode on canon 5DmarkII ? I can’t find it,When I Connect it with USH r1.1 .

  • Pookycade

    Does not appear to be working on a Nikon D5000. I am able to run PTPDevInfo, however, the camera if connected already does not provide info, program just sits there. If I disconnect and then reconnect, PTPDevInfo will run, giving the information below. If I start PTPCapture, it just sits there at the start screen, never seemingly recognizing the camera is connected. If I disconnect and reconnect the camera I get a scrolling message “Transaction: Command block send error: 000D”. Caveats are that I am using V1.0 Aug 2010 version of USB Host mini board and hand jumpering over to and Arduino Uno. However, EOSCaptuer works fine on my Canon Eos Rebel XS. Waiting for USB Host shield I just ordered to arrive so I can confirm

    PTPDevInfo for Nikon D5000

    0000: 49 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00
    0010: 00 00 64 00 13 6D 00 69 00 63 00 72 00 6F 00 73
    0020: 00 6F 00 66 00 74 00 2E 00 63 00 6F 00 6D 00 3A
    0030: 00 20 00 31 00 2E 00 30 00 00 00 00 00 2C 00 00
    0040: 00 01 10 02 10 03 10 04 10 05 10 06 10 07 10 08
    0050: 10 09 10 0A 10 0B 10 0C 10 0D 10 0E 10 0F 10 14
    0060: 10 15 10 16 10 1B 10 C0 90 C1 90 C2 90 C3 90 C4
    0070: 90 C7 90 C8 90 C9 90 CA 90 CB 90 CC 90 CD 90 CE
    0080: 90 CF 90 00 92 01 92 02 92 03 92 04 92 05 92 06
    0090: 92 01 98 02 98 03 98 05 98 0D 00 00 00 01 40 02
    00A0: 40 04 40 05 40 06 40 09 40 0A 40 0C 40 0D 40 08
    00B0: 40 01 C1 02 C1 04 C1 13 00 00 00 01 50 03 50 04
    00C0: 50 05 50 07 50 08 50 0A 50 0B 50 0C 50 0D 50 0E
    00D0: 50 0F 50 10 50 11 50 13 50 18 50 1C 50 06 D4 07
    00E0: D4 02 00 00 00 01 38 00 30 06 00 00 00 01 38 00
    00F0: 30 01 30 0A 30 06 30 02 30 12 4E 00 69 00 6B 00
    0100: 6F 00 6E 00 20 00 43 00 6F 00 72 00 70 00 6F 00
    0110: 72 00 61 00 74 00 69 00 6F 00 6E 00 00 00 06 44
    0120: 00 35 00 30 00 30 00 30 00 00 00 06 56 00 31 00
    0130: 2E 00 30 00 30 00 00 00 08 33 00 34 00 36 00 36
    0140: 00 31 00 39 00 33 00 00 00

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x6(Microsoft)

    Vend.Ext.Ver.: 0x64
    microsoft.com: 1.0
    Func.Mode: 0x8E0

    Operations supported:
    1001 GetDeviceInfo
    1002 OpenSession
    1003 CloseSession
    1004 GetStorageIDs
    1005 GetStorageInfo
    1006 GetNumObjects
    1007 GetObjectHandles
    1008 GetObjectInfo
    1009 GetObject
    100A GetThumb
    100B DeleteObject
    100C SendObjectInfo
    100D SendObject
    100E InitiateCapture
    100F FormatStore
    1014 GetDevicePropDesc
    1015 GetDevicePropValue
    1016 SetDevicePropValue
    101B GetPartialObject
    90C0 Vendor defined
    90C1 Vendor defined
    90C2 Vendor defined
    90C3 Vendor defined
    90C4 Vendor defined
    90C7 Vendor defined
    90C8 Vendor defined
    90C9 Vendor defined
    90CA Vendor defined
    90CB Vendor defined
    90CC Vendor defined
    90CD Vendor defined
    90CE Vendor defined
    90CF Vendor defined
    9200 Vendor defined
    9201 Vendor defined
    9202 Vendor defined
    9203 Vendor defined
    9204 Vendor defined
    9205 Vendor defined
    9206 Vendor defined
    9801 GetObjectPropsSupported
    9802 GetObjectPropDesc
    9803 GetObjectPropValue
    9805 GetObjectPropList

    Events supported:
    4001 CancelTransaction
    4002 ObjectAdded
    4004 StoreAdded
    4005 StoreRemoved
    4006 DevicePropChanged
    4009 RequestObjectTransfer
    400A StoreFull
    400C StorageInfoChanged
    400D CaptureComplete
    4008 DeviceInfoChanged
    C101 Vendor defined
    C102 Vendor defined
    C104 Vendor defined

    Device properties supported:
    5001 BatteryLevel
    5003 ImageSize
    5004 CompressionSetting
    5005 WhiteBalance
    5007 FNumber
    5008 FocalLength
    500A FocusMode
    500B ExposureMeteringMode
    500C FlashMode
    500D ExposureTime
    500E ExposureProgramMode
    500F ExposureIndex
    5010 ExposureBiasCompensation
    5011 DateTime
    5013 StillCaptureMode
    5018 BurstNumber
    501C FocusMeteringMode
    D406 Session_Initiator_Version_Info
    D407 Perceived_Device_Type

    Capture formats:
    3801 EXIF_JPEG
    3000 Undefined

    Image Formats:
    3801 EXIF_JPEG
    3000 Undefined
    3001 Association
    300A AVI
    3006 DPOF
    3002 Script

    Manufacturer: Nikon Corporation
    Model: D5000
    Device ver.: V1.00
    Serial num.: 3466193

    Camera disconnected

    • Mini is 3.3V board. MAX3421E is known to have difficulties detecting devices on the bus while powered from 5V (5V on the input pin may act as power).

      Thanks for sending the PTPDevInfo output – I’m going to post it right away.

    • In my D90 it works changing

      #define DATA_IN_EP 2 > 1
      #define DATA_OUT_EP 1 > 2
      #define INTERRUPT_EP 3 > 3
      #define CONFIG_NUM 1 > 1

      It might help..

      • scottwal

        Thanks, these values fixed the same error on my D90!

      • SKnight

        This also works for the Nikon D3100. Was about to try the ImageCapture function but my battery died ;( Looks like it all works though.

        THX!

  • Hi! i’m working in a Nikon D90 specific controller, (bulb shutter, intervalometer..) but i can’t know which are the “opcodes” that trigger for example in bulb mode. Can you give me some clue as might be found?
    Thanks for your work, is great!

    (sorry for every one that reads my horrible english)

  • karsten

    I’d recommend to pull the latest gphoto sources and start from there

  • gary

    I’m having some different success depending on the camera.

    First, I have to use these endpoints, or else there is no response at all:

    #define DATA_IN_EP 1
    #define DATA_OUT_EP 2

    Both the example PTP capture and PTPDevInfo sketches work fine with my D40.

    With a D7000, the capture sketch doesn’t work, and the PTPDevInfo sketch produces strange results, with the dump broken up between transaction errors and camera disconnections like this:

    Start
    0000: 59 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00
    0010: 00 00 64 00 13 6D 00 69 00 63 00 72 00 6F 00 73
    0020: 00 6F 00 66 00 74 00 2E 00 63 00 6F 00 6D 00 3A
    0030: 00 20 00 31 00 2E 00 30 00 00 00 00 00 2F 00 00
    0040: 00 01 10 02 10 03 10 04 10 05 10 06 10 07 10 08
    0050: 10 09 10 0A 10 0B 10 0C 10 0D 10 0E 10 0F 10 14
    0060: 10 15 10 16 10 1B 10 C0 90 C1 90 C2 90 C3 90 C4
    0070: 90 C7 90 C8 90 C9 90 CA 90 CB 90 CC 90 CD 90 CE
    0080: 90 CF 90 01 92 02 92 03 92 04 92 05 92 06 92 07
    0090: 92 09 92 0A 92 0B 92 01 98 02 98 03 98 05 98 0F
    00A0: 00 00 00 01 40 02 40 03 40 04 40 05 40 06 40 07
    00B0: 40 09 40 0A 40 0C 40 0D 40 08 40 01 C1 02 C1 04

    Transaction: Response recieve error: 000E

    Transaction: Command block send error: 000E
    Camera disconnected

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x6(Microsoft)

    Vend.Ext.Ver.: 0x64
    microsoft.com: 1.0
    Func.Mode: 0x8E0

    Operations supported:
    1001 GetDeviceInfo
    1002 OpenSession
    1003 CloseSession
    1004 GetStorageIDs
    1005 GetStorageInfo
    1006 GetNumObjects
    1007 GetObjectHandles
    1008 GetObjectInfo
    1009 GetObject
    100A GetThumb
    100B DeleteObject
    100C SendObjectInfo
    100D SendObject
    100E InitiateCapture
    100F FormatStore
    1014 GetDevicePropDesc
    1015 GetDevicePropValue
    1016 SetDevicePropValue
    101B GetPartialObject
    90C0 Vendor defined
    90C1 Vendor defined
    90C2 Vendor defined
    90C3 Vendor defined
    90C4 Vendor defined
    90C7 Vendor defined
    90C8 Vendor defined
    90C9 Vendor defined
    90CA Vendor defined
    90CB Vendor defined
    90CC Vendor defined
    90CD Vendor defined

    Transaction: Response recieve error: 000E
    Camera disconnected

    The last portion with the “Operations supported:” section will continuously repeat in the serial monitor, over and over, but the initial hex only shows up once.

    Any ideas?

  • Hi Guys

    I have a arduino mini 3.3v and mini USB host, Im trying to upload the EOSremote code but running into trouble figuring out what code and what libraries needs to be present to make it work ? I have added all libraries that the EOSremote wants to include ie #include “USB.h” and and and , problem is evertime try compile I get “Qstate does not name a type”

    Can someone please maybe note down for me all files needed and steps to follow to get it working correctly ? or is the code faulty ?

    Any help is greatly appreciated

  • Adam

    I’ve been trying to use PTPCapture with a Nikon D200 camera. I am able to get the camera to take a picture, but only by unplugging the attached USB cable and then reconnecting. Even then, it only takes one picture.

    The following output was produced by 1) loading the code to Arduino with the camera off 2) turning on the camera 3) unplugging and replugging the USB cable to the camera.

    Start
    Session opened
    Transaction: Response recieve error: 2013
    CaptureImage error: 2013
    Camera disconnected
    Session opened
    CaptureImage: New object added.
    CaptureImage: Image captured.
    Camera disconnected

    What’s the best way to triage this further? Where can I get more info about the codes (ex. “2013”)?

  • Zegeer

    I am having the same problem with my Nikon Coolpix P5100. By turning off/on while connected to Arduino, the camera will capture one, then return:

    “Transaction: Response recieve error: 2019”

    PTP Dev Info :

    Camera disconnected
    PTP Init
    Addr:: 0001
    NI:: 0001
    PTP configured
    Session opened
    Camera connected
    00000000: 4F 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00
    00000010: 00 00 64 00 29 6D 00 69 00 63 00 72 00 6F 00 73
    00000020: 00 6F 00 66 00 74 00 2E 00 63 00 6F 00 6D 00 3A
    00000030: 00 20 00 31 00 2E 00 30 00 3B 00 20 00 4E 00 69
    00000040: 00 6B 00 6F 00 6E 00 20 00 50 00 54 00 50 00 20
    00000050: 00 45 00 78 00 74 00 65 00 6E 00 73 00 69 00 6F
    00000060: 00 6E 00 73 00 00 00 00 00 17 00 00 00 01 10 02
    00000070: 10 03 10 04 10 05 10 06 10 07 10 08 10 09 10 0A
    00000080: 10 0B 10 0C 10 0D 10 0E 10 0F 10 14 10 15 10 16
    00000090: 10 1B 10 01 98 02 98 03 98 05 98 0C 00 00 00 01
    000000A0: 40 02 40 03 40 04 40 05 40 06 40 07 40 08 40 09
    000000B0: 40 0A 40 0C 40 0D 40 05 00 00 00 03 50 04 50 11
    000000C0: 50 05 D0 07 D4 01 00 00 00 01 38 07 00 00 00 01
    000000D0: 38 01 30 06 30 08 30 0D 30 0A 30 00 38 12 4E 00
    000000E0: 69 00 6B 00 6F 00 6E 00 20 00 43 00 6F 00 72 00
    000000F0: 70 00 6F 00 72 00 61 00 74 00 69 00 6F 00 6E 00
    00000100: 00 00 06 50 00 35 00 31 00 30 00 30 00 00 00 12
    00000110: 43 00 4F 00 4F 00 4C 00 50 00 49 00 58 00 20 00
    00000120: 50 00 35 00 31 00 30 00 30 00 56 00 31 00 2E 00
    00000130: 31 00 00 00 0D 30 00 30 00 30 00 30 00 33 00 30
    00000140: 00 34 00 35 00 37 00 35 00 36 00 36 00 00 00

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x6(Microsoft)

    Vend.Ext.Ver.: 0x64
    microsoft.com: 1.0; Nikon PTP Extensions
    Func.Mode: 0x8E2

    Operations supported:
    1001 GetDeviceInfo
    1002 OpenSession
    1003 CloseSession
    1004 GetStorageIDs
    1005 GetStorageInfo
    1006 GetNumObjects
    1007 GetObjectHandles
    1008 GetObjectInfo
    1009 GetObject
    100A GetThumb
    100B DeleteObject
    100C SendObjectInfo
    100D SendObject
    100E InitiateCapture
    100F FormatStore
    1014 GetDevicePropDesc
    1015 GetDevicePropValue
    1016 SetDevicePropValue
    101B GetPartialObject
    9801 GetObjectPropsSupported
    9802 GetObjectPropDesc
    9803 GetObjectPropValue
    9805 GetObjectPropList

    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

    Device properties supported:
    5003 ImageSize
    5004 CompressionSetting
    5011 DateTime
    D005 Vendor defined
    D407 Perceived_Device_Type

    Capture formats:
    3801 EXIF_JPEG

    Image Formats:
    3801 EXIF_JPEG
    3001 Association
    3006 DPOF
    3008 WAV
    300D QT
    300A AVI
    3800 Undefined

    Manufacturer: Nikon Corporation
    Model: P5100
    Device ver.: COOLPIX P5100V1.1
    Serial num.: 000030457566

    • 2019 means “device busy”, you can either ignore it in the code or increase delay between commands.

      • Zegeer

        Thanks so much Oleg!

        I am very new to this, but found that if I erase the connection test from the loop it seems to work fine….

        if (stateConnected == stDisconnected || stateConnected == stInitial)
        {
        stateConnected = stConnected;
        Notify(PSTR(“Camera connected\r\n”)); }

  • psi3000

    I want to make a trail camera that can transmit via a wifi shield to my home network, which is of course within range, the pictures that it has taken. I dont care if it does it via ftp or serving them on a website. Does anyone know if this can be done. I have a coolpix 3100 and 3200, but I would buy a new camera if I knew I could get this to work.
    thanks

  • Geoff

    Hi Oleg

    Thanks again for your guidance on getting set up with your libraries.

    I notice we have some older EOS digitals not represented yet in your list. Not sure if this is where you want this posted, so feel free to delete if not. Here’s the PTPDevInfo output from a Canon EOS 300D which is running the 10D firmware hack (sometimes called the “russian firmware” etc.

    I’m pretty sure one of our bodies still has the original 300D firmware on it too so will test that and if it differs post it too.

    EOS 300D / Digital Rebel

    Start
    Camera disconnected
    PTP Init
    Addr:: 0001
    NI:: 0001
    PTP configured
    Session opened
    Camera connected
    00000000: AF 00 00 00 02 00 01 10 02 00 00 00 64 00 00 00
    00000010: 00 00 00 00 00 00 00 0E 00 00 00 01 10 02 10 03
    00000020: 10 04 10 05 10 06 10 07 10 08 10 09 10 0A 10 0B
    00000030: 10 0C 10 0D 10 1B 10 04 00 00 00 01 40 02 40 03
    00000040: 40 09 40 00 00 00 00 00 00 00 00 06 00 00 00 01
    00000050: 30 01 38 0A 30 08 30 02 30 00 00 0B 43 00 61 00
    00000060: 6E 00 6F 00 6E 00 20 00 49 00 6E 00 63 00 2E 00
    00000070: 00 00 15 43 00 61 00 6E 00 6F 00 6E 00 20 00 44
    00000080: 00 69 00 67 00 69 00 74 00 61 00 6C 00 20 00 43
    00000090: 00 61 00 6D 00 65 00 72 00 61 00 00 00 08 30 00
    000000A0: 31 00 2E 00 30 00 30 00 30 00 31 00 00 00 00

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x0(Unknown)

    Vend.Ext.Ver.: 0x0

    Func.Mode: 0x8E2

    Operations supported:
    1001 GetDeviceInfo
    1002 OpenSession
    1003 CloseSession
    1004 GetStorageIDs
    1005 GetStorageInfo
    1006 GetNumObjects
    1007 GetObjectHandles
    1008 GetObjectInfo
    1009 GetObject
    100A GetThumb
    100B DeleteObject
    100C SendObjectInfo
    100D SendObject
    101B GetPartialObject

    Events supported:
    4001 CancelTransaction
    4002 ObjectAdded
    4003 ObjectRemoved
    4009 RequestObjectTransfer

    Device properties supported:

    Capture formats:

    Image Formats:
    3001 Association
    3801 EXIF_JPEG
    300A AVI
    3008 WAV
    3002 Script
    0 Vendor defined

    Manufacturer: Canon Inc.
    Model: Canon Digital Camera
    Device ver.: 01.0001
    Serial num.:

    Cheers, Geoff

  • Gabriel

    Here is the one for pentax K7 with latest firmware (only works in PTP mode and in MSC it gives a error)
    Here there’s a opensource tethering software (http://pktriggercord.sourceforge.net/) but I can’t manage to send the codes for the init or to make a capture. Can you give me some tipes about where to start and what documentation read?

    Thanks

    00000000: CB 00 00 00 02 00 01 10 02 00 00 00 64 00 06 00
    00000010: 00 00 64 00 13 6D 00 69 00 63 00 72 00 6F 00 73
    00000020: 00 6F 00 66 00 74 00 2E 00 63 00 6F 00 6D 00 3A
    00000030: 00 20 00 31 00 2E 00 30 00 00 00 00 00 16 00 00
    00000040: 00 01 10 02 10 03 10 04 10 05 10 06 10 07 10 08
    00000050: 10 09 10 0A 10 0B 10 0C 10 0D 10 0F 10 14 10 15
    00000060: 10 16 10 1B 10 01 98 02 98 03 98 05 98 03 00 00
    00000070: 00 03 40 04 40 05 40 03 00 00 00 11 50 06 D4 07
    00000080: D4 00 00 00 00 07 00 00 00 01 30 06 30 0A 30 0D
    00000090: 38 01 38 00 38 00 30 07 50 00 45 00 4E 00 54 00
    000000A0: 41 00 58 00 00 00 04 4B 00 2D 00 37 00 00 00 05
    000000B0: 31 00 2E 00 31 00 31 00 00 00 08 33 00 34 00 31
    000000C0: 00 36 00 33 00 34 00 31 00 00 00

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x6(Microsoft)

    Vend.Ext.Ver.: 0x64
    1091059911411111511110211646991111095832494648
    Func.Mode: 0x21DA

    Operations supported:
    1001 GetDeviceInfo
    1002 OpenSession
    1003 CloseSession
    1004 GetStorageIDs
    1005 GetStorageInfo
    1006 GetNumObjects
    1007 GetObjectHandles
    1008 GetObjectInfo
    1009 GetObject
    100A GetThumb
    100B DeleteObject
    100C SendObjectInfo
    100D SendObject
    100F FormatStore
    1014 GetDevicePropDesc
    1015 GetDevicePropValue
    1016 SetDevicePropValue
    101B GetPartialObject
    9801 GetObjectPropsSupported
    9802 GetObjectPropDesc
    9803 GetObjectPropValue
    9805 GetObjectPropList

    Events supported:
    4003 ObjectRemoved
    4004 StoreAdded
    4005 StoreRemoved

    Device properties supported:
    5011 DateTime
    D406 Session_Initiator_Version_Info
    D407 Perceived_Device_Type

    Capture formats:

    Image Formats:
    3001 Association
    3006 DPOF
    300A AVI
    380D TIFF
    3801 EXIF_JPEG
    3800 Undefined
    3000 Undefined

    Manufacturer: 806978846588
    Model: 754555
    Device ver.: 49464949
    Serial num.: 51524954515249

    • I see no camera control operations, nor do I see any vendor-specific ones. It seems that remote control protocol for this camera is not PTP based.

  • Alex Gorn

    Here is my PTPDevInfo for original Canon EOS 350D. I expected this camera to work perfectly with your examples, but this is not the case. Actually nothing works. I am getting Error: 2005

    May be you can help. Спасибо!

    Start
    Session opened
    0000: 1D 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 07
    00B0: 00 00 00 02 30 06 30 0A 30 08 30 01 38 01 B1 03
    00C0: B1 0B 43 00 61 00 6E 00 6F 00 6E 00 20 00 49 00
    00D0: 6E 00 63 00 2E 00 00 00 17 43 00 61 00 6E 00 6F
    00E0: 00 6E 00 20 00 45 00 4F 00 53 00 20 00 33 00 35
    00F0: 00 30 00 44 00 20 00 44 00 49 00 47 00 49 00 54
    0100: 00 41 00 4C 00 00 00 0A 33 00 2D 00 30 00 2E 00
    0110: 30 00 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: 0x8E0

    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

    Manufacturer: Canon Inc.
    Model: Canon EOS 350D DIGITAL
    Device ver.: 3-0.0.0.1
    Serial num.:

    • Can you be more specific about “nothing”? I can see that PTPDevInfo is working quite well. If you want to control this camera, you need to use EOS-specific code.

      • Yes of course. Sorry.

        So I can start session but Eos.Capture() causes error: 2005. Eos.SwitchLiveView(state_view) results error 0004 and error 2002. Same for EOS_DPC_ShutterSpeed, EOS_DPC_WhiteBalance etc.

        Same code works well on EOS 1D Mac IV

        • 350D doesn’t support LiveView. The rest should work – I’ll double check it and let you know.

          • Thank you very much!

            Also 350D has two communication modes “Print/PTP” and “PC Connection”. When I set my camera to “Print/PTP” it constantly flashes “Busy” if USB cable is connected. So I assume it should be “PC Connection”?

            In my code I am controlling:
            Eos.SetProperty(EOS_DPC_Iso, XXXX);
            Eos.SetProperty(EOS_DPC_ShutterSpeed, XXXX);
            Eos.SetProperty(EOS_DPC_WhiteBalance, XXXX);
            Eos.SetProperty(EOS_DPC_Aperture, XXXX);
            Eos.MoveFocus(0x01, 0x02, 0x03);
            Eos.MoveFocus(0x8001, 0x8002, 0x8003);

            I am getting errors 2005 and 2004 on 350D, but all this works fine on 1D Mac IV

        • Alex

          Hi Alex!
          2005 error code stands for “Operation is not supported” and as I can see it in the PTPDeviceInfo dump you posted, EOS_OC_Capture (0x910f) command is not on the list, which means it’s not supported. 0x04 – is NAK returned by the camera and converted into 2002 (PTP_RC_GeneralError) by PTP library obviously because your camera is not capable of LiveView functionality. The same for EOS_OC_SetDevicePropValue(0x9110). It’s not on the list. The dump looks rather PowerShot than EOS. If model name was not written at the end of the dump I would think it was PowerShot. Make sure you have the latest firmware burnt for your type of camera.

  • Here is another PTPDefInfo from my EOS 1D Mac IV, just in case you need it. It works like a charm. I made a simple remote for my camera – perfect. May be you can tell me what should I do to shot video (Start/Stop) with it.

    Заранее спасибо!

    Start
    Session opened
    0000: F3 01 00 00 02 00 01 10 02 00 00 00 64 00 06 00
    0010: 00 00 C8 00 00 00 00 82 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 60 91 55 91 57 91 58 91 59 91 5A
    0090: 91 1F 91 FE 91 FF 91 28 91 29 91 2D 91 2E 91 2F
    00A0: 91 2C 91 30 91 31 91 32 91 33 91 34 91 2B 91 01
    00B0: 98 02 98 03 98 04 98 05 98 C0 91 C1 91 C2 91 C3
    00C0: 91 C4 91 C5 91 C6 91 C7 91 C8 91 C9 91 CA 91 CB
    00D0: 91 CC 91 CE 91 CF 91 D0 91 D1 91 D2 91 E1 91 E2
    00E0: 91 E3 91 E4 91 E5 91 E6 91 E7 91 E8 91 E9 91 EA
    00F0: 91 EB 91 EC 91 ED 91 EE 91 EF 91 F8 91 F9 91 F2
    0100: 91 F3 91 F4 91 F7 91 22 91 23 91 24 91 F5 91 F6
    0110: 91 52 90 53 90 57 90 58 90 59 90 5A 90 5F 90 07
    0120: 00 00 00 09 40 04 40 05 40 03 40 02 40 07 40 01
    0130: C1 04 00 00 00 02 D4 07 D4 06 D4 03 D3 01 00 00
    0140: 00 01 38 0B 00 00 00 01 30 02 30 06 30 0A 30 08
    0150: 30 01 38 01 B1 03 B1 02 BF 00 38 04 B1 0B 43 00
    0160: 61 00 6E 00 6F 00 6E 00 20 00 49 00 6E 00 63 00
    0170: 2E 00 00 00 15 43 00 61 00 6E 00 6F 00 6E 00 20
    0180: 00 45 00 4F 00 53 00 2D 00 31 00 44 00 20 00 4D
    0190: 00 61 00 72 00 6B 00 20 00 49 00 56 00 00 00 08
    01A0: 33 00 2D 00 31 00 2E 00 30 00 2E 00 38 00 00 00
    01B0: 21 39 00 34 00 36 00 65 00 38 00 63 00 61 00 62
    01C0: 00 66 00 36 00 38 00 65 00 34 00 34 00 62 00 36
    01D0: 00 38 00 38 00 36 00 66 00 66 00 64 00 37 00 63
    01E0: 00 61 00 37 00 31 00 61 00 38 00 32 00 65 00 38
    01F0: 00 00 00

    Std.Ver.: 0x100
    Vendor Ext. ID: 0x6(Microsoft)

    Vend.Ext.Ver.: 0xC8

    Func.Mode: 0x8E0

    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
    9160 Vendor defined
    9155 EOS_MoveFocus
    9157 Vendor defined
    9158 Vendor defined
    9159 Vendor defined
    915A Vendor defined
    911F Vendor defined
    91FE Vendor defined
    91FF Vendor defined
    9128 Vendor defined
    9129 Vendor defined
    912D Vendor defined
    912E Vendor defined
    912F Vendor defined
    912C Vendor defined
    9130 Vendor defined
    9131 Vendor defined
    9132 Vendor defined
    9133 Vendor defined
    9134 Vendor defined
    912B Vendor defined
    9801 GetObjectPropsSupported
    9802 GetObjectPropDesc
    9803 GetObjectPropValue
    9804 SetObjectPropValue
    9805 GetObjectPropList
    91C0 Vendor defined
    91C1 Vendor defined
    91C2 Vendor defined
    91C3 Vendor defined
    91C4 Vendor defined
    91C5 Vendor defined
    91C6 Vendor defined
    91C7 Vendor defined
    91C8 Vendor defined
    91C9 Vendor defined
    91CA Vendor defined
    91CB Vendor defined
    91CC Vendor defined
    91CE Vendor defined
    91CF Vendor defined
    91D0 Vendor defined
    91D1 Vendor defined
    91D2 Vendor defined
    91E1 Vendor defined
    91E2 Vendor defined
    91E3 Vendor defined
    91E4 Vendor defined
    91E5 Vendor defined
    91E6 Vendor defined
    91E7 Vendor defined
    91E8 Vendor defined
    91E9 Vendor defined
    91EA Vendor defined
    91EB Vendor defined
    91EC Vendor defined
    91ED Vendor defined
    91EE Vendor defined
    91EF Vendor defined
    91F8 Vendor defined
    91F9 Vendor defined
    91F2 Vendor defined
    91F3 Vendor defined
    91F4 Vendor defined
    91F7 Vendor defined
    9122 Vendor defined
    9123 Vendor defined
    9124 Vendor defined
    91F5 Vendor defined
    91F6 Vendor defined
    9052 Vendor defined
    9053 Vendor defined
    9057 Vendor defined
    9058 Vendor defined
    9059 Vendor defined
    905A Vendor defined
    905F Vendor defined

    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
    D303 Vendor defined

    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
    B104 Vendor defined

    Manufacturer: Canon Inc.
    Model: Canon EOS-1D Mark IV
    Device ver.: 3-1.0.8
    Serial num.: 946e8cabf68e44b6886ffd7ca71a82e8

    • Alex

      Shooting video is the question that captures my mind. Apparently, old cameras, I was lucky to test the library code on, had no video commands available via PTP protocol, but the dump taken with your EOS-1D Mark IV shows much wider range of commands. If you have any Canon or third party vendor software capable of shooting video, I think I’ll be able to figure it out.

    • There is a project called DSLRRC -> http://crispconcept.com/android.php built using USB Host Shield and PTP library. It supports video recording and Arduino code is available. You may want to tale a look into it and see how it was done.

  • tommykay

    Oleg, you say, “this one can’t really be called NikonCapture – keep reading to find out why.”

    But I don’t see the answer.

    • Nikon P&S cams take generic Capture command with no prerequisites, all other cameras need either their own command or vendor-specific initialization. That’s why it’s not called NikonCapture – the sketch doesn’t contain any vendor-specific code.

  • tommykay

    I see your logic.

    On the other hand, seeing EOScapture for EOS the Examples, most people would assume to find a NikonCapture in the Nikon examples. Why not include a copy there? Even if the sketch contained just a comment saying the generic capture works with Nikons.

    Also, it would be helpful to include a one-liner remark at the top of each sketch, describing what they do.

    That might save you from answering pitiful questions like this one. 🙂 🙂

    Again, thanks for your excellent work on this, Oleg.

    • The capture command is the only shooting control command supported by Nikon compacts, it is not worth making a special section. Nikon examples are given for DSLRs, they are quite different from compacts.

  • tommykay

    The code on this page is different from the code in PTPCapture in Library Examples. Capitalization doesn’t match other libraries, for one.

    So I’m guessing this code is obsolete, and replaced by the PTPCapture sketch, is that right? Or is this for a different rev or model board than the full size host shield 2.0 I am using?

    Also, is there a place to look up error codes, or share the ones you’ve found? I discovered that you get a 2002 error if you are using an old manual lens, but forgot to put the set the dial to M. (Duh.) Even with a modern lens, my D40 throws a 201E error, but takes the picture anyway.

    • The code works with legacy library, which can be found by following links at the beginning of the article. Many people still use this library – it gives smaller code size. Also, the code structure of PTP 2.0 is very similar to the legacy one and old posts can still be used as a source of information. Legacy library is compatible with USB Host Shield 2.0.

      Response codes can be found in https://github.com/felis/PTP_2.0/blob/master/ptpconst.h , starting at line 109.

  • tommykay

    Thank you. I understand. If the original article can still be edited, you might post these details with it. As it reads now, a person will not know the things you just wrote.

    I also now understand why you say (in another thread) that the documentation is in the source code. Yes, this is valuable information, but not a substitute for documentation.

    Thanks for the detailed response, Oleg. I am grateful.

  • thorben

    Hi, when I try to compile your program with the USB Host Shield 2.0 Library and the PTP 2.0 Library I get following errors. I have no idea how to fix them.

    PTPObjInfo:38: error: no matching function for call to ‘PTP::PTP(int, int, int, int, int, CamStateHandlers*)’
    /Users/thorbenschoepe/Documents/Arduino/libraries/ptp20master/ptp.h:114: note: candidates are: PTP::PTP(USB*, PTPStateHandlers*)
    /Users/thorbenschoepe/Documents/Arduino/libraries/ptp20master/ptp.h:60: note: PTP::PTP(const PTP&)
    PTPObjInfo.pde: In function ‘void setup()’:
    PTPObjInfo:63: error: ‘class PTP’ has no member named ‘Setup’
    /Users/thorbenschoepe/Documents/Arduino/libraries/ptp20master/ptp.h: In function ‘void loop()’:
    /Users/thorbenschoepe/Documents/Arduino/libraries/ptp20master/ptp.h:66: error: ‘void PTP::Task()’ is protected
    PTPObjInfo:69: error: within this context

  • thorben

    I changed the library to the one on top, the last error I got:
    /Users/thorbenschoepe/Documents/Arduino/libraries/ArduinoCameraControlmaster2/ptp.cpp: In function ‘void Notify(const char*)’:
    /Users/thorbenschoepe/Documents/Arduino/libraries/ArduinoCameraControlmaster2/ptp.cpp:108: error: ‘BYTE’ was not declared in this scope

    • thorben

      I fixed the issue with changing the code from Serial.print(c,BYTE) to Serial.write(c). I don’t get any errors anymore but when I upload teh code to my arduino uno and connect it to the D200 via Sparkfun Host Shield nothing happens at all. The D200 is set on PTP.