How to Build a 4-axis CNC Gcode Interpreter for Arduino

4-axis CNC motors

I’ve updated the GCode CNC Demo on Github with an example of how to run 4 stepper motors. It could be extended to 6, 8, or more.

Using the new Adafruit Motor Shield v2 and an Arduino UNO I’m showing how to control 4 stepper motors at once with GCode, the standard language for CNC machines like 3D printers, mills, and lathes. If you are designing your own machine this is the simplest way to get started. The code has four different examples that build on each other to grow your understanding. In theory this system could be expanded up to 32 stepper motors.

Tags: , , , , , , ,

18 Responses to “How to Build a 4-axis CNC Gcode Interpreter for Arduino”

  1. diyman says:

    Hi, I am a newbie in cnc and arduino. I was looking at your project as I am very much interested in building a cnc machine. But before I bought the Adafruit motor shield, I wanted to do a little but of research. I looked through your code and one thing that I don’t understand how does the gcode get passed on to the serial port. Do I have to copy and paste each line into the serial monitor or copy and paste a bunch of lines to the serial monitor? How your code get the gcode is where I am stuck at. Any help would be much appreciated.

    Awesome work by the way..

    Thanks
    diyman

    • Dan says:

      Yes, pasting lines is the way. I am working on a program to delivery many lines one at a time. It will be released when it is ready.

  2. Jbc says:

    I love what you have started.
    I’ve been using the AFMS’s on another project and love them plus Adafruit’s forum techs are a great help.

    Any updates?
    I am interested in a 4 axis concept router using the Adafruit motor shields +Uno.
    Thanks you.
    Jbc

  3. Russ says:

    Dan, what model of motors are you using in the demo? I am planning on building a CNC Router very soon and am putting together a parts list. I love the idea of the Adafruit Motor/Stepper/Servo Shield for Arduino v2, but am unsure that it can handle the level of power I (think I) need. Still deciphering…

    • Dan says:

      I’m using LDO 0.3a 400-step-per-turn stepper motors.

      There are so many factors in building a good machine. I’ve heard that new people build three: their first machine, the one they do better, and the one they actually use – in that order. Based on my experience, this sounds about right. If this is for learning about building machines then do it any way you like and I salute you, sir. If you intend to use it in the long run or your budget is limited then I strongly recommend you get a kit and build that, instead. You’ll still learn a lot and you’ll avoid a lot of mistakes you just couldn’t know about.

      • Russ says:

        Dan, thanks for replying so quickly!

        Your three steps sound about right to me. I think that I am just (barely) aware enough of my own limitations that I do recognize that it will be a learning process whether I want it or not. ;)

        I have seriously considered kits. Unfortunately for me, I have some specific requirements that are not met by most of the Atmega/Arduino based kits. therefore, my goal will be to get the first build done and hope that my tolerances are good enough to build its replacement.

        Also, I would like to re-use as many parts as possible. I’m going with its bigger brother, so I’ll go with Sparkfun’s Big Easy – used in the Shapeoko.

  4. Paul Isabelle says:

    Dear Dan,
    Thanks for this great webpage posting!
    This is fantastic, a great jump start for my projet. I was looking for a template project to help me on my first Arduino project, a 4 axis hot wire foam cutter. Basically there will be 2 axis on both ends of the wire, for cutting foam airfoil sections, constant or with linear and synchronized transitions from one profile to another.
    As for generating the code to run it, no problem there, just formatting G-Code properly and it should work. Then there is all the hardware stuff; rails, leadscrews,…hours of fun!
    Thank you for increasing the robot litteracy of the collectivity.
    Cheers,
    Paul.

  5. Hey Dan,
    Great stuff.
    I was wondering if there is a way to handle larger files through possibly a sd card shield or something like that.
    Thanks

    • Dan says:

      Absolutely! We’ll be releasing some code soon for the RUMBA controller that handles 6 axies, reads SD cards, and controls an LCD screen all at once. A lot of it has been inspired by the Marlin firmware for 3D printers.

  6. jarango3d says:

    Hi, I am a newbie in cnc and arduino.I look for the g-code interpreter for arduino with 3 axes. I want to make a filament winding machine, for polar winding,(similar to a cnc lathe), but has variable velocity in the rotational axe.
    this software could work for this aplication?

    • Dan says:

      Do you mean coil winding, like making magnets or collecting filament from an extruder? Yes, I think it could work. How about if you use many short turn commands, each with a slightly different feed rate?

      If you are winding wire then you only need two motors. If you are winding ABS or PLA coming from an extruder then things get… more complicated.

      • jarango3d says:

        The machine is for filament winding.(this machine winding filament of glass fiber, carbon fiber,etc)the best machine for polar winding have 4 axes, but i think that with 3 axes could work fine.

  7. jarango3d says:

    Hey dan:
    Please see this video:
    http://youtu.be/Blry5gOd7ps
    here is the 3 axes machine.

Leave a Reply