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

8.6K3513

Intro: 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!

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.

11 Comments

What is GCODE interface and how to connect to CNC mill?
Thanks for sharing
Most CNC devices take their instructions via a serial input stream in a command language called GCODE. Connections can be via serial over USB, old-fashioned RS232 serial, or even parallel port - it all depends on your specific CNC hardware. Once you have your CNC mill and know how to connect to it, you can send it GCODE commands. There's a lot of info on GCODE on the net if you search for it - it's too large a subject for me to explain here. Not all CNC users are aware of the details of GCODE - many CNC users just use applications that work in terms of 2D or 3D models and the GCODE details are hidden by the application; nevertheless the GCODE interface is usually still available to you if you look for it. It will be in the manual for your equipment somewhere. You might be able to find a local Maker Space where someone can give you an introduction to using CNCs and get you started. It *is* possible to buy a CNC online and teach yourself to use it, but to get to the stage where you can easily write GCODE and do the things I was suggesting in the article above, you may need a few months to learn your way around.
Nice instructable and clever usage of resources.
Is 'CombineZP' is maintained currently?
Can not locate it's official site / developer page
Any pointer to this will be appreciated
Would someone please tell me what a CNC tool is?
CNC stands for computer numerically controlled machining. You write a program and send it to the machine, set the tool heights, set your XYZ zero points. If you set all the parameters right and hit GO the machine will start milling the part you programmed it to make. That's a very basic explanation from a machinist of 25 years.
Love the project! What CNC controller are you using? I can send you a Smoothieboard for free if you are ready to do a short writeup in the smoothie documentation on how somebody would reproduce the CNC-controller-related steps of what you are doing.
The CNC is a Sainsmart 3018 and the controller board is their GRBL one. I do appreciate the offer of a free board but really there is nothing at all controller-specific in the way I'm using this. The G-Code to move the Z axis is pretty simple - something like "G0 Z15" for example to set the Z axis to 15mm above the surface. You could do it trivially with the Jog controls of any package.
Quite simply, brilliant idea. I’ll be doing this later today.
I don't hava a CNC. Neither do I have a PiCamera. But a 3D printer and a fixed-focus endoscope camera could do the trick. Thanks.