[EDIT] Here is a build log of mini-variant of this device.[/EDIT]
One of my favorite shooting techniques is focus stacking. Many pictures on Circuits@Home site are made using this technique. I use Helicon Focus for post processing and even though this program has camera control built-in, it obviously requires a computer close to the object of shooting. In order to be able to control my camera in the field, I wanted to replace a laptop with simple lightweight controller able to move focus of camera lens and take pictures between steps. In this article, I will show how to build one from Arduino, USB Host Shield and several small parts.
Finished circuit can be seen on the title picture. As you may already have guessed, the sequence of shots used to produce the picture has been made with the very unit depicted on it. Focus stacking assistant is controlled by 3 buttons: first moves focus towards the camera, second moves focus away from the camera, third button starts shooting sequence. Long press on focus move button sets “near” of “far” points, after both points are set shooting sequence can be run – it always starts from “near” point. The sequence can be stopped at any time by pressing on any of focus move buttons. It is important to understand that after a point is set, subsequent focus moves must be performed with focus move buttons only.
The controller can also be set to “free run” mode. Long press on third button starts shooting sequence from current lens position (which in this case can be set by hand using lens’ focusing ring) towards infinity and will run indefinitely. It can be stopped at any moment by pressing on a focus move button.
A single LED shows states of the controller. Short blink once a second indicates “idle” state – controller is connected to the camera, PTP session is open. Continuous frequent blinking means some kind of an error – most likely, controller not being able to initialize the camera or open PTP session. 3 short blinks act as a feedback to long press, focus move, etc. Additionally, more detailed diagnostic is output to Arduino serial console.
Even while connected to the camera, Focus Stacking Assistant allows camera buttons to function as usual. For example, camera LCD can be turned on and zoom area can be moved to the area of interest and then zoomed in to help focusing. Shooting mode, as well as aperture/shutter speed/ISO can be changed. It is also possible to access or erase images on the card and perform other manipulations as necessary.
Let’s now talk about how building the assistant. Links to Arduino board and USB Host Shield has been given at the beginning of the article, refer to USB Host Shield hardware manual for connection instructions. The protoshield is also handy, I prefer ones from Adafruit, maybe I’m just lucky but I’m always receiving blue ones which match nicely with Arduino and host shield. You will also need some wire, a LED, current-limiting resistor (Adafruit sells all of that), and 3-4 tactile switches. The connections can be figured out from title picture, here is “formal” schematic just in case.
The control software is hosted on gitHub. It depends on USB Host Shield library r.2.0, PTP library r.2.0 and Quantum Leaps state machine framework AKA QP (the code uses standard Arduino variant of QP from Quantum Leaps site, not the modification made for PTP library examples!). The state machine design has been made using QM modeling tool and model file is included in the repo for your viewing pleasure.
The code has been extensively tested with Canon 5D Mark II and XSi cameras, it should work with any Canon DSLR with LiveView function. The code is in beta, it is a little slow and maximum exposure time is around 1-2 sec depending on the camera and lens model. In coming weeks I’m going to build and test Mini variant of the circuit and write code for Nikon DSLRs. As always, stay tuned for the updates and if you build this circuit, please share your experience in the comments!
Oleg.
Hello Oleg,
I have a problem ,can you tell me.what command can get canon camera product id?
Thanks!
I believe it’s part of device info -> https://github.com/felis/PTP_2.0/tree/master/examples/ptpsketches/PTPDevInfo
I’ll learn it ,Than you very much!
Hi ,
Is there a way to use your library with arduino 2 ?
Thanks in advance!
what is arduino 2?
Arduino due ;p
It won’t work with Due, sorry.
=( thanks
Hi, Oleg,
I have read Michael and your discussion, but, still confused.
I have been struggling to comfile FSA sketch…
I have some questions.
What is your best suggestion for compiling FSA
1. Arduino IDE Version?
2. QPC or QPC++ or QP_Arduino?
QP Version? 4.3.00 or 4.5.02?
3. USB_Host_Library/Example Version? 2.0 or 1.0
4. PTP_Library/Example Version? 2.0 or Arduino_Camera_Control
Thanks, in advance…
Hello Oleg,
I have a problem ,can you tell me.
what command can change camera form AF mode to MF mode,or reverse.
Thanks!
I’m not sure if there is such a command. I just flip a switch on the lens.
I see,thank you!
Hello Oleg, i want command focus in nikon, you can help me? Thanks
When using the usb host shield with the the ptp 2.0 library, do the pictures/videos get pushed back up the wire? I would like to take a picture using something like the yanis eos controller, and have the image transferred back to a host a computer.
you can read images/videos, the library supports it, the method name is
GetObject()
.Hi,
is fsa_eos still supported? I spent hours trying to get it compiled with qp without luck. Unfortunately I was uable to find qp version 4.3.00 but just the latest.Examples compile but not fsa_eos.
Any idea what to do?
Some error messages:
In file included from bsp.cpp:52:
/qp_port.h:65:79: error: qf_port.h: No such file or directory
/qp_port.h:66:79: error: qassert.h: No such file or directory
/qp_port.h:71:79: error: qs_dummy.h: No such file or directory
In file included from /bsp.h:32,
from bsp.cpp:54:
C:\Users\noone\Documents\Arduino\libraries\USB_Host_Shield_20/message.h:18:2: error: #error “Never include message.h directly; include Usb.h instead”
In file included from bsp.cpp:52:
qp_port.h:109: error: ‘QEvt’ does not name a type
In file included from bsp.cpp:53:
fsa.h:26: error: ‘Q_USER_SIG’ was not declared in this scope
I don’t support fsa_eos anymore; however, your errors mean that compiler can’t see QP source. Have you tried to compile any of examples that came with QP? 4.3 should still be available on SF, if not, ask in the support forum.
Hello Oleg,
I’m still new using USB Host Shield.
While i compile the pde file using Arduino IDE (1.0.5-r2 version), there’s error :
bsp.cpp:44:21: error: qp_port.h: No such file or directory
In file included from /bsp.h:24,
from bsp.cpp:46:
C:\Users\rezaalfath\Documents\Arduino\libraries\USBHost/message.h:18:2: error: #error “Never include message.h directly; include Usb.h instead”
In file included from bsp.cpp:45:
fsa.h:19: error: ‘Q_USER_SIG’ was not declared in this scope
fsa.h:79: error: expected class-name before ‘{‘ token
fsa.h:85: error: expected initializer before ‘*’ token
fsa.h:86: error: expected initializer before ‘*’ token
fsa.h:87: error: expected initializer before ‘*’ token
fsa.h:88: error: expected initializer before ‘*’ token
fsa.h:89: error: expected initializer before ‘*’ token
bsp.cpp:49: error: ‘Q_DEFINE_THIS_FILE’ does not name a type
bsp.cpp: In function ‘void __vector_7()’:
bsp.cpp:103: error: ‘DebouncedState’ was not declared in this scope
bsp.cpp:109: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:109: error: ‘QEvent’ was not declared in this scope
bsp.cpp:109: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:113: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:113: error: ‘QEvent’ was not declared in this scope
bsp.cpp:113: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:120: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:120: error: ‘QEvent’ was not declared in this scope
bsp.cpp:120: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:124: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:124: error: ‘QEvent’ was not declared in this scope
bsp.cpp:124: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:131: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:131: error: ‘QEvent’ was not declared in this scope
bsp.cpp:131: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:135: error: ‘AO_Controls’ was not declared in this scope
bsp.cpp:135: error: ‘QEvent’ was not declared in this scope
bsp.cpp:135: error: ‘Q_NEW’ was not declared in this scope
bsp.cpp:148: error: ‘QF’ has not been declared
bsp.cpp: At global scope:
bsp.cpp:173: error: ‘QF’ has not been declared
bsp.cpp:183: error: ‘QF’ has not been declared
bsp.cpp:187: error: ‘QF’ has not been declared
bsp.cpp:187: error: variable or field ‘onIdle’ declared void
bsp.cpp:187: error: ‘QF_INT_KEY_TYPE’ was not declared in this scope
bsp.cpp:228: error: expected ‘,’ or ‘…’ before ‘*’ token
bsp.cpp: In function ‘void Q_onAssert(char)’:
bsp.cpp:232: error: ‘line’ was not declared in this scope
Can you help me fixed this?
Thanks
Have you installed QP yet? It is used in the code – that’s why you’re getting these errors.
Hi Oleg,
i try to build something where i control an EOS 1200d and two stepper engines. Camera works fine with USB Shield and your library. Stepper Shield works finde too, until i setup Usb.Init() .After this the stepper shield doesn’t work. Is there any way to use boath shields at the same time?
I’m not familiar with Stepper Shield you’ve mentioned. If it uses SPI for control you may want to take a look at this series of articles for ideas -> https://www.circuitsathome.com/mcu/running-multiple-slave-devices-on-arduino-spi-bus .
Hi,
I just came upon your excellent article on focus stacking. What model of the Arduino did you use. The link in the article is dead.
Thanks
Jas
It’s Uno, and I also fixed the link 🙂