Go Down

Topic: EMC2.4/AXIS over USB w/Arduino and a call to the crowd. (Read 32121 times) previous topic - next topic


Feb 18, 2012, 04:05 am Last Edit: Mar 28, 2012, 09:15 pm by dewy721 Reason: 1
After looking at RepRap, rStepper, Grbl and others, I found that although they are all really cool projects for turning an Arduino into a G-Code parsing CNC controller made by some really clever people. 3-Axis only, or 3d-printing choices only just didn't fit what I was looking for...

An industry compliant solution that accepts custom codes, canned routines, offsets, tool compensation, encoder feedback for closed-loop control and a UI that lets me see what I'm about to make all on a platform that can grow with me AND my machine. All the way up to 9-axises! You know, THE WHOLE WORKS!

Well I'm glad to say I found one, and its free to boot! Called EMC/Linux, its been around for decades and its very well documented. Perfect! Just one problem, how to get this wonderful piece of software to talk to an Arduino that wants to become a CNC machine one day.

After looking around the web for weeks and pouring over documents, forums and posts that said "it can't be done" blah blah blah. I was becoming discouraged.

But, I discovered it could be done! And this is how:

EMC has an underlying interface called HAL, a virtual breadboard or sorts that can do tons of stuff including loading a python script. A python script can use serial communications and talk to one or more Arduino's simultaneously. Interesting...

That python script could then collect the X/Y/Z/Whatever coordinates from EMC's HAL interface and send the data over to the Arduino, the Arduino then moves the machine accordingly and tada! CNC magic happens!

So in a nutshell, here is a sketch, instructions, a python script and a HAL config to interface an Arduino to EMC in a useful way, and all the code is wrapped up inside the sketch for ease of use.

If anyone finds this useful, have any constructive suggestions or code contributions/improvements please let me know.

There's enough code to get a plotter up and running, but hopefully laid out well enough that one could interpret and expand it to their needs.

It currently supports:
 Stepper motors (microstepping as well)
 A plotter solenoid.
 ATX psu control for automatic power up/down
 LCD display (alpha)
 Closed-loop feedback (Arduino controlled.)
 Machine power status LEDs
 Power control button that will tell EMC to turn the power on/off.

So check it out at: https://github.com/dewy721/EMC-2-Arduino

If you do add to it, PLEASE let me know. It would be interesting to see what others make from it, or a link to it so others can benefit too.

Hack it, mod it, improve it, tag it, post it. This is now a crowd-source project, and its now public domain. Enjoy!


That is cool you started this I am working on emc2 and arduino. It will power a 4x8 router and plasma table (to start with).


I just realized that all your files are ino's don't quite know what to do with them yet. any help would be a great. really exited about this project, I will be trying to get stepper motors to work.


Mar 23, 2012, 02:27 am Last Edit: Mar 23, 2012, 08:06 am by dewy721 Reason: 1
The .ino files you can open with the Arduino software. I'm currently making a stepper version for 4-axies. (3+optional rotary chuck/print head.)

Here's the alpha version if you'd like. This one loses the servo/encoder support in favor of steppers instead. (I added an optional fourth axis to boot!)

I've moved the project over to GitHub at https://github.com/dewy721/EMC-2-Arduino were I can facilitate its development better.


What is the difference between:   EmcArduino_02b   and    EmcArduino_04a?

Also,  when you edit the my-mill.hal file do you comment out all lines containing "parport"  or just the ones that start with "net" ?

GREAT IDEA!    This is going to be fantastic,   please keep it up.


Mar 24, 2012, 10:49 pm Last Edit: Mar 24, 2012, 11:10 pm by dewy721 Reason: 1
Sorry about that I should have been more clear about it in the description.

In the HAL file you comment out the lines starting with "net" that refer to parport. This is normally the case, UNLESS you want to take input from the parallel port as well. But that would make for a debugging nightmare should something go wrong. (Limit/home switches for example.)

#net home-x <= parport.0.pin-10-in
#net home-y <= parport.0.pin-11-in
#net home-z <= parport.0.pin-12-in
#net home-a <= parport.0.pin-13-in

0.2b is the initial public release that has support for making 2.1-axis servo/encoder driven plotters. It just uses 2 moving axies (X,Y) and one solenoid (Z) to deploy a pen/pencil/marker with.

