Pocket laser engraver.

FeaturedContest WinnerContest Winner

Step 6: Prepare the Arduino.

Picture of Prepare the Arduino.
For the Arduino I started out writing my own software. But while searching for a good way to control movement from the serial port I stumbled upon something called "Grbl ". This is a g-code interpreter with lots of nifty functions. As I already had everything connected to the Arduino I had to ether change my connections or change the software. Luckily it is easy to change control pins in the software. I did however have to download Winavr and then the code from . It is not that hard to do. After downloading and extracting the code you have to change the port numbers in config.h and make sure you get them in the right order. Then all you have to do is start a command window, enter the correct folder and type "make". If all goes to plan you should end up with a .hex file ready for the Arduino.

I have however changed the pin-out since then and here in the instructable I use the default pin-out of Grbl. This will make it a lot simpler to follow and setup. You can just download the prepared hex file from the Grbl download page .

The current version of Grbl (0.6b) has a bug in the queue system. The laser on and off (M3, M5) commands are not put in the queue and the laser will be turned on and off as soon as the Arduino receives the commands. This is resolved in the edge branch. You can download and the source from here , or grab the compiled hex I am using from here . This should resolve the issue until the next version of Grbl.

Any way you choose to do it you will end up with a .hex file that you must get into the Arduino. I have tried a couple of different ways and the one I like the most is by a program called XLoader . The programming is pretty straight forward; select the correct serial port for your Arduino. Select the hex file and type of Arduino and press upload. If you are using the new Arduino Uno the XLoader doesn’t work, you will get an upload error. In that case I recommend using ARP/Arduino Uploader but even this uploader has some issues with the Uno. When programming the Arduino select the com port and microcontroller in the respective dropdown. After that you will have to make a change in the “AVR Dude Params” text. Erase the “-b19200” (without the quotes) part and click on the upload button. In any case, a couple of seconds later you are done and are ready to try it out. Exit the XLoader and get to the next paragraph.

The Arduino needs to be set up for the job. Start your favorite serial terminal and open the port your Arduino is connected to. You should get a welcome message:

Grbl 0.6b
'$' to dump current settings"

If you enter $ followed by return you will get a list of options. Something like this:

$0 = 400.0 (steps/mm x)
$1 = 400.0 (steps/mm y)
$2 = 400.0 (steps/mm z)
$3 = 30 (microseconds step pulse)
$4 = 480.0 (mm/sec default feed rate)
$5 = 480.0 (mm/sec default seek rate)
$6 = 0.100 (mm/arc segment)
$7 = 0 (step port invert mask. binary = 0)
$8 = 25 (acceleration in mm/sec^2)
$9 = 300 (max instant cornering speed change in delta mm/min)
'$x=value' to set parameter or just '$' to dump current settings

You must change the steps/mm for X and Y axis to 53.333 on both. Just enter "$0=53.33" followed by return and then "$1=53.333" followed by return. Z axis can be ignored as it is not used. The acceleration can be ramped up to something like 100 ("$8=100" and return). As we move really slowly with this machine acceleration can be high. Another side effect of low acceleration can be that curves get a lot more burnt than straight lines as the controller constantly tries to accelerate and decelerate but never reach full speed. If you build this like me one of your axis might be mirrored. This is easy to fix. Option $7 lets you change direction on axis. I wanted to change direction on the X axis so I type in "$7=8" as I want to change bit 3 (8 = 00001000 binary) if you want to change direction on Y axis you type in 16 (00010000) or 24 (00011000) to change both. The complete documentation of the invert mask can be found here .

Now you are ready for the computer setup. If you want to try some movement you can type "G91 G28 X0 Y0 [return]" to zero the axis. Followed by "X10 Y10 [enter]". You should see 10mm movement on each of the axis.

Remove these adsRemove these ads by Signing Up
rcerchier3 months ago

hi, can i use arduino uno for this project?

