Skip to content
Dan Royer edited this page Aug 17, 2016 · 1 revision

Table of Contents

About

A CNC machine is a computer controlled machine tool. Common examples include 3D printers, lathes, routers, and plotters. A common computer that people use for DIY CNC machines is the Arduino. GcodeCNCDemo is a collection of Arduino sketches. Each sketch can teach an Arduino to speak Gcode, the language of CNC machines. Then you can talk to your CNC with gcode and tell it what you want instead of reprogramming it over and over.

Here are examples that use Marginally Clever code.

Download

To get the code please visit the Github repository

Which files should I use?

  • GcodeCNCDemo2AxisV1 uses an UNO R3 and the L293D Motor Shield.
  • GcodeCNCDemo*AxisV2 uses an UNO R3 and the Adafruit Motor Shield v2.
  • GcodeCNCDemo6AxisRumba* uses an RUMBA board. A RUMBA board is compatible with an Arduino MEGA2560 board.

GcodeCNCDemo6AxisRumbaTimerInterrupt

GcodeCNCDemo6AxisRumbaTimerInterrupt abuses the timer interrupt on the RUMBA to eliminate the brief pause between commands. It can also "look ahead" and plan more efficient movement. It does this by storing a few commands ahead in memory and then comparing them. For example, if you have line commands A>B and B>C, every other gcodeCNCDmo would pause at B. GcodeCNCDemo6AxisRumbaTimerInterrupt will go A>C without slowing down if it can.

V2

You can use any of of the *V2 with an Adafruit Motor Shield v2. With all V2 code you will have to change the address of the board. Look for

  Adafruit_MotorShield AFMS0 = Adafruit_MotorShield(0x61);

and change the 0x61 to the address of your shield.

Installation

  • Get Arduino software if you don't have it already.
  • Get the Adafruit motor shield library and install it in Arduino.
  • Use the Arduino software to open the ino file that interests you. If you want to use GcodeCNCDemo2AxisV1 then open GcodeCNCDemo2AxisV1/GcodeCNCDemo2AxisV1.ino'.
  • Choose Tools > Serial port and note the list of ports.
  • Choose Tools > Board type and set either UNO R3 or MEGA 2560 (depending on which sketch you use).
  • Plug your Arduino into the computer with a USB cable.
  • Choose Tools > Serial port and select the new port where your board is connected.
  • Press the upload button.

Test

  • In Arduino, open the Serial monitor
  • at the bottom of the window select "57600" and "newline" from the two dropdowns. English text starting with "HELLO WORLD!" should appear in the monitor.
  • type
  G00 X1 Y2

in the serial window and hit enter. Your machine should move a short distance on the X axis and slightly further on the Y axis.

You can now send any gcode commands that the arduino understands.

Sending whole files

So you've used a demo to make a CNC machine, and now you want to deliver a whole file full of gcode.

See our sister project, the GcodeSender.

See Also

If you get any errors try our forums for help.