Need advice on how to use CHDKPTP to retrieve file name of last picture taken

  • 1 Replies
I'd like to use an AVR2560 or ARM Cortex-M4F microcontroller to somehow trigger a Canon to take a picture and then I'd like to retrieve that pictures filename (not the file itself, just an identifier of the picture) back into the microcontroller so that it can be stored in a log file.  The microcontroller is actually a multicopter flight controller so it knows it's attitude, gps location, etc but I want to make sure that after the flight, when the user downloads the dataflash files from the microcontroller and the images from the camera that they can easily be tied together.  So this is why I would like the microcontroller to get the file location so it can store it along with the position data.

I had a look through the scripting cross reference page but I didn't see an obvious way using chdkptp to get the filename of the image just taken.

Any suggestions?

P.S. I'm fairly experienced with embedded programming but not at all experienced with CHDK yet.
The flight controllers I'm talking about are the APM2.6 or PX4 running "ArduCopter".


Offline reyalp

  • ******
  • 11087
The CHDK PTP interface mostly works by sending Lua code to the camera to run.

Using Lua, you can get the last file name using something like
Code: [Select]
Note in some situations, it might be sufficient to just store the number, or the number and time to disambiguate if it wraps around.

To get this from a microcontroller, you will need a USB stack, and a PTP client library, and implement enough of the CHDK PTP protocol to execute scripts and read the messages containing the script return value.

Information about the PTP protocol can be found at

Some people have successfully implemented PTP support on Arduino, see

An alternate approach would be to trigger the shots using GPIO from your microcontroller with USB remote function and log enough information on the camera to correlate the images and flight controller data later.

A note on terminology.
"CHDK PTP" refers to the PTP extension in CHDK.

"chdkptp" generally refers to the PTP client I wrote:
This can be built for normal linux distros and windows, but would probably be difficult to port to a microcontroller environment. It might be a useful example if you end up writing your own client.
Don't forget what the H stands for.


Related Topics