imont10 months ago
Hi again, do you think, the gcode can be modified to run a galvo? You know
, to correct the geometry distortion.
DBender1 year ago
Hello friend, first I would like to congratulate you on an excellent project.
Well I am Brazilian and I have difficulty understanding English, would aid her.
I'm struggling to understand how to download the files to the arduino, control the motors, which files should I download?
You could pass them to me by email?
Thank you.
Simpson_jr1 year ago
A nice ~easy to build instructable for a rather professional application at almost no costs !!! I really love instructables like these. To make it an even cheaper device, check the house for abandoned floppydrives, they already have a stepper-controller, controllable by two pins of the floppydrive-connector, built in. Resolution will be lower as when using easydriver controllers but, looking at the engraved Match..., probably still quite high.
nemoskull1 year ago
ur my hero. that is the ghettoest thing i have every seen, proving once again that you dont need 4000$ to get a cnc laser cuttter, or even 1000$ to buy parts and assemble it, just a bit of thinking.
great job!!!!
rmistry11 year ago
how to make hex file
Hey, i have a question about using the easydriver hardware. I'm using a seperate driver for my laser so what would I have to do to drive the steppers without using all of the circuitry that you used.
1st of all this is the best explained tutorial for CNC (especially for the software part!)
Now to my questions
1st- so the 53.333 is the length of the axis, so if i were to make my laser engraver bigger thats the thing to change right?

and second: If I use the pin-out defined by Grbl i can just use your .hex file , right?
, oh and is the shield schematic you provided uptadet (with the correct pin-out's)
Thanks in advance!
Groover (author)  Tutorial Master1 year ago
53.3333 is the number of steps needed to move one mm. This have to do with the number of steps per revolution and the screw. On most DVD's (all i checked) this number will work. But if you build a machine with another stepper and screw you might have to change it.

Yes, schematics and hex file will be the correct pinout for grbl. Unless they changed it in the last year and you use the files from Grbl repository. They have come a long way in since this was written.
Thanks for the reply! One more thing- is it possible to extend the X,Y axes to make it bigger with that kind of setup, what would i have to change?
Groover (author)  Tutorial Master1 year ago
The software should work as is. The easydriver should be able to drive larger steppers if you would use something like a small x-y plotter or something like that. But they need cooling and the limit is 750mA per driver, so no big stepper like in CNC milling machines.
i can still use the small steppers to drive a bigger rig, right...or are they consuming more current when they are at greater effort
but how does the program know how long the "cutting area" is (how long are X and y) if i dont define it somewhere , i mean , wont it print/cut on a 5x5 cm even if my setup is ...25 cm ?
livingbios2 years ago
also, the TX light is blinking constantly...
livingbios2 years ago
why is it that when i run a termite terminal it keeps saying "tick tack tock" constantly? at the very beginning it says "Motor Test!" and then it just spams that tick tack tock bullshit. i try to enter $, but it gives me nothing... what the hell is going on?
prandall2 years ago
Thank you for the GREAT instructable. I am looking for a little clarfication on GRBL. Background is I have easydriver setup and tested as working with other code.

For streaming a file to GRBL with G-code sender I not sure what to expect. I put your 2 sample line in, however G-codeSender only ever sends Row 1.

Is g-codesender waiting for some sort of acknowledgement before sedning the next line?
Fr0sty2 years ago

I'm using chipkit max32 (arduino mega clone) and when I try to upload .hex file using xloader - shows "upload failed".
I can't find any software to upload the .hex file.. can you give me some suggestions ?

Fr0sty Fr0sty2 years ago
yaaaay! after few hours (being a complete noob) i successfully uploaded the hex on my chipkit max32 arduino mega clone... i entered folder where arduino processing software is (mpide.exe) opened hardware/tools/avr then hold shift and right click, press Open Command Window Here and typed:

avrdude.exe -C ../etc/avrdude.conf -c stk500v2 -P COM3 -p pic32 -b 115200 -U flash:w:"C:\Users\Fr0sty\Desktop\Laser\simen-grbl-74576a8\grbl.hex":i -v

then its loading and succes!
Fr0sty Fr0sty2 years ago
when i open serial monitor and type $ i don't receive any information nor the welcome message: - '$' to dump current settings" - ... i also tried another serial terminal called "Termite" and tried all the baud rate from 9600 to 115200.. i guess the problem is that the microcontroller is a virtual ATmega2560.. i'll buy an Arduino Uno tomorrow to cut the crap.. btw..i can move my little steppers from arduino sketch and i'm using A4983 Stepper Motor Driver Carrier from Pololu..and my laser driver is adjustable (30mA-800mA/4.5V-16V) (50mW,
100mW, 150mW, 200mW, 400mW, 500mW) all colors.. but is with pushbutton :< i must modify the laser driver in order to turn on and off when its needed..
Fr0sty2 years ago
ohhh for the love of god :))..the .hex is for atmega328 or 168..facepalm..therefore is not working for me :9...i'll buy tomorrow an arduino uno.. 8-|
BobPigford2 years ago
Found the problem: Adduino pin assignments noted (above) as default for GRBL are misleading. The incorrect ones are noted on the "Connecting GRBL" page:

