Automated Macro Photography

Open Source MacroRail Application

I’ve just uploaded the beta of an Open Source Windows application (x64 only at this stage) to Github. It’s used for automatically capturing the images for stacking macro images. It connects to most Nikon cameras and sets up the camera, provides a live-view for setting up the shot, takes the photo, downloads the images and shows a preview of the shot just taken. You can also use it with other cameras by switching on manual mode.

The camera controls in the application currently only works with Nikon cameras and only on x64bit systems because the Nikon SDK only supports that system and Mac’s (I don’t have a Mac to try it). I’m looking to change this in the future with the inclusion of an open source library that supports other manufacturers cameras and other operating systems.

This is a photo of my D800 with extension tubes and a 105mm macro lens. The Nikon 105mm macro doesn’t focus inside the lens like many others.

Why a Macro Rail

When doing close up (macro) photography the depth of field of the image, or how much of the image is in focus, is very narrow. To get the whole subject in focus you have to take many shots and combine the in-focus part off the image to make a single image with the whole subject in focus. With very small subject this can means tens to many hundreds of photographs taken at very slightly different distances from the subject. The automated macro rail does all this for you so you can just set it up and come back once it’s finished.

Wikipedia has some good articles on macrophotography and focus stacking here:

Macro Photography:

Focus Stacking:

Note: The Wikipedia Focus Stacking article lists software for performing the stacking of the images.


The macro rail used is completely oversized for macro-photography - I’m going to use it as a slider as well. You also don’t need a NEMA23 motor like I sed here for similar reasons.

The application communicates with a Pololu TIC stepper motor controller. These controllers provide everything you need for this solution. The TIC provides limit switch inputs (I used inductive proximity sensors), acceleration, positioning, current limiting and fault control. Core Electronics sells them here:

TIC T500 - 4.5 V to 35 V - 1.5 A - fullhalf1/41/8 - MP6500 driver
TIC T835 - 2.5 V to 10.8 V - 1.5 A - fullhalf1/41/81/161/32 - DRV8834 driver
TIC TT825 - 8.5 V to 45 V - 1.5 A - fullhalf1/41/81/161/32 - DRV8825 driver
TIC T249 - 10 V to 47 V - 1.8 A - fullhalf1/41/81/161/32 - TB67S249FTG driver
TIC T36v4 - 8 V to 50 V - 4 A - fullhalf1/41/81/161/321/641/1281/256 - discrete MOSFETs

I went with the TIC T36v4 to take advantage of the wide voltage supply, lots of micro-step options and high current. A TIC T249 would have driven the project easily but there’s very little difference in price and I had a TIC T36v4 in my stock.

The electronics for this project is very simple. You just need to wire a stepper motor into the TIC controller, provide the TIC it with power (I used a 19v laptop supply), connect the limit switches or proximity sensor to the TIC (RX/TX - configured as sensor input), connect the TIC and the camera to the computer via a couple of USB cables - I used a USB hub mounted to the rail.

For the rail I used an actuator kit from Maker Store, but for most applications you can use a much smaller and cheaper rail or make one yourself.


I spent the last three weeks building the project and have only one test shoot :slightly_smiling_face:.

This image is made up of 50 images. More than I need, but I was testing the rail.

More Information

More information can be found on Github:


Hi Shaun, welcome back!

This is an incredible project that will be a boon to anyone working with windows and Nikon! (I work on Sony and Linux unfortunately, but you’ve laid the groundwork here, so maybe someone will fork it!).

Fantastic stuff :smiley:


I’m looking to replace the Nikon library with a pure C# library that will be able to shoot with many other camera soon. In the meantime, you can also use it with other cameras by clicking on the manual shoot option. It will halt after each move and wait for you yo click on the button in a dialog.


Damn that’s a polished project @Shaun21504 :smiley: you can really see the love that’s gone into it.
10/10 project, thanks for sharing :clap:

1 Like

I’ve got a RasPi solution that can do this :stuck_out_tongue:

1 Like

I was looking at the gphoto2 library you’re using. If only there was a library that was cross platform, including Windows without having to make lots of code modifications.

1 Like

Yeah, it’s a shame, but Gphoto2 is great for linux :stuck_out_tongue:

1 Like