My experience with Arduino CNC shield was a bit frustrating at the start. This article is about version v3.0 CNC shield. I didn’t know anything about this shield, GRBL software and how G-code is sent to CNC machine.
So I was pretty unsure about everything I was doing. I tested GRBL software with only CNC shield + Arduino, motors, and drives. Good start would be to buy whole Arduino CNC kit where everything essential for small desktop CNC is included (electronics wise).
Original manual is pretty massive to start with and there seemed to be no 5-minute setup guide. But for the first-time test, I am not in the mood to read all that. I want to plugin everything and see things moving. And then make my progress through settings afterward. Be sure to read original Arduino CNC shield article also. Here I share my experience and problems occurred during the first tests.
- I am using Ubuntu Linux with KDE desktop, but I suppose this works universally.
- You even don’t need to have CNC shield to go through this article- minimum requirement is to have Arduino UNO development board (or possibly some other Arduino board).
Are you a beginner and don’t even know how to run stepper motors? You have to check out my detailed overview post on running stepper motor. If you have the machine ready- you should totally test out the online G-code tool I created to generate code for a simple customized hold-down clamp.
Getting GRBL code on Arduino
I downloaded latest (on time of writing this article it was v0.9i version) source from “github.com/grbl/grbl” by downloading using “Download ZIP” button on the top-right. So in future, it might download some newer version which maybe not be the same version I was using when writing this article.
How to download source code by zip file from Github.com
If you want to use the exact same code version that I used in this article, you can download it here. But I suggest using the latest, since it probably will work also. Then you have to add it as a library. After that, you can import GRBL library to your source. You can read more about compiling here.
After importing I was not able to upload/flash it on Arduino on the first try. A error raised: “./sketchbook/libraries/grbl/nuts_bolts.h:73:15: error: ‘uint32_t’ was not declared in this scope“. By adding #include <stdint.h> before other includes removed this problem. Now I think I had just an old Arduino version or something.
Note that, there is no need for additional code. Only importing and you are done. Just upload it to your Arduino UNO board. Before GRBL v0.9 there was no direct upload option (If I remember correctly). Anyway – my code looked like this:
Connecting to GRBL via Arduino serial monitor
Now everything should be ready to go. I opened serial monitor via Tools menu in Android IDE. Note that since GRBL version 0.9 you have to set the baud rate to 115200. Otherwise, you only see some garbled characters echoed to serial monitor window.
Everything seemed OK to this point. In terminal following welcome message popped up: Grbl 0.9i [‘$’ for help]. That means everything is OK and I was connected. But it can’t go so smooth isn’t? I stepped into next issue. I tried to send some commands, but nothing happened. Except – “?” command yielded results similar to this: <Idle,MPos:0.0000,0.0000,0.0000,WPos:0.0000,0.0000,0.0000,Buf:0,RX:0>
After wrestling with this problem sometime I finally learned why this was happening. One must set “No line ending” to “Carriage return” in Arduino Serial monitor (bottom – right). Actually, it’s said in GRBL Readme too, but somehow I had missed it. I was excited. Finally, I got something back. It was “$$” command which returns current settings used by GRBL software.
GRBL v0.9i serial monitor welcome message
First steps and sending g-code to GRBL?
I would test real movements without hooking motors up into your CNC machine at first. To get hang of this before ripping your nice machine apart. Now for testing, you could insert g-code command such as “G0 X2.0 Y2.0 Z2.0” into Serial monitor terminal – it should move all motors a bit. (Look video at the end) Even if you have no shield, drives or motors hooked up- terminal should report back with “ok”. You are done!
I had some unanswered questions also. Do I have to add limit switches before motors will move? What about the homing cycle? Turned out that I can just configure that there are no limit switches. Also, a homing cycle is not needed. Nothing at all. Everything runs smoothly without configuring beforehand. See config lines $20, $21 and $22. Zeroes mean that these features are turned off by default config.
I somehow had problems with default settings at first. Motors did not move. At first, only one step was done and no “ok” was echoed back. Settings were different than in this article. I think I messed up something earlier somehow. Anyway – probably acceleration or maximum rate of movement was with wrong settings- so command executed too slow and echo back no “ok”.
Default GRBL v0.9 settings with Arduino CNC shield version 3.0
Default settings Arduino had were following. I don’t know – are these same for all installations or not. Anyway, here is my printout of settings for reference.
$0=10 (step pulse, usec)
$1=25 (step idle delay, msec)
$2=0 (step port invert mask:00000000)
$3=0 (dir port invert mask:00000000)
$4=0 (step enable invert, bool)
$5=0 (limit pins invert, bool)
$6=0 (probe pin invert, bool)
$10=3 (status report mask:00000011)
$11=0.020 (junction deviation, mm)
$12=0.002 (arc tolerance, mm)
$13=0 (report inches, bool)
$20=0 (soft limits, bool)
$21=0 (hard limits, bool)
$22=0 (homing cycle, bool)
$23=0 (homing dir invert mask:00000000)
$24=25.000 (homing feed, mm/min)
$25=500.000 (homing seek, mm/min)
$26=250 (homing debounce, msec)
$27=1.000 (homing pull-off, mm)
$100=250.000 (x, step/mm)
$101=250.000 (y, step/mm)
$102=250.000 (z, step/mm)
$110=500.000 (x max rate, mm/min)
$111=500.000 (y max rate, mm/min)
$112=500.000 (z max rate, mm/min)
$120=10.000 (x accel, mm/sec^2)
$121=10.000 (y accel, mm/sec^2)
$122=10.000 (z accel, mm/sec^2)
$130=200.000 (x max travel, mm)
$131=200.000 (y max travel, mm)
$132=200.000 (z max travel, mm)
Video with default settings
Here is a quick video of all 3 axes moving with default settings and no micro stepping applied. Just running different axes forward and backward separately and in the end also back to zero simultaneously. Wantai 42BYGHW609 stepper motors were in use.