For GRBL version 0.6, the default Arduino pin assignments should be:   
                                        Arduino Pin #
X_STEP_BIT                         2
Y_STEP_BIT                         3
Z_STEP_BIT                         4
X_DIRECTION_BIT             5
Y_DIRECTION_BIT             6
Z_DIRECTION_BIT             7

All is good now.
BobPigford2 years ago
Wiring is correct. Works fine with simple Arduino .pde file written to test the motor. Motor is fine, and works at most any setting of power pot.

Appears not to work with GRBL. GRBL hex file loaded with Xloader just fine. GRBL responds correctly to $ prompt, and can change settings correctly, but still only a slight movement when issuing an X command (testing only X direction now).

Should I have loaded GRBL into the Arduino with a separate hardware programmer like the AVR ISP2? Why would this make any difference compared to Xloader?

Still dead in the water. Thank you to all who offer suggestions!
BobPigford2 years ago
Oh, I forgot to add that I am using EasyDrivers and their related stepper motors (12vdc and .33amp) from SparkFun.
BobPigford2 years ago
I wast able to use Xloader to install the GRBL hex file and I get the proper response after sending a $. I configured for my X,Y, and Z movements in steps/mm correctly.
However, when I send, for example, a movement command, say X100, all I get is a small movement. In addition, sending X-100 does not reverse the direction. Sending X10000 delivers the same small movement. And the motor is getting hot!
Please offer suggestions! Thank you in advance!
Bob Pigford
legazier2 years ago
Hi Groover, this is a very nice project that got me very inspired: thanks! I am having difficulties with my Arduino board, also a Mega 1280. After checking how the Arduino IDE is doing it, using the verbose mode, (press SHIFT while clicking the upload button, btw), I managed to upload grbl. However, there seems to be a problem when I open a terminal emulator session or the Arduino IDE serial monitor: the board appears to be sending stuff non-stop (the prompt appears continuously) but never gets to "ok". I am going through the code to see if I can tweak it, but I am not familiar with this code yet. Any ideas?
pi-rho3 years ago
FIXED: changed to -b57600 for the correct baud rate fot 1280 in ARP uploader, X loader didnt work, not sure why
pi-rho3 years ago
reading the log it appears "protocol error, expect 0x14, resp 0x51"
pi-rho3 years ago
Hey Groover,

When attempting to upload the grbl.hex to my arduino mega 1280 (older revision not the new one on sparkfun) I get Upload Failed, on Xloader and something about "not in sync" on ADP is this because this program was not designed for the mega or is soemthing else up ?

vknezevic3 years ago
Can you make *.hex file to work without easydrive? It's out of stock, and it's hard to find. I want to connect stepper motors to 2,3,4,5 arduino pins for x-axis, and 6,7,8,9 for y-axis stepper motor trough dralington array. Laser on pin 10. I looked to source code, but is to hard codded for me. Can point to file and code row where is chosen output pins on arduino? I am newbie in C and need help
Jarzas3 years ago
I got my engraver to work but there is strange problem with arduino (bare atmega328p with 16MHz resonator in stripboard), my laser start burning immediately from zero (0.0) and stop burning too early. Burning start immediately when M3 code is send to arduino buffer and stop when M5 is in.
Any idea what's wrong?
Groover (author)  Jarzas3 years ago
Yes, It is a bug in the Grbl code. I thought it would be fixed but it seems like it is not. The M3 and M5 commands are not put in the queue with the rest of the G-code. It is fixed in the edge version of Grbl. If you feel comfortable about downloading the source and compile it yourself it can be found here. I have a hex file that I can attach as soon as I get home from work.

I'll have to update the instructable about this.
Genomique3 years ago
Dear Groover,
Do you know any Linux or Mac os equivalent to ARP/Arduino uploader ?
Best regards.
GeoffN3 years ago
Hey Groover,
when you calculated the steps/mm to 53.333, did you use this formula
"steps_per_mm = (steps_per_revolution*microsteps)/turns_per_mm"
if so, how do we get "turns/mm " of the screw .


Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!