Arduino milling machine, part I

21st January, 2014

As projects go, this one is quite ambitious. I've been thinking of building a CNC milling machine for some time now... Today, I decided to dive in and get cracking.

My recent Arduino Uno purchase should provide the perfect place to start for prototyping a computer numerical control (CNC) system to help make precision parts in metal, plastic, wood, etc.

After some preliminary research, my initial plan for CNC glory is:

  1. Design a part in Google Sketchup or similar
  2. Convert to G-code
  3. Stream G-code to Arduino
  4. Parse G-code with Grbl
  5. Interface with a 3-axis stepper motor driver
  6. Use stepper motors to control milling machine

I'll walk you through the steps I took to get to step 4 in about a half hour of tinkering... This is primarily to help myself record how I did things as this project may take a while to fully complete.

Normally, you write a sketch and upload it to your Arduino via their IDE. However, in the case of Grbl, you have to flash the micro-controller manually via the command line. Luckily, the Adruino IDE comes with avrdude which enables you to do so.

Firstly find the location of avrdude, which in my case was:


And the avrdude configuration file:


With the Arduino connected, find the serial port number as follows:

ls /dev/tty.*

Which yields something like: /dev/tty.usbmodemfd121

Then, in the folder with the hex file downloaded from the Grbl GitHub repository, run:

/Applications/ -C/Applications/ -pm328p -cstk500v1 -P/dev/tty.usbmodemfd121 -b115200 -D -F -Uflash:w:grbl_v0_8c_atmega328p_16mhz_9600.hex


  • m328p = ATMEGA328P chip found on the Uno
  • 115200 = Baud rate for the Uno
  • grbl_v0_8c_atmega328p_16mhz_9600.hex = the latest hex file from Grbl

Using the Arduino IDE serial monitor, I tested the connection to the Grbl controller which was successful. The next step was to test the setup with some actual G-code. I found Will Winder's Universal G-code Sender program which I'll use to stream data to the Arduino. Before running the program on a Mac, it's advised to create a /var/lock directory and make it writable:

sudo mkdir /var/lock
sudo chmod 777 /var/lock

The Grbl wiki has some example G-code (below) which I borrowed to test the streaming. I created a file with the following commands and sent it to my Arduino to route the path of a circle.

G17 G20 G90 G94 G54
G0 Z0.25
X-0.5 Y0.
G01 Z0. F5.
G02 X0. Y0.5 I0.5 J0. F2.5
X0.5 Y0. I0. J-0.5
X0. Y-0.5 I-0.5 J0.
X-0.5 Y0. I0. J0.5
G01 Z0.1 F5.
G00 X0. Y0. Z0.25

Here's the visualised result, seems to be a success! The program runs and returns a success message after about 1 minute. Next job is to invest in a few stepper motors, a decent driver, and a milling machine!

Universal G-code sender