How to wire an arduino-based 3-axis CNC machine Home Sign Up!

Home Sign Up! Browse Community Submit
All
Art
Craft
Food
Games
Green
Home
Kids
Life
Music
Offbeat
Outdoors
Pets
Photo
Ride
Science
Tech
How to wire an arduino-based 3-axis CNC machine
by aggrav8d on June 15, 2010
Table of Contents
License: Attribution Non-commercial Share Alike (by-nc-sa) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Intro: How to wire an arduino-based 3-axis CNC machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
step 1: parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
step 2: Wire the stepper motor to the EasyDriver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
step 3: Soldering and wiring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
step 4: Sample arduino code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
step 5: In conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
License: Attribution Non-commercial Share Alike (by-nc-sa)
Intro: How to wire an arduino-based 3-axis CNC machine
I've seen a number of tutorials about how to build the platform for a 3-axis CNC milling machine. I have not seen anyone tackle the tricky subject of the electronics.
Here now is my attempt to do so.
step 1: parts
You'll need:
- an arduino (I chose duemilanova) (depends on the board you get)
- 3 stepper motors (I chose NEMA 17s, though mine didn't come with molex on the end) ($15/ea)
- 3 EasyDrivers from Sparkfun. ($15/ea)
- some Cat5 ($2?)
- a 5V power supply for the steppers ($5?)
- a soldering iron
- some electrical tape
- an optional female plug is not would be a bad idea (<$1)
TIP: Don't get a 6ft or 10ft Cat5 cable. Those wires are made of hundreds of little fibers and they're a huge pain to work with. Buy your cat5 by the foot from any
computer or electronics store. That stuff has one wire inside
step 2: Wire the stepper motor to the EasyDriver
Now we'll wire up each of the EasyDrivers.
Remove some of the interior wire from the Cat5 and strip the ends. For each servo you will need two normal pairs of white/colored and one oddball of a white and two
colored. In all, you'll have to strip 14 ends.
PCB soldering is easy, once you get used to it. There are many other tutorials that cover the subjct. Follow the image as indicated. Your color combinations for the
servo may be different. I had to google for a long time to find this page with the color codes for my model.
TIP: "Do NOT connect or disconnect a motor while the driver is energized. This will cause permanent damage." -- Sparkfun
Next we'll wire the power sources and the arduino.
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
Image Notes
1. NEMA-17 order is red, green, blue, yellow. I was not easy to google that info!
2. These power the servos. That's separate from the power for the board logic.
3. These connect to the arduino. The arduino tells the board which way to go and how far.
4. These power the board logic. That's separate from the servo power.
step 3: Soldering and wiring.
I've done this all in one step, but feel free to wire each EasyDriver one at a time, check that it works, and then unplug it from the power and do the next one.
All 9 GND wires from the EasyDrivers are soldered to a single line, which goes to GND on the arduino.
All 3 +5V from the EasyDrivers are soldered to a single line, which goes to +5V on the arduino.
All the positive leads from the stepper power are soldered to a single line, which is then soldered to the female plug.
All the negative leads from the stepper power are soldered to a single line, which is then soldered to the female plug.
TIP: Remember to put the plug cover on the wire BEFORE you solder everything together. Then slide the cover down and over the soldering.
TIP: Don't forget to have everything disconnected while you solder!
Double check you didn't wire the board power to the stepper power. That would be bad.
Now the wiring is done, time to test it with some code.
Image Notes
1. This stepper is controlled on pins 4 and 5.
2. This stepper is controlled on pins 6 and 7.
3. This stepper is controlled on pins 8 and 9.
4. All the positive leads from the stepper power are soldered to a single line, which is then soldered to the female plug. Repeat for all negative leads from the stepper
power.
5. Remember to put the cover on the wire BEFORE you solder everything together. Then slide the cover down and over the soldering.
6. All 6 GND wires from the EasyDrivers are soldered to a single line, which goes to GND on the arduino. The three from the stepper power go to the plug.
7. Arduino Duemilanova Atmega328 with an ethernet shield on top. You don't need an ethernet shield. I'm just telling you so you don't wonder why the picture looks
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
different from your Duemilanova.
8. 9DOF IMU. Not part of this CNC project. Inb4 "what's that?!"
step 4: Sample arduino code
// for duemilanove atmega328 arduino board + easydriver stepper controller
// [email protected] 2010-06-15
#define SENSOR_X_PIN 1
#define SENSOR_Y_PIN 2
#define SENSOR_Z_PIN 3
#define DIR1_PIN 4
#define STEP1_PIN 5
#define DIR2_PIN 6
#define STEP2_PIN 7
#define DIR3_PIN 8
#define STEP3_PIN 9
#define DELAY 150
void setup() {
Serial.begin(9600);
pinMode(SENSOR_X_PIN,INPUT);
pinMode(SENSOR_Y_PIN,INPUT);
pinMode(SENSOR_Z_PIN,INPUT);
pinMode(DIR1_PIN,OUTPUT);
pinMode(STEP1_PIN,OUTPUT);
pinMode(DIR2_PIN,OUTPUT);
pinMode(STEP2_PIN,OUTPUT);
pinMode(DIR3_PIN,OUTPUT);
pinMode(STEP3_PIN,OUTPUT);
}
void loop() {
int i;
digitalWrite(DIR1_PIN, LOW); // Set the direction.
digitalWrite(DIR2_PIN, LOW); // Set the direction.
digitalWrite(DIR3_PIN, LOW); // Set the direction.
delay(DELAY);
Serial.println(">>");
for (i = 0; i<6800; i++) // Iterate for 4000 microsteps.
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
if((i%2)==0) {
digitalWrite(STEP2_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP2_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
if((i%4)==0) {
digitalWrite(STEP3_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP3_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
delayMicroseconds(DELAY); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(DIR1_PIN, HIGH); // Change direction.
digitalWrite(DIR2_PIN, HIGH); // Change direction.
digitalWrite(DIR3_PIN, HIGH); // Change direction.
delay(DELAY);
Serial.println("<<");
for (i = 0; i<6800; i++) // Iterate for 4000 microsteps
{
digitalWrite(STEP1_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP1_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
if((i%2)==0) {
digitalWrite(STEP2_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP2_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
if((i%4)==0) {
digitalWrite(STEP3_PIN, LOW); // This LOW to HIGH change is what creates the
digitalWrite(STEP3_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step.
}
delayMicroseconds(DELAY); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
step 5: In conclusion
If everything worked right, you should have three steppers each moving at different speeds back and forth. There should be a light on each EasyDriver showing that it
has power. If you have a light and no movement, You might not have a good connection to your arduino.
So what next?
Now that you have three motors working through the arduino you can use the serial interface to tell the arduino what you want the steppers to do. By changing the
different motors in the right pattern you can interpret G-CODE and start cutting patterns. The biggest choice you face is what to cut!
Thanks for reading!
Dan
Image Notes
1. Congratulations! You earned it.
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
Related Instructables
DIY CNC (guide)
by Instructables
Guides
CNC (guide) by
Instructables
Guides
Build a CNC
Router from
Scratch (Part 2):
Complete Video
Tutorial by
phooddaniel
Easy to Build
Desk Top 3 Axis
CNC Milling
Machine by Tom
McWire
Mostly selfreproducing 3axis CNC
milling
machine(SHELVED
PROJECT) by
ebidk
Make your own
cnc controller
by charcoal999
How to make a
mini milling
machinemanual or CNC!
by Honus
Easy to build
CNC Mill
Stepper Motor
and Driver
circuits by Tom
McWire
Advertisements
Comments
13 comments Add Comment
tatagatha says:
Jun 17, 2010. 9:43 AM REPLY
I've got a pet project of yet another plotter...inspired by Motöri The Plotter... dubbed "Inky". I looked at the arduino G-Code interpretter from the first versions
of the reprap project. I decided against doing the conversion inside the arduino and instead to have a computer handle the real conversion work. The 3g
version of the rep rap software sends commands (usually via replicator-g) that get stacked up in the arduino. These commands are interpretted versions of
the g-code(things like, move x 10 steps). What is nice about this, is that you can theoretically interpret other things like HPGL. I'm currently working on a
driver for replicator-g and a stripped version of the RepRap 3g firmware that will allow you to use the adafruit motorshield. While I'm only implementing this
for a plotter, and so I only need 2 steppers (which is all the motorshield can provide) you could do a similar things and forgo the motorshield in favor of
interacting with the easydriver. Just some food for thought.
aggrav8d says:
Jun 17, 2010. 10:06 AM REPLY
How do you make a plotter with only two steppers? Don't you need to lift the pen?
tatagatha says:
Jun 17, 2010. 11:07 AM REPLY
Yeah, the motorshield still can control a servo while controlling the two steppers. the pen only needs up or down, so I don't have to worry about the
distance. If I was getting fancy, and I eventually would like to get fancy, I'd have some height aspect to the pen, so I could control thickness when
using a marker or brush. For now though, up and down is enough.
aggrav8d says:
Jun 17, 2010. 12:22 PM REPLY
Unless you're slamming the stepper from full off to full on, there's no reason you can't have fine grain control.
Alternately, you could add a set of pens with different nib sizes and build an automatic tool changer. Maybe a second servo to hold the pen in a
clamp grip, and some code to know how to go to the tool holder, drop off the old pen, pick up the new pen, and keep going.
Bonus: if you get this working then you'll get multicolor drawing, free.
tatagatha says:
Jun 17, 2010. 1:27 PM REPLY
Do you mean slamming the servo? I could have some fine grain control on the servo, but a little less precise. However, for iteration 1. I'm
aiming for draw and not draw. I'm trying to string together as much existing projects as I can, so it can be a starter project for someone else. It
is as much an exercise of learning the stack below as it is to make a plotter: G-Code interpreter : replicator-g Handling commands : rep-rap 3g
firmware to interact, using their protocol Controlling the steppers : Adafruit's motorshield, which comes with a nice stepper library, but only
controls a 2 steppers at a time. Another goal is to make this with only two old epson printers. My general plan has a gantry for the x axis, but
only pulled on one side. I don't want to put to much weight on it so it can move the pen fast and not lag on the off side. I thought about doing
the suggestion in the motori write up, which is to do the etch-a-sketch set up to pull both sides with a single motor. However, one feature I
want is an open bottom, so this can write onto any surface directly. I've thought about the multi-pen approach, but I'll probably go lo-tech and
just draw one color at a time. I've got a registration system set up to use the rep-rap's edge detection code. This way, I can always zero my
printer and draw again. Its all just a bunch of steppers and rods in a box right now. And a semi working firmware for the rep rap. I still have to
make the actual build, and then the driver.
dwmcdougall says:
Jun 16, 2010. 6:59 AM REPLY
Most CNC machines use a computers parallel port for out put as opposed to serial. There have been some solutions out there that use USB, but they are
few and far between. I have two machines in my garage and am currently building a third dedicated only to PCB making. As for software to run your Gcode,
try Mach 3 (windows) or EMC2 (linux). Both are relativly easy to use and have a great user base, and lots of support can be foun for HW and SW over at
CNCzone.com. Great project BTW, my third (smallest) CNC is currently running the steppers with the older version of the Easydriver circuit and they work
pretty good. Nice writeup, hope to see more as your machine gets set up good luck!
aggrav8d says:
Jun 16, 2010. 11:28 AM REPLY
I'm not actually trying to build a CNC machine, as much as I want to. I wired all this up because I'm building a gyro stabilizer for a standard size
consumer-grade camera and I realized the same system could be used for a CNC. ...so why not post an Instructable about it?
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/
sammyBoy says:
Jun 16, 2010. 7:53 AM REPLY
Nice instructable.
GRBL is an almost complete implementation of the G-Code (only 3 axis) standards specifically written in C for the *duino atmega platforms.
maxpower49 says:
Jun 15, 2010. 6:30 PM REPLY
do you have to figure this out every time you want to cut something or is there a program that will do this for you
aggrav8d says:
Jun 15, 2010. 10:02 PM REPLY
There are a few open source programs now that will convert a DXF file to G-CODE. Unfortunately the standard for G-CODE is effectively junk. From
what I read, nobody sticks to it. What needs to happen is someone needs to write a standard interface between mill software and mill hardware - just like
drivers for any other peripheral on your computer. Hmm... Anyone want to pay me to do this? I could dedicate a few months to the problem and bang out
a pretty good solution.
cmchapman says:
Jun 16, 2010. 5:08 AM REPLY
I'd give you some money over on kickstarter.com if you really want to write an open standard interface for milling hardware and software. I'm sure
other people would too!
aggrav8d says:
Jun 15, 2010. 10:04 PM REPLY
Since no standard currently exists, you'll need to write your own translator between the g-code they offer and the limits of your system. You'll still
need software to drive the CNC, too.
}{itch says:
Jun 16, 2010. 5:10 AM REPLY
The folks at rep-rap have written an arduino based G-Code interpreter. You can just send the g-code commands via serial and the arduino will
calculate the required stepper motor movements. I haven't used it myself yet but have had a look at it for a CNC machine i have in the works.
Here's the link .
http://www.instructables.com/id/How-to-wire-an-arduino-based-3-axis-CNC-machine/