Search This Blog

Sunday, March 6, 2011

Arduino based XYZ CNC Carving Machine

Starting a new thread now that I have a plan....


After some poking around researching building a small CNC machine for light carving, I came to the conclusion that the Zen toolworks CNC machine was a good deal and would shave months off my project.   I figured by the time I collected steppers, lead screws, made parts etc I'd spend a more than this and get a worse result.   This kit is the stage, leadscrews and steppers.  No electronics/drivers are included.  It is fairly small but it looks like a great leg up.

Here is what I'm planning to use

Zen Toolworks CNC Carving Machine DIY Kit 7x7. 

My initial plan is to use Arduinos as the motor controllers.  I like the older Arduino, because it is a tad cheaper, and really functionally equivalent to the Uno.  Amazon for the free shipping and no tax.

Arduino Duemilanove

Most CNC software uses a computer parallel port to synchronize output bits to control the motor, and perhaps the Arduino isn't really the best solution.  However parallel ports are old and obsolete, so I'm going to make my own controller anyway.  Irrational decision probably, but buying an old parallel port board makes me nauseous.    If i can control all the motors from one Arduino, I can keep the synchronization with no work.
Motor driver controllers are way expensive and even with a coulple Arduinos and motor control boards, I'm probably coming out ahead.

Bought two motor control boards from adafruit.  A prebuilt board that saves a lot of time, from an A+ vendor.

Adafruit Motor/Stepper/Servo Shield for Arduino kit - v1.0

I want to be able to know the position of the machine at all times.  This isn't really needed for stepper motor controlled machines, don't need feedback.   However for manual stepping and testing, I wanted a readout.
Will try to read back position via cheap rotary encoders,
I may just use the encoders for calibration, or monitoring.  A feedback loop solution may be overkill.  It depends on the torque and backlash of the motors.  TBD.

The arduinos will commnicate via USB to the host PC.
The software is a journey, but there is tons of stuff on the web, so we will see!


The stepper is rated for 1.68A at 2.8V.  I'm going to have to run it at 5V, because the driver chips need at least 4.5V, and I'm using a repurposed ATX computer power supply to give me 5V.
The stepper that comes with the Zen is this one:
I understand that it can take the higher voltage, but the current will go up.  Have to be careful to not step too fast since I don't have a current limiter.  Maybe I could put a 1.3 ohm resistor in series to limit the current to 1.68A.  It would have to be a 3.6W resistor.  They are available as wirewounds for >$1.  That would add inductance for sure.  I will wait and see how it works first.
Upgraded the L293D drivers with SN754410 in the adafruit stepper motor board, it wasn't driving the stepper very well.  They are pin for pin compatible.  I will solder two together to get 2A.  Three might be even safer.  Added a heat sink too.  Bought this at

Stacking the two driver chips turned out to be tricky, and after making a big solder short, and apparently ruining one driver chip, i found the method to do this.   Solder the two chips piggy back BEFORE you put them onto the pc board.  Put one in a vice, piggyback the second, then solder tack the end pins on both sides.  Then come back and one by one solder the pins together.   Then put the assembly into the PC board.

To use a computer power supply, you have to trick it to turn on like this guy shows:
After that, just use any of the red and black wires.  Says it will source 32A.  wow.

Set it up, used a scrounged PC power connector to plug it in, shorted the two pins as described and 5.1V, cool and quiet.  Plugged it into the stepper motor board and the Zen toolworks steppers, and it is working great.  The chips do get a bit hot, so i'm thankful for the heat sink and I'm suing the power supply fan to blow across the driver boards.

In this photo you can see the power supply, the Arduino with the motor control board on top, the double stacked driver chips and heat sinks, connected to the stepper motors.

Then i moved on and modified the Adafruit motor shield so that I could stack two shields on top of each other and control 4 motors at once (only have three right now).  Made a stand alone post for what I did here, it was so cool.   Basically a small hack to give each board it's own latch pin.  Only took one more pin to differentiate which board responds to the commands to the motors, and the other motors still hold their value.  Awesome!
Arduino with two Adafruit motor shields on top, connected to the PC 5V power supply and three motors (3rd is out of the picture)


Now I need to build an Arduino module with the rotary encoders and an LCD display to show the position. I will also have at least one button to set the home position.
Back to the rotary encoders from sparkfun. Some sample code is here:
The sample code worked out of the box, now to modify it to read three encoders.
It makes use of port manipulation to read all the input simultaneously.  This page helped
Got the three encoder code working, I made a separate post for it so I could include it in the blog, look for it.
I rewrote the code so it made sense to me, the example took a lot of head scratching.

Attached the three encoders to the machine temporarily, and it is working great.  Stepped over and back and it returns to the same position.  No worries about he rotary encoders missing steps.

found some small limit switches for <$2 a piece.  The plan is to use them to interrupt the jumper wire on the PC power supply, thereby killing power if the stage is going to hit the walls.   I was advised by a friend that it can be a pain to unstick yourself if you have killed the motor power, but I will turn the stage back by hand if this happens.


Now I have moved on to coding.   Plan is to write or borrow a simple Gcode interpreter than can run on the Arduino.   I found this page, making a note:

I hope to be able to use some open source software for the graphics.  Looks like the defacto is EMC2.  EMC2 is open source CNC software at,en/.  I will have to use Linux ubuntu for this, but since it probably would be best to use a dedicated PC, Linux is a good choice because I can use an old PC knocking about.  Had hoped to use windows to be able to make visual basic widgets.  I'll come back to that later.   I may need to write some layer of code between the serial ports and the EMC2, since it wants to drive a parallel port and do all the thinking.  "G-code" is the format for the commands that EMC2 produces.

Found this link, he beat me to it!  Arduino controlling and translating Gcode.

I decided to start some new posts for the coding, so look there for updates


  1. We have wide range of CNC Turning Centers and deal with all types of CNC turning machines. It's allows you to offer rapid, accuracy tooling and also fast turnaround on production.

  2. Great post. I was checking continuously this blog and I am impressed! Extremely helpful info specially the last part :) I care for such info much. I was looking for this particular information for a long time. Thank you and best of luck.
    Router Mill

  3. Very helpful!!!, Is it possible to read five encoders at the same time using the Arduino uno?, Thank You!!!.