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:
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:
Which yields something like: /dev/tty.usbmodemfd121
Then, in the folder with the hex file downloaded from the Grbl GitHub repository, run:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -pm328p -cstk500v1 -P/dev/tty.usbmodemfd121 -b115200 -D -F -Uflash:w:grbl_v0_8c_atmega328p_16mhz_9600.hex
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. Z0.1 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!