Introduction: Convert Your CNC to a Macro Photography Rail in 30 Seconds Flat!

If you're lucky enough to already own a CNC milling machine, here's a way to turn it into a 'rail camera' for 'focus stacked' or 'extended depth of field (EDOF)' macro photography. When you get really close to an object to take macro photos, your camera doesn't have very much depth of field, so a technique was invented to take multiple photographs from different heights, each one contributing a slice of the final picture. In order to get good coverage, the camera distance should be moved in small and equal steps between frames - which is something that a CNC mill can easily do!

Supplies

1) CNC mill

2) 1/8th in shaft from Dremel tool

3) Raspberry Pi Camera and Raspberry Pi

Step 1: You'll Need One Simple Tool...

If you have a CNC mill there's a pretty good chance you have one of these lying around - it's a shaft to connect various types of tool to a Dremel. Or you can buy one for pennies. It's the type of shaft that has a screw in the end.

Step 2: Attach the Shaft to a Corner of Your Raspberry Pi Camera

Many people who have CNC mills already have a webcam or Raspberry Pi camera attached, to remotely view or record their CNC work. If you have one, just remove it from its mount.

You'll want to adjust the focus to the closest possible. Official Pi cameras have a small lens that is lightly tacked in place to stop the focus drifting - you may need to break the glue to turn the lens into close-up mode. There are also Chinese clones of the PiCam which look similar but the lens is in a one-piece holder and cannot be focused.

The ideal lens is one similar to the attached images, which is easily re-focused, such as comes with the ArduCam cameras.

Attach the shaft to a corner of your Raspberry Pi Camera - any corner will do.

Step 3: ... and Insert the Shaft Into the Collet.

It fits in to the tool holder collet just like any CNC tool. Obviously you don't want to spin the motor! Either just be careful not to turn the spindle on, or be extra cautious and remove the +/- wires to the spindle (which you can cover with tape to avoid accidental shorts).

Step 4: And Now Take Some Pictures!

Use the GCODE interface to raise or lower the Z axis a small unit at a time (eg 0.5mm) and snap a photo using the raspistill command on your Raspberry Pi. Then process the image stack with one of many utilities, such as CombineZP, PicoLay, EnFuse, and TuFuse. Experienced CNC users/programmers could easily automate the rail movement and picture taking.