Tuesday, December 1, 2015

A DIY A4 Laser Engraver made from a scanner and a printer on ATmega328

This "Get Ready For Win98" Laser Engraving Machine it's built using an old scanner, and an old printer.
A laser engraving machine is a tool that uses lasers to engrave an object.

I've an old broken scanner and an old printer lying around. Inspired by this instructables project:
I decide to build a bigger version of my small CD-ROM based laser engraver, you can find here:
That way, the engraving area are will be almost 212mm x 274mm.
Note that some part of this post is taken from the above blog post link.

Before starting up, read my blog disclaimer and the one below:

Warning! Laser diodes drive are emitting visible and invisible laser radiation and they are extremely dangerous! Their light can permanently damage the eyes. You must never look into the working diode even without the lens or point it on a reflective surface. Laser beam can cause burns or fire. This is usually a Class IIIb laser. Everything you do at your own risk.

The Y-axis it is build using the scanner assembly, the X-axis using the printer one.
As you can see by the Get Ready For Win98 sticker, the scanner is pretty old, and this sticker was so vintage that i've decided to leave it on.

The base of this machine is the scanner itself.
The scanner was completely disassebled, all except the motor and the movement mechanism is removed. The same applies for the printer.
Assembling the hardware, pay attention to build it making X normal to the Y axis. The two direction has to be perpendicular, or your engraving will have distortions.
The printer mechanism it is connected to the Y-axis scanner assembly, that way, the laser moves over the part to be engraved.

My engraver it is powered by a 12V 2A power supply, though the total current absorbed it's 700mA.

The brain of this project is an ATmega328p running at 16Mhz. loaded with grbl firmware http://github.com/grbl/grbl, which is a powerfull yet opensource g-code parser.
I've used an Arduino Mini board, even if the software does not use the Arduino framework.
A 7805 voltage regulator it is used as power supply for the ATmega.
Grbl 0.9 it is build for 3 axis router, to make it works on 2 axis systems like this, with hard limit and homing enabled, a custom version of the firmware it is needed. The only change to apply to version 0.9g are on config.h file.
#define HOMING_CYCLE_0 (1<<Z_AXIS) 
#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) 
was commented out and changed to:
#define HOMING_CYCLE_0 ((1<<X_AXIS)|(1<<Y_AXIS))
//#define HOMING_CYCLE_0 (1<<Z_AXIS) 
//#define HOMING_CYCLE_1 ((1<<X_AXIS)|(1<<Y_AXIS)) 
Then the new grbl firmware can be compiled and used, preventing grbl 0.9 homing problem on 2 axis machines.

My custom version of grbl v0.9g compiler for ATmega328p @16Mhz, with a baudrate of 115200, can be download below.
CP2102 it is used as USB to UART board.
You just have to upload the firmware using your favorite uploader, the grbl wiki page drive you on how to do this step.
On the grbl wiki page you could also find any other information about command and software setup.

The motor driver I've use to move the X and Y motor stepper are Polulu A4988 Stepper Motor Driver Carrier, based on Allegro A4988.
My scanner has an unipolar 5-wire stepper motor. That Allegro driver works only with 4-wire bipolar stepper motor. So I've transformed the unipolar motor to a bipolar stepper motor.
To made this modification, I've just cut the common wire between the two main windings. Then I checked that the windings haven't got any connection by using a multimeter. That way i have two coil, like a bipolar motor. Look at the image below for carify:

The printer has a bipolar 4-wire stepper motor.

We can setup how many microstep and how much current Allegro A4988 sends to the motor.
Incrasing microsteps makes the motor more accurate, but it also reduce the motor torque.
You can made some tests to find your best motor power setup.
For mine motors, to allow a smooth and fine motor movement, and a good torque the Allegro A4988 it is setup to 8 microsteps for the Y-motor, and 16-microstep for the X-motor.
Below you can find the basic Polulu board connection wiring.

To make the Polulu board runs at 8 microsteps M1 and M2 has to be connected to logic power supply VDD, if you want to run it at 16 microsteps, connect also M3 to VDD.

Motors supply VMOD is connected straight to 12v.

On each axis a limit and an home microswitch it is placed to prevent axis over-running, and eventually the motor or the motor driver damage.
Because the limit switch are pretty sensible to noise, I've added an high pass 100nF capacitor and an additional pull-up 10k resistor. Also the limit and home wire are indipendent and distant from the motor and laser cable strap.