0.4a however has temporarily dropped servo support in favor of stepper control. This version controls four stepper motors simultaneously and was developed using an Arduino Mega2560 and a quadStepper controller from sparkfun. This makes a setting up a 3 or 4 axis CNC a lot easier.

When I get a chance It re-include servo/encoder support and mix-n-match so junk bot CNC building will be just another weekend mashup. :) I'm still looking for user input, coding help, and general feedback. So if you use it and need some doodad or feature I'll try to add that into a future release. Wanna help with the code? Just let me know.


Mar 28, 2012, 09:08 pm Last Edit: Mar 29, 2012, 01:22 am by dewy721 Reason: 1
EmcArduino_05b has been released.

Completely rewritten code, optimized, documented and cleaned up.
3 times faster than previous versions.
Full support for virtual and/or physical limit and homing switches.

Now supports full 9-axis (non-blocking) stepper motion control, expanded HAL file.

Included example ini file to get your CNC machine up and going fast.

Coders wanted.



Apr 01, 2012, 10:51 am Last Edit: Apr 01, 2012, 10:56 am by dewy721 Reason: 1
Hot off the presses, EmcArduino 06b CNC control has just been released.

Added support for the following:
 Program step

Accepting feature requests, if you got one and its related just let me know.  :)

By the way, it also accepts basic serial commands which makes it an excellent robotics controller!

With 9 non-blocking stepper channels. That's enough to control an entire RC robot with an 7-joint arm to boot! Just feed it serial commands and go.



Emc2Arduino has been released! (As well as a new Homepage)

Added support for:

  • Spindle control, On/Off, Direction, RPM control.

  • Coolant options, flood and mist.

  • Power Supply control.

  • Power and E-Stop indicator output for LEDs and such.

Were accepting feature requests on our poll.
Cast your vote and be heard by the development team.

Come and check us out at http://emc2arduino.wordpress.com/



is there a noticeable speed improvement over outputting step and dir signals through the parallel port ?



Parallel ports are generally faster (provided you're using a suitably fast PC).

Emc2Arduino is really meant for those that:
 1. Have no parallel port available. (Newer PC's or Virtual Machines for example.)
 2. Have an existing CNC that needs expansion.
 3. Want to toy around with CNC's (or even robotics) but without buying dedicated hardware.

PS. Sorry for the delay in response. (PC Upgrade complete.)



Hi dewy,
first of all: thx for ur software (and sorry for my bad english ;))
i tried to get your programm running, but i couldnt. I tried to configure everything you said, but the machine made almost nothing. x axis was a little bit moving (not really nice) but y and z werent.
my configuration is :
Mega 2560 with Ramps 1.4 Shield and Pololu drivers
mechanical endstops (NC)
the mechanic works perfect

Hopefully you can help me



Usually this is a situation where the stepper driver is moving too fast. Try raising the value for the following line:

#define minStepTime 1

Using a value of 100 should work.

Higher values are slower but more compatible, lower values perform faster.
Ideally, it should be set high enough to give your machine strong motor torque, but low enough to move as quickly as you need to.

Using stepper motors is game a balance between speed vs strength.


thanks a lot.
i ll try it out as soon as possible


hi dewy,

First of all : Respect for what you have accomplished so far!!! really cool project.
i'v stumblues upon today so i dont really get all the components but i guess the basic is clear.
iv been working on my CNC since last summer after buying an arduino i thought that should be possible, but i did not know anything about anything! So after a lot of reading about basic electronics and steppers and (.. you know what i mean) i finally got the mechanics together and now its time to implement the controlling part. i will be using an arduino UNO for now  but probally it will be a MEGA or DUE to have enough pins and 3 A4988 shields from Pololu. ( theese basterts took me a long time to figure out that they need to be cooled, but they work fine now)
At first i wanted to parse a dxf and calculate it into the correspondning XYZ coordinates and use an adapted version of the stepper library.
the problem is i would have to implement everything myself. Lines at any angle is eays but wehn it goes to cicles and splines i will have to spend a lot of time to get an accepting code.
i took a look at LinuxEMC some time ago, but the problem was i had no idea how to get the connection to the arduino

So here you are with your project!! Awsome :-) !!!  i will try it out as soon as i can and will tell you how it works for me!!

thanks allready

keep on coding


Go Up