Pocket laser engraver.

 by Groover
Contest WinnerFeatured

Step 6: Prepare the Arduino.

ArduinoLogo.jpg
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 github.com . 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 .

Important:
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
ok

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
imont says: May 23, 2013. 4:40 PM
Hi again, do you think, the gcode can be modified to run a galvo? You know
, to correct the geometry distortion.
Simpson_jr says: Mar 15, 2013. 5:13 AM
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.
dcms4 in reply to Simpson_jrApr 9, 2013. 2:51 PM
I have like 6 old floppy drives and would LOVE to be able to use them for something like this. Can you point me in any direction on how to leverage them in such as way as you describe.
Simpson_jr in reply to dcms4Apr 10, 2013. 6:24 AM
http://www.epanorama.net/circuits/diskstepper.html

You could use the floppydrive-mechanics as well for an engraving machine as above, unfortunately they have a smaller "reach" as DVD-players. I've noticed that some floppy/DVD-drives use unipolar steppermotors/drivers, while other use bipolar steppermotors/drivers. (Some DVD-drives don't use steppermotors b.t.w.) You'll need to be sure driver and motor are the same type.
DBender says: Apr 9, 2013. 8:55 PM
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.
nemoskull says: Jan 4, 2013. 4:54 PM
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!!!!
rmistry1 says: Jan 2, 2013. 5:55 AM
how to make hex file
Unclegummers says: Oct 24, 2012. 8:35 PM
(removed by author or community request)
Electroinnovation says: Jul 27, 2012. 6:25 PM
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.
arvacon in reply to ElectroinnovationAug 6, 2012. 12:33 PM
You can just use the lasershield board that Groover provides, without need put any of the laser components that you can see at his list at the below msg.
Just make the board and use it for the easydrivers, or just connect the easydrivers with the arduino by simple cables (but I would suggest you to use the board as it seems better way).
Tutorial Master says: May 28, 2012. 3:23 PM
Hi,
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) in reply to Tutorial MasterMay 28, 2012. 11:53 PM
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.
Tutorial Master in reply to GrooverMay 29, 2012. 4:33 AM
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) in reply to Tutorial MasterMay 29, 2012. 5:43 AM
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.
Tutorial Master in reply to GrooverJun 9, 2012. 4:09 AM
I could use the Pololu drivers with 2A limit for bigger steppers (1000grams/centimeter is ok for a CNC dremil mashine, right?)
Oh and i have also seen that people use servos instead of steppers, can they be used with this software?
Thanks!
Tutorial Master in reply to GrooverMay 29, 2012. 3:15 PM
P.S.
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
Groover (author) in reply to Tutorial MasterMay 29, 2012. 1:34 PM
The small from a DVD drive will not work well with anything larger. They will consume more power but as they are fairly small and fragile they will overheat by the load. However you could try to find some old 5.25" floppy drives. Sometimes they have very good steppers that should work.
Tutorial Master in reply to GrooverMay 29, 2012. 3:14 PM
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 ?
Groover (author) in reply to Tutorial MasterMay 29, 2012. 1:42 PM
Well, that is the thing about how these machines work. They don't know the size and will happily try to do the 25 cm work even on this little machine. Only that it will crash into the side ones it gets to the max position. Normally you will make sure your work is within limits (like on this little thing) or have limit switches that will report back and let you know that your outside of the workarea and stop the motors.

This is the reason you have to take great care when you create your g-code from your drawing. If your drawing is of a box 20cm by 20cm the controlling software will try to make that happen without knowing the physical limits.
livingbios says: Dec 30, 2011. 1:03 AM
also, the TX light is blinking constantly...
livingbios says: Dec 30, 2011. 1:00 AM
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?
prandall says: Dec 10, 2011. 6:40 AM
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?
Groover (author) in reply to prandallDec 10, 2011. 1:16 PM
Yes, it is. There have been some confusion on the line endings of different versions of GRBL. Depending on the version of G-code sender there should be an option for \n\r and \n\r as a line ending.
Fr0sty says: Oct 23, 2011. 10:42 AM
Hi,

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 ?

Thanks.
Fr0sty in reply to Fr0styOct 23, 2011. 2:58 PM
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 in reply to Fr0styOct 23, 2011. 4:06 PM
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 :<..so i must modify the laser driver in order to turn on and off when its needed..
Fr0sty says: Oct 23, 2011. 3:49 PM
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-|
BobPigford says: Oct 22, 2011. 11:31 AM
Found the problem: Adduino pin assignments noted (above) as default for GRBL are misleading. The incorrect ones are noted on the "Connecting GRBL" page:
http://dank.bengler.no/-/page/show/5473_connectinggrbl?ref=mst

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.
Bob
BobPigford says: Oct 21, 2011. 6:40 AM
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!
Bob
BobPigford says: Oct 20, 2011. 1:03 PM
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
Groover (author) in reply to BobPigfordOct 20, 2011. 1:08 PM
It sounds like it might be your stepper not connected the right way.
BobPigford in reply to GrooverOct 20, 2011. 2:36 PM
Thank you. I'll re-check the wiring right away.
Bob
BobPigford says: Oct 20, 2011. 1:08 PM
Oh, I forgot to add that I am using EasyDrivers and their related stepper motors (12vdc and .33amp) from SparkFun.
Bob
pi-rho says: Apr 18, 2011. 2:21 PM
FIXED: changed to -b57600 for the correct baud rate fot 1280 in ARP uploader, X loader didnt work, not sure why
omnistructable in reply to pi-rhoMay 3, 2011. 11:54 AM
I had more or less same prob with Arduino Uno with AtMega328p. I've used ARP Uploader to load the hex file. Just delete the baud rate parameters from the AVR Dude Params to read: "-F -v -pm328p -cstk500v1 -P\\.\COM1 -D -Uflash:w:"D:\Your Dirrectory\grbl_0_6b_atmega328p_16mhz_9600.hex":i" and hit upload.
Groover (author) in reply to pi-rhoApr 18, 2011. 11:45 PM
I'm glad you sorted it out. The problem is in the AVRdude that both the uploaders use. Not a problem per say, but as you cant set all parameters in XLoader it seems be a little harder to get it to work on some AVR based devices.
legazier says: Apr 30, 2011. 10:02 PM
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-rho says: Apr 18, 2011. 1:50 PM
reading the log it appears "protocol error, expect 0x14, resp 0x51"
pi-rho says: Apr 18, 2011. 1:46 PM
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 ?

Thanks!
vknezevic says: Apr 14, 2011. 11:46 AM
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
Pro

Get More Out of Instructables

Already have an Account?

close

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!