Tuesday, 19 February 2013

CNC Mill Build - eLectronics

The last post saw me putting the finishing touches to my machine build, by adding the belts. Unfortunately that's the easy part over, now I'm tackling electronics.

There are two stages to controlling a CNC machine. The first is a controller which will take a Gcode file* and turn it into step and direction pulses that tell each motor when to turn.
The second is a motor driver which takes these low voltage data signals and sends high power signals to actually drive the motor.

For the driver (the second part) I'm using pololu a4988 drivers along with a stepper shield. After finally sourcing all the parts this is what they look like.

The driver is quite small, you can see one of them in the top left. The rest is just capacitors, to even out power, and connectors, to attach all the motors.

This board is a 'sheild' which is intended to be used with an arduino. You can use an arduino as your controller, but I wanted to use a PC because it gives me more control and a  nice graphical interface.

Which means I had to build a separate board to make it so the signals to and from this shield could be sent via a parallel cable.

This is what I put together. Again not much going on here, the parallel cable is broken out and the signals sent to the right sockets (so they match up when the shield is plugged in on top).
There is also a 5v regulator to supply the logic voltage and all the connections are optically isolated. This means that the CNC motors and the computer aren't physically connected, this means any noise caused by the motors won't affect the computer.

Bart Dring, of Buildlog.net designed this board which does exactly what I want. But he doesn't sell them anymore. So what I did was buy the arduino version (also designed by Bart, but now made by Reactive Substance) and adding in the missing components so that it was functionally the same. It probably would have been easier to just build the whole thing myself from Bart's schematic. But the black boards help with heat dissipation  as well as matching the drivers I bought, and looking badass.
Edit: of course now that the M6 is finished, I could design a new PCB with everything on and mill it on my machine, how ever I'm unlikely to ever get round to this.

Now the shield carrying the stepper drivers, just plugs in on top. Each one of those drivers (now with large blue heat sinks on) controls one of the motors, each motor has 4 wires.

The large silver box off to the left is the 24V power supply, this is the power that is used to drive the motors, the 5V logic is supplied by a small regulator I put on the lower board.

That's most of the hardware set up, the other end is an old PC running Ubuntu, I'm using LinuxCNC to control my machine, it's a very powerful tool (probably overkill for this little thing) but nice all the same.

What came next was lots or testing tinkering and , to be honest, swearing as I tried to figure out why it wouldn't work.

(figured it out eventually WooHoo!)

*Gcode is the end result of designing on a computer, it's composed of simple lines of text that instruct the machine where to go using an absolute positioning system. E.g. g0 x10 y10 would tell the machine to move to that co-ordinate (g0 is just max speed) so kind of like playing Battleships.


  1. Awesome build and an enjoyable read!
    If you have dual x and y then there must be five steppers but I see only four driver boards on your shield? Do they supply enough current to drive two steppers?


  2. When I refer to the dual X I mean that I have two lengths of makerslide sandwiched together. This stiffens up the X axis, prevents it from twisting and supports the X carriage from two sides. The X carriage is still only powered by one motor.
    I should probably go back and make that clearer.

    However you can run two motors off of one driver, the current to each motor will be halved, but it's normally fine for milling soft materials. I know lots of people who have run two Y motors off of one driver.

  3. Tom,

    Would you provide the BOM and layout for your breakout board. I would like to build one and I have not had any success finding details online.

    1. My board was based around this design from Buildlog.net:
      The BoM is in this user guide:

      The guy used to sell these as kits, but hasn't for years.
      Unfortunately there is no layout so you have the decipher the schematic yourself. I wanted to avoid this so I purchased one of his similar boards (tweaked and sold by a third party) :

      This board is intended for use with Arduino, so while some of the circuit is the same, I had to use perfboard for the opto-isolators and resistors that connect the inputs to a 25pin parallel connector. I did this by refering to the above schematic, unfortunately I can't provide my exact layout because it was all figured out with sketches and trial and error.

      I don't recommend what I did and if I were to do it again I think I would take the time to set the whole design out on one board. The design is solid though just make sure to leave large traces for your high current motor outputs.

    2. Thanks for the response. I have been using my Shapeoko with the arduino and buildlog stepper shield, but am interested in moving to an EMC2 setup (without breaking the bank). I will take a shot at recreating what you did with your set up.

    3. Your post got me thinking and I've started designing a proper milled PCB for my electronics, at the same time I can add in functionality for limit switches and an emergency stop.
      If I ever get something finished I'll post it up here.
      Let me know how you get on too.