The laser used is a red laser diode, taken apart from the DVD-ROM writer optics.
In CD-ROM and DVD-ROM you could also find IR driver, DVD laser writer diode will be a little more powerfull than the CD one.
Laser diode usually has three pins, one is the common ground, laser and photodiode cathode (-), one the laser diode anode (+), the other is the monitor photodiode anode(+).
If the diode you are using has no mark, and you do not know the diode pinout, you have to find the laser cathode and anode. One simple method I use is to power up the diode with a 1.8 to 2.2v current, just for a little amount of time, let's say 1s, if it absorbs current, that wiring is the laser diode pinout.

Laser diode has to be drive with a proper driver, to run mine, i've build a LM317 based laser driver.
This laser driver can drive diode from 12mW to 700mW.
A 9v voltage regulator prevent overvoltage on the laser diode.
Also a NPN it is placed to allow the TTL input that comes from the microcontroller to enable or disable the laser.
We are using LM317 IC as a current regulator.
Input voltage get in the Vin pin of the LM317, from the output Vout to the ADJ pin there is a resistor R connected.
The output current Iout is given by the formula Iout = Vref/R.
Over there resistor there always be Vref voltage. When current decrease, the voltage over R should be lower, but that way the regulator increase his output voltage to adjust his Vref voltage.
Vref is 1.25 for the LM317. R is made using a fixed resistor R1 and a trimmer R2. That resistor and the trimmer sets the current that the laser use.
So laser driver current is given by the formula: I=1.25/(R1+R3).
The power rating of the resistors R1 and R2 is calculated by the forumla P=1.25*I.
Before connecting the laser and testing the driver, check that the resistence is the higher value possible, then connect the laser and measure the absorbed current using an amperometer. Note that if you set too much current to the laser, that will blow.
Below the laser driver circuit.

A standard 60mm x 60mm pc brushless fan is installed to clear the smoke, this prevents the laser optics lens to be clouded.

Commands to the engraving machine are sent through UART at 115200 baud rate.

One you have built the machine, checked and connect all, upload the grbl firmware to your microcontroller, you could use terminal software, or a grbl controller to setup your board. I'm using Universal G-Code Sender to setup and send command to grbl, but you can also use a simple terminal.

The first thing to do is test the motor movement:

To test it, just send the
X10 Y10
command, or use the Universal G-Code Sender movement button.

You should see a motor movement on each axis.

Also check the laser is turned on and off using

Now to setup the correct motor distance to run, you have to set each motor step/mm.
The axis motor step/mm calibration method is pretty simple.
Let's try the X axis calibration as example.
We know how many step/mm or steps_per_revolution grbl is actually setup, grbl $100=250.000 (x, step/mm) parameter.
Now, we move your motor for some steps, let's say 100 microsteps, the axis should have move 100mm.
Now we measure the real distance the motor has moved, let's suppose is 181mm.
The new step/mm value for this motor axis should be
steps_per_mm = (steps_per_revolution*microsteps)/mm_per_rev
138.121 = (250*100)/181
Now, if you move the motor 100mm, it should move 100mm.

Because i've installed the limit and home switch, I have alse enabled hard limits
I've setup the homing pull-off to 5mm, cause my microswitch have a long lever, and i want the motor to move fare away after the home cycle.
Also the homing cycle it was enabled:
And the homing direction mask it is changed. One may even need to invert axis direction, "dir port invert mask" is the paramenter you have to touch.

Those are the most common grbl setup, for the complete list, look at the grbl wiki page.

Below you can find the grbl configuration parameters i changed:
$21=1 (hard limits, bool)
$22=1 (homing cycle, bool)
$27=5.000 (homing pull-off, mm)
$23=3 (homing dir invert mask:00000011)
$100=37.879 (x, step/mm)
$101=94.246 (y, step/mm)
$110=100.000 (x max rate, mm/min)
$111=100.000 (y max rate, mm/min)
$130=212.500 (x max travel, mm)
$131=274.400 (y max travel, mm)

Now you could be able to send g-code drawing to your engraver.

There are a lot of software you could use to build g-code draw, the one I use the InkScape.
The working are for this plotter is 212mm x 274mm, so setup your project area to this dimension.
Once you have you path, then you could select the path you want to engrave, and transform it using the InkScape laser engraver extension.
Just copy the extension on your extension inkscape folder, restart inkscape, and use that to build your g-code file.
Once you have your g-code file, you could send it to grbl using Universal-G-Code-Sender, or other grbl software like Grbl Controller.


  • read risk disclaimer
  • excuse my bad english