Você está na página 1de 27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

20th October A Raspberry Pi controlled mini CNC Laser engraver [last update
Dec 18, 2013]
I recently made a mini CNC laser engraver using two DVD drives salvaged from old computers and <$10 extra parts bought on
eBay. The controller of the CNC machine is a Raspberry Pi, a $35 credit card size computer. The engraver turns out to be pretty
successful. So I am sharing it with everyone.
There have been a lot of examples people using Arduino to control CNCs. And you can probably can find tons of C programs
available that can run directly on Arduino to process G code. A famous one is grbl. Like this on by Groover in instructable
[http://www.instructables.com/id/Pocket-laser-engraver/] A Chinese translation can be found here [http://www.guokr.com/article/18616/] .
Also there are available CNC controller like MATH3 on the market that can be controlled by serial.
I am taking a different approach by using a RPi (http://www.raspberrypi.org/)

[https://lh5.googleusercontent.com/-gZxCHkodIg/UmQ7E0MNe3I/AAAAAAAABlo/j4Xc11Na9Zk/s640/blogger-image-1777046652.jpg]
A Raspberry Pi mini computer
The reason why I choose Raspberry Pi is: it is a much more powerful device than Arduino; it has a complete OS; the GPIO pins
can be controlled by python, a more intuitive and simpler language than C (the disadvantage of python would be the slow speed); I
don't have to buy a separate controller for this project--I can use a single Raspberry Pi to do a lot of different things without
reloading firmware. Most importantly, I have a Raspberry Pi but don't have an Arduino right now!
Also, there are projects people running LinuxCNC on Raspberry Pi and use an external PIC 32 board to control CNC. It's a great
idea but I want to limit my cost to be minimum. Instead, I wrote my own python interpreter to execute G code or process jpg
image directly. For 2D CNC laser engraver, it is actually very easy to control and don't require high-level program techniques.
I will keep updating this post. And hopefully this post will eventually cover everything including the python code.
First, some pictures.

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

1/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh3.googleusercontent.com/NhET35e5HHE/UmQ6XNquFGI/AAAAAAAABlY/1h6hy94DCJ4/s640/blogger-image-1422023181.jpg]
Laser engraver is work ing

[https://lh4.googleusercontent.com/-9WzCIW9OWPY/Umrz8fhsEdI/AAAAAAAABqM/mGzgnLCfkuc/s640/blogger-image1868552292.jpg]
A coin size university icon on a plastic board

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

2/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh4.googleusercontent.com/--Uz2gPIMjGE/UmQ6VzgbuI/AAAAAAAABlI/T7Md51ZZ9wE/s640/blogger-image-1452605621.jpg]
I messed up the direction for this one...

[https://lh4.googleusercontent.com/X5Fff2_epwM/UmQ6WXvi99I/AAAAAAAABlQ/znB88dNArXc/s640/blogger-image-1347168473.jpg]
Some words..

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

3/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh3.googleusercontent.com/TO6rmzfeHiE/Umsa8Qr6DFI/AAAAAAAABqs/Xuf_pwW9_mY/s640/blogger-image-954034757.jpg]
The machine is not pack aged yet. You can find: machine (top middle), controlling circuit (top left) and RPi (lower right)

[https://lh4.googleusercontent.com/O_1FzA6BDMg/UmsbKBSgJyI/AAAAAAAABq8/gfj1FxDT4BU/s640/blogger-image-1433608126.jpg]
The controller and wires in a perfect chaos

Must read!!!
This post has drawn considerable attention in the past several weeks. Sorry that I still haven't been able to finalize it yet.. But
everything needed to make a RPi mini laser engraver is already here. Once all parts are ready, it shouldn't take more than a
weekend to finish the project.
Now, as everyone does, I feel crazy about laser. But it is extremely important to keep in mind that the laser used in this project
could burn human eye retina in millisec before eyeball is capable to react. Even a random reflection beam during engraving could
be >50 mW (for comparison, a regular laser pointer is 1 mW), and make permanent damage to your eyes, kids' eyes, or pets'
eyes. ALWAYS WARE A LASER SAFE GOGLE when you are close to the working engraver. A suitable one for 650 nm laser
should be green color. MAKE SURE THE ENGRAVER IS NOT ACCESSIBLE TO KIDS OR PETS. I would suggest everyone
planning to build this should enclose the whole thing inside a large box or cover (however, mounting a little computer fan on the
box would be nice).
AGAIN, think TWICE before you make it.

About the capability of the engraver


Due to the size limit of DVD drives, the machine can only engrave within an area of 36 mm by 36 mm.. So it can do little pieces of
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

4/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

wood, plastic board or iPhone cases, but not any larger.


The laser used here is 200 mW 650 mm red laser diode. It cuts letter paper fine. But It is not powerful enough to actually cut
through anything thicker and tougher. In fact, the working surface is preferred to be black color so that it can absorb as much
laser power as possible. To engrave on transparent plastic board, as shown above in the coin size university icon picture, I have to
use a black marker to paint the surface and clean the ink after engraving. However, I believe for a thin black foam sheet (<3mm
thick), and given enough engraving time, the laser should be able to cut it through, as Groover showed in instructable.

Now here is the instruction.


Things required:
1. A raspberry pi (running Raspbian or what ever supporting GPIO)
2. two DVD writable drives.
To be able to engrave, you need 200mW laser diode from DVD writer. A DVD R or CD R will do nothing. A CD writer might be OK
in term of power (~100mW), but the laser diode of a CD writer is infrared, which can be super dangerous (you can't see it!).
3. a TO-18 5.6mm laser housing
(like this one http://www.ebay.com/itm/251316903193?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649)
4. Two dual channel H-bridges.
A H bridge is a circuit containing four (effective) switches that can apply a voltage across a load (DC motor or one coil of a stepper
motor) in either direction.
Stepper motors from DVDs are 4 wire 2 phase bipolar stepper motors. They require truly reversible voltage on each pairs of the
wire. You need two H bridges for each stepper motors. So total of four H bridges for teo strepper motors. Some famous stepper
motor controllers like ULN2003 are for the 5 wire stepper motors, so they cannot be used for controlling the DVD stepper motors.

You can make your own H bridges by using 4 NPN and 4 PNP transistors and probably TTL converters (RPi's GPIO pin are 3.3V
so logic TTL chips might be required). Or you can simply buy them. There are a lot of integrated H bridge circuits available in the
market, such as L298. The ones I use are L9110s Dual H Bridge purchased on Ebay (like this one:
http://www.ebay.com/itm/350877288713?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649). They are low cost (~$2
each), compact (.8"x1") and are powerful enough (~800mA). However, if you buy from a Chinese seller, shipping can cost 3
weeks.
L9110s is also known as HG7881.
Regarding the H bridge, you need to make sure that the continuous current limit of the circuit is greater than 500mA. Usually the
stepper motor in a DVD drive is rated at 5V and each coil has a resistance of 10ohm. So the current through each coil would be
500mA!

5. a LM317 regulator, a power NPN bipolar transistor (like E3055, should be able to handle continuous 200mA at least), some
resistors, capacitors and a bundle of jumpers.
The LM317 is for the laser driver. The power NPN is for making a switch for the laser. My lab has tons of these components so I
don't have buy them. If you don't want to solder a driver by your own, you can surely buy a laser driver for <$5. The laser driver
need to be able to output at least 200mA at 2V and have the function of enable/disable.
6. a solder gun, screw driver and some basic hard wares.

STEP 1: Disassemble DVD drives


There are a lot of picture/video tutorials online for this step so I will keep it short.

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

5/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh3.googleusercontent.com/A8TCx9psJ1k/Umf7nko9YsI/AAAAAAAABnE/E92lJZWfB7Q/s640/blogger-image--865966619.jpg]
Two DVD found in E-waste

[https://lh6.googleusercontent.com/AqE0_gUYNTM/Umf7m607nCI/AAAAAAAABm8/Kq3PtUQ0-B8/s640/blogger-image--1290820048.jpg]
They are rewritable

All you need from the DVD are


1. stepper motor with the slider (lower right part in
the picture below)

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

6/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh5.googleusercontent.com/-uShfewz1fs/UmSPqMT8zZI/AAAAAAAABmA/ttZV2bW4imM/s640/blogger-image-675544038.jpg]
tearing down a DVD

2. Laser diodes (see picture below). Be very careful


that the laser diodes on the DVD are very fragile.
Make sure you don't break them.

[https://lh6.googleusercontent.com/U9SHrrvyYjM/UmSTtTAAo7I/AAAAAAAABmc/G2nZTaapCEE/s640/blogger-image-1858542639.jpg]
Two 5.6mm laser diodes (infrared and 650nm red)
compared with a USB connector.

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

7/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh5.googleusercontent.com/KdkGOs7eL30/UmSPtdBrOpI/AAAAAAAABmI/lpZfL5FjOXI/s640/blogger-image-1710620668.jpg]
Stepper motor (right) and linear slider.
I soldered four wires on the stepper motor.

There are other good things you can salvage from the DVD drive and keep for future projects, such as a 9 V dc motor near the
gate, a brushless motor that spins the DVDs, some shock reducers and some miniature lens and optic parts. You can also find
four strong magnets near the laser diode. Don't throw them away. They will turn out to be useful later.

STEP 2: Assemble Laser


Now you have two laser diodes. One is infrared which we don't need. The other one is 650nm red diode (usually has a letter 'R' on
it) and is the one we need. The diode normally has three pins forming a fat triangle. One is NC. You need a multimeter to figure
out which two pins are cathode and anode. The forward voltage across anode and cathode should be around 1.4V and the forward
resistance should be 20-40k ohm. If the forward resistance is too high then the laser diode is over used.

[http://2.bp.blogspot.com/XSMh79o74FQ/UmgAjAM49fI/AAAAAAAABnU/KkE5DPnQ1us/s1600/untitled.bmp]
The laser diode housing

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

8/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[http://1.bp.blogspot.com/-nrlB5I5__xA/UmgB5GeydNI/AAAAAAAABng/baeZmj4pIIA/s1600/laser.jpg]

[https://lh4.googleusercontent.com/nhuXe5WT5pE/UmoYwpU_1oI/AAAAAAAABpU/YKjhDO8bskw/s640/blogger-image--801909403.jpg]
Laser diode (middle left) and laser housing
[http://1.bp.blogspot.com/-nrlB5I5__xA/UmgB5GeydNI/AAAAAAAABng/baeZmj4pIIA/s1600/laser.jpg]
[https://lh4.googleusercontent.com/-V4anUZswBHM/UmoYvGexB-I/AAAAAAAABpM/sddluZksTXs/s640/blogger-image400252594.jpg]

[https://lh4.googleusercontent.com/DA0TsV2dvrQ/UmoYrxJq4xI/AAAAAAAABo0/GgB7EFyrV2A/s640/blogger-image-1938372409.jpg]
Pushing the diode into the housing head
[https://lh4.googleusercontent.com/-V4anUZswBHM/UmoYvGexB-I/AAAAAAAABpM/sddluZksTXs/s640/blogger-image400252594.jpg]

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

9/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

Laser diode in the housing head


[https://lh6.googleusercontent.com/-szkDaeXurBI/UmSPo2geN-I/AAAAAAAABl4/OVzK8VPKZdg/s640/blogger-image--230814447.jpg]
[https://lh6.googleusercontent.com/-w6lrjFmfVAQ/Umi5pGhVmaI/AAAAAAAABoA/hyWFvHhWFpU/s640/blogger-image--1656642207.jpg]

[https://lh6.googleusercontent.com/I2tiD3hpFGw/UmoYmgVRJZI/AAAAAAAABoc/zch9WYhH0Lo/s640/blogger-image-482774664.jpg]
Solder two wires on the diode
[https://lh6.googleusercontent.com/-w6lrjFmfVAQ/Umi5pGhVmaI/AAAAAAAABoA/hyWFvHhWFpU/s640/blogger-image--1656642207.jpg]

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

10/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh5.googleusercontent.com/EELclxxwmHI/UmoYn1OjXoI/AAAAAAAABok/CTrNSCnXdjM/s640/blogger-image-1314658176.jpg]
Use some heat shrink to increase the strength

[https://lh3.googleusercontent.com/fL2kWXPADlY/UmoYpBnIc4I/AAAAAAAABos/8SUVecbUQGQ/s640/blogger-image-1947563989.jpg]
Getting there

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

11/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh4.googleusercontent.com/zmVUvqNTwBU/UmoYsqg_vGI/AAAAAAAABo8/KkzCpx0A8oo/s640/blogger-image--227150302.jpg]
Done!

Carefully put the laser diode into the head of the laser housing. You can use the laser housing body to help knock against the
diode and push the diode into the housing head. The diode should fit perfectly into the head. Make sure the pins are still fine. Then
solder two wires to the electrodes and assemble the housing together.

STEP 3: Make laser driver and enabler and test the laser
A laser diode is like a photodiode but equipped with a resonant cavity. Laser diode is a huge current sink. Once the
diode conducts, it generates a lot of heat, and the heat further lowers the diode impedance. So it is a unstable positive
feedback system. If you simply put a 1.5 V battery across the diode, you will either get the diode burn or battery
drained right away. We need a laser driver that can output a constant current to the diode.
There are numerous way to do this. One of the most popular and least frustrating way is to use a DC current regulator. LM317 is a
good choice. By adding a resister R across the adjust pin and output pin, LM317 can output a constant current of ~1.25V/R.
[In fact, LM317 is mostly used as a voltage regulator. It maintains a 1.25V across the output pin (pin 2) and the adj pin (pin 1).
Meanwhile, it controls the current output from the adj pin to be very low (usually <100 uA). Therefore by adding a resistor R across
pin 2 and 3, we can have 1.25V/R current output from pin 2 to pin 1. We then add the laser diode across pin 1 and GND. Since
pin 1 is forbidden to sink current, all the 1.25V/R current outputted by pin 2 will flow through R and laser diode to GND. The official
datasheet of LM317 can be download here . [http://www.fairchildsemi.com/ds/LM/LM317.pdf]
A good instruction can be found here LM317 Laser Driver [http://www.rog8811.com/laserdriver.htm]

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

12/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

In my case, I replace the two parallel 10 ohm resistors by two .5 Watt 12 ohm resistors. The max current I am going to run
through the diode is 200mA.
Make sure you don't mess up the adjust pin and the output pin. A heat sink would be necessary on the LM317.
You also need a switch that can be controlled by RPi. I used a power NPN E3055 transistor. You can choose what every you
want, just make sure that the transistor can support continuous CE current >300mA and also put a heat sink on it.

[http://1.bp.blogspot.com/-ewI7TGlE0q8/UmvuF9vmrSI/AAAAAAAABrM/pn0yN2P9Vpo/s1600/laser_driver.png]
Schematics of the laser driver and the switch. Laser is on only when "Laser switch" port is logic high (>3V). Mak e sure you don't
mess up the pin order of LM317

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

13/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh4.googleusercontent.com/-0HWB1UT3Ccc/Umrz5RUEyMI/AAAAAAAABp8/lGNwa25KNG4/s640/bloggerimage--1341492090.jpg]

LM317 Laser driver

[https://lh5.googleusercontent.com/kvgU8nHr7YY/Umrz7LGSVVI/AAAAAAAABqE/P6rKSIUDIPg/s640/blogger-image--482078108.jpg]
Laser driver (top) and the E3055 power NPN (bottom)

STEP 4: Shape the machine


Now you have two identical linear stages and it is time to put them together! There are a lot of ways to do this. For 2 axes CNC
machine, I think the best way is the one given by Groover @ instructable. In Groover's configuration, the engraving sample is
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

14/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

attached to x-axis so it only moves in x direction. The laser is attached to y axis so it only moves in y direction. This configuration
minimizes the weight on each of the axes.

[https://lh5.googleusercontent.com/Mr32O1BsXxA/UmoYt96zZDI/AAAAAAAABpE/RByzrEnqT80/s640/blogger-image-1694152089.jpg]
Laser engraver I made

[https://lh5.googleusercontent.com/-nysEOwGE4tc/Umi5n4pVAyI/AAAAAAAABn4/aMFNAwYovCM/s640/bloggerimage-1285557579.jpg]
I cut a 2"x2" steel board out of the DVD case and glued it to the x-axis stage as the sample support base. Since the DVD case is
made from iron, you can use the strong magnets salvaged from the laser optical system to help you stabilize the engraving
sample on the base.
The laser diode will generate a lot of heat . And it is important to dissipate this heat. Otherwise the diode will die fast. I cut a
1inch cube heat sink from an old computer CPU heat sink and drilled a hole though it. The hole is perfectly large to hold the laser.
I glue the heat sink on the y axis stages.
The most important issue is the x axis, y axis and body of laser have to be perpendicular to each other.

STEP 5: Connect H-Bridge to the stepper motors

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

15/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh5.googleusercontent.com/-9yw5RESL_ow/UmvurjhTtSI/AAAAAAAABrU/8u5BnERSTbo/s640/blogger-image975699712.jpg]
Four connect pins on a 4-wire-2-phase stepper motor. They are usually arranged in the following order: a1,a2,b1,b2. (a1 and a2
are the two leads of coil a; b1 and b2 are the two leads of coil b). Using a multimeter will help to verify this.

The stepper motor in DVD is a 4-wire 2-phase bipolar motor. There are two independent coils inside. Each coil has a
10 Ohm resistance. Usually the DVD stepper motors are rated at 5V. Therefor the rated current through each coil is
500mA! The RPi GPIO pins can only output less than 20mA so RPi cannot control a stepper directly. H bridges are
required.
Here

is

very

good

tutorial

on

Bipolar

stepper

motor

Bipolar

Tutorial

[http://www.stepperworld.com/Tutorials/pgBipolarTutorial.htm]

Conceptual model of 4-wire 2-phase stepper motors, from Bipolar Tutorial


[http://www.stepperworld.com/Tutorials/pgBipolarTutorial.htm] .I renamed the pins

Seems I am using different names for pins of stepper motor. In most people's writeup I can find online, they define
coil 1 and coil 2 and name 1a, 1b as the two leads of coil 1, and 2a, 2b as the two leads of coil 2. It doesn't matter, as
long as we know what we are doing. At least in this post I will keep the terminology thing consistent.
The central spinner of the bipolar stepper motor can be regarded as a bar magnet (actually it is circular). Obviously from the figure
above that if we successively conduct current in coil a1, b2, a2 and b1, the spinner will spin in the desired sequence. To do this,
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

16/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

we can apply a voltage sequence to a1, b2, a2, b1 as:1) high, low, low, low. So only a1 and a2 are activated. Since a1 a2 have
same polarity (or opposite depending on how you define it), the spinner is pointing to a1
2)low, high, low, low. So only b2 and b1 are activated. Spinner is pointing to b2
3)low, low, high, low. So only a2 and a2 are activated. Spinner points to a2
4)low, low, low, high. Spinner points to b1.
go to 1).
Denote high as 1 and low as 0. The sequence can be written as 1000,0100,0010,0001
The advantage of this configuration is that it is very easy to understand and usually the stepper motor moves very precisely.
However, since in each step only one pair of coils is activated, the torque applied on the spinner is not very great.
To achieve high torque, a more popular way is to apply the following sequence: 1100,0110,0011,1001. And the spinner will be
pointing to middle of a1 and b2, middle of b2 and a2, middle of a2 and b1, middle of b1 and a1 consequentially. And the torque is
doubled. This is called full-step mode or high torque mode or two phase mode.. and is usually the mode used.
If the torque won't be a problem then we can use a 8-step sequence: 1000,1100,0100,0110,0010,0011,0001,1001. The spinner will
turn 8 steps instead of 4 steps to turn same angle. This doubles the resolution. And the cost is the non-uniform torque being
applied on the stepper motor. This is called half-step mode.
Usually for DVDs, the linear sliders moves about 0.15mm every full step stepper motor turn, corresponding to a resolution of
~170dpi. Good enough for home-made projects. If 8-step mode is implemented, then the resolution is 0.075mm/step or 340dp,
similar to regular printer.
For laser engraver, there isn't any serious load on the stepper motor so I choose the half-step mode or 8-step mode.
As mentioned, RPi cannot drive the stepper motor directly because of the current limit. Actually, besides powering low power
LEDs, the GPIO pins of a RPi usually serves as logic switches. In output mode, they are either logical High (3V) or logic low
(<0.7V). A H bridges is a "translator" that translates these logic High or Low into power source that has high voltage or low
voltage.

A conceptual schematics of H bridge (from wik i)


Above is a conceptual schematic graph of H bridge (has similar shape with letter "H"). One H bridge has two working mode: (S1
S4 close, S2 S3 open) and (S2 S3 open, S1 S4 close). In the first mode, current flows rightwards through the motor and in the
second mode, current flows leftwards through the motor. In reality, this H bridge is never used. A common way is to use transistor
as electric switches. See figure below.

[http://2.bp.blogspot.com/fV0rZGpTArw/UnFHMel0eFI/AAAAAAAABsM/i01kBInTTZ8/s1600/Hbridge.bmp]
A very very simplified conceptual schematics of NPN PNP H bridges. NEVER build an H bridge based on this graph. You
will probably burn the transistors or even the Pi. A practical H bridge requires current limiting resistors, reverse diodes and logic
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

17/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

TTL chips. Please consult more from other sources if you would lik e to build a work ing H bridge from scratch.
When A is logic low (0V) and B is logic high(+V), then transistor 1 and 4 are conducting while 2 and 3 are open; when A is logic
high (+V) and B is logic low (0V), then transistor 1 and 4 are oepn while 2 and 3 are conducting. When both A and B are logic
high, 2 and 4 are conducting, 1 and 3 are open, the motor stalls; when both A and B are low, 1 and 3 are conducting, 2 and 4 are
open, the motor stalls.
Therefore by setting A and B high or low, we can control the current direction through a load. For each 4 wire 2 phase stepper
motor, there are two independent coils we need to control. So a total of 4 H bridges are required to control the two stepper motors.
There are a lot of integrated H bridge available on the market. For my case, I need 500mA through each H bridge so L9110S
suffices (L9110S can afford 800mA through each H bridge). Each L9110S contain two H bridge so two of them is enough. There
are L9110S module for <$2 each on the market. Very convenient!
I am not exactly sure but I think sometimes people call it L9110 sometimes L9110S.. Datasheet can be found here
[http://nvhs.files.wordpress.com/2013/02/datasheet-l9110.pdf] .
Also, L9110S has internal clamp diodes to conduct the reverse current generated by the sudden stop of the stepper motors. This
protects the circuit. L9110S is TTL/CMOS output level compatible so it can be directly connected to RPi.

[https://lh5.googleusercontent.com/-ZJCKmxDARE/Umrz90EnW3I/AAAAAAAABqU/twC9EEK2yCk/s640/blogger-image--1562055245.jpg]
Two L9110 dual H bridges (also k nown as HG7881). They are 0.8" by 1" big
Each dual bridges control a stepper motors. On the right hand side, there are a1, a2, b1, b2 connectors to the stepper motors
(top to bottom). On the left hand side, there are logic control pins for a1, a2, b1, b2 (actually they are named as A-IA, A-IB, BIA, B-IB) and VCC and GND.

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

18/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

[https://lh5.googleusercontent.com/_u3tXFcXriI/Umrz_CHi1AI/AAAAAAAABqc/QtZBxTCYqSM/s640/blogger-image--492549739.jpg]
When powered, the chips light up (The big circular thing is my ring. I don't have a big finger..)

STEP 6: Driving the machine using Raspberry Pi


Now this is the key part. Because I am not using external stepper motor drivers so I have to incorporate the function of external
stepper drivers in software. I choose python to do the job.
People say that RPi is not a real time device because it has an entire OS on it and python is very slow. However, in my case,
these issues didn't cause any trouble.
The python code I wrote includes the following functions:
1. An encapsulated bipolar stepper motor class. It enclosed information like phase and position. It has a .move(direction, steps)
build-in function that converts movement commands into a sequence of GPIO.output() commands that spins the stepper motors.
2. A G code interpreter: read G code and send the corresponding commands to the bipolar stepper motor objects. For G02 and
G03 commands (circular interpolation), the interpreter performs the interpolation and converts the commands into a sequence of
straight motions.

The most challenging part is how to control more than one stepper motor simultaneously. The idea is actually very simple and
can be extended to any number of motors. We already know how to control one motor. Now suppose we have two motors: MX
and MY, and we want to turn MX 12 steps and MY 15 steps simultaneously in 6 seconds. First find the least common multiplier
(LCM) of 12 and 15, which is 60. Now divide 6 seconds by 60 we get dt=0.1sec. Set 60 loops. Before the end of each loop, we
use time.sleep(0.1) commands. So it takes 6 sec to finish the loop. And we move MX one step every 5 loops and move MY one
step every 4 loops. After 60 loops, MX moves 60/5=12 steps and MY moves 60/4=15 steps. And both MX and MY moved at
constant speeds.

00001 [tel:0000100001] 00001 [tel:0000100001] 00001 [tel:0000100001] 00001 [tel:0000100001] 00001 [tel:0000100001] 00001
[tel:0000100001] 00001

[tel:0000100001] 00001

[tel:0000100001]

00001 [tel:0000100001] 00001 [tel:0000100001] 00001

[tel:0000100001] 00001 [tel:0000100001] (60 digits, 12 ones)

0001 [tel:0001000100] 0001 [tel:0001000100] 00 [tel:0001000100] 01 [tel:0100010001] 0001 [tel:0100010001] 0001 [tel:0100010001]
0001 [tel:0001000100] 0001 [tel:0001000100] 00 [tel:0001000100] 01 [tel:0100010001] 0001 [tel:0100010001] 0001 [tel:0100010001]
0001 [tel:0001000100] 0001 [tel:0001000100] 00 [tel:0001000100] 01 [tel:0100010001] 0001 [tel:0100010001] 0001 [tel:0100010001] (60
digits, 15 ones)

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

19/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

For more than two stepper motors, just find the LCM of all the steps (ignore 0).

You

can

download

all

the

python

code

here

My

RPi

CNC

Laser

Engraver

Code

[http://hostcode.sourceforge.net/p/raspberrypi-cnc-laser-engraver] :

You can find three python codes:

Project: raspberrypi-cnc-laser-engraver
Code
Bipolar_Stepper_Motor_Class.py
[http://hostcode.sourceforge.net/view/1084]

Motor_control.py [http://hostcode.sourceforge.net/view/1085]
Gcode_executer.py
[http://hostcode.sourceforge.net/view/1086]

spiral.nc
[http://hostcode.sourceforge.net/view/1126]

grid.nc [http://hostcode.sourceforge.net/view/1127]

Uploaded
by

Date

Xiang Zhai

October 25,
11:34 pm

2013,

Xiang Zhai

October 25,
11:38 pm

2013,

Xiang Zhai

October 25,
11:39 pm

2013,

Language

Xiang
Zhai

November 11, 2013, 6:31


pm

text

Xiang
Zhai

November 11, 2013, 6:38


pm

text

python

python

python

Bipolar_Stepper_Motor_Class.py [http://hostcode.sourceforge.net/view/1084] defines the Bipolar_Stepper_Motor class. By


default, line 5 is commented and line 7 is valid. This corresponds to a 8-step half-angle sequence. If maximum torque is desired,
you can comment line 7 and uncomment line 5 to select 4-step full-angle sequence.

Motor_control.py [http://hostcode.sourceforge.net/view/1085] defines a set of functions such as LCM (for calculating the lcm of
two integers) and Motor_Step (for controlling two motors simultaneously). Usually you don't need to modify anything.
Gcode_executer.py [http://hostcode.sourceforge.net/view/1086]
This is the main program. You need to modify line 25 (G code file name), line 29 (pin numbers for stepper motor X), line 31 (pin
numbers for stepper motor Y), line 32 (pin number for laser switch), line 35, 36 (resolution of the machine in unit of mm/step) and
line 38 (engraving speed). The code read and interpret G code, and send corresponding commands to the motor control functions.

spiral.nc [http://hostcode.sourceforge.net/view/1126]
This is a simple G code which plots a small spiral. It can perfectly test whether the machine can process G code,
especially the circular interpolation G02 and G03, correctly.
grid.nc [http://hostcode.sourceforge.net/view/1127]
A simple G code which plots several straight lines to make a grid. Perfect code to test the machine and make a
coordinate system!
Currently the Gcdoe_executer.py only accepts limited number of G commands: G90, G20, G21, M05, M03, M02, G01, G02,
G03.
The code can recognize G1F commands (engraving speed) but simply ignore it. Engraving speed is set by line 38 in unit of
mm/sec.

STEP 7: Engraving!
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

20/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

Following Groover (by Groover in instructable [http://www.instructables.com/id/Pocket-laser-engraver/] ), I use Inkscape to make G


code. Inkscape [http://inkscape.org/en/] is an open-source vector graphics editor and support various OS (windows, linux, Mac),
which means that you should be able to install it on Raspbian! I didn't try that. I simply use my laptop and send my design to the
RPi.

You need a laser engraving extension to convert vector graph into G codes. There are several different G code extension. The one I
use can be downloaded here Inkscape-Laser-Engraver-Extension [http://www.slackersdelight.com/instructables/laserengraver.zip]
[Note: I wrote my python G code interpreter based on the G code generated by this Inkscape extension. So the code can only
deal with limited numbers of G commands, sufficient for laser engraving though, fortunately. For G codes given by other generator,
my codes might not be able to handle all the commands. You might have to modify the python code on your own.]
Here is the step-by-step instruction on how to generate G code that my python code can process.

Step 7-1: Install Inkscape and Inkscape-Laser-Engraver-Extension


Inkscape can be freely download here http://inkscape.org/en/
It runs on windows, mac and various linux OS.
Then download Inkscape-Laser-Engraver-Extension [http://www.slackersdelight.com/instructables/laserengraver.zip] here.
To install the extension, simply unzip the file and copy everything into the Inkscape installation folder. For example, in
Windows 7, if Inkscape is installed under
C:\Program Files\Inkscape
, then just copy everything from Inkscape-Laser-Engraver-Extension to C:\Program Files\Inkscape\share\extensions
and then restart Inkscape, the extension should be already installed. To verify this, run Inkscape and check for "Laser
Engraver" item under "Extension" on the manu bar.

[http://3.bp.blogspot.com/-6PnG1Qwpm38/Uq0wtUXP6VI/AAAAAAAABzY/51yUdaDP5qo/s1600/extension.png]
The Laserengraver extension is successfully installed

Step 7-2: change page size


Open Inkscape, goes to "File" => "Document properties" => "Page", under the "Custom Size" box, change the "Units"
to "mm" (millimeter) and then put 36 and 36 in both "Width" and "Height". Then close the dialog.
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

21/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

You will see the blank page becomes a small square box. Zoom into that box.

Step 7-3: plot, text, create, a lot of fun~


You can type texts, plot graphs, or even paste png/bmp in the box.
Press "Ctrl" and "A" to select everything plotted, under "Path", click "Object to Path". Or simply press "Shift" + "Ctrl"
+"C". This steps is required if you have text or other external objects.

[http://4.bp.blogspot.com/-69zIE7HsgJk/Uq0z9arKNmI/AAAAAAAABzk/O846_1rlV9E/s1600/object_to_path.png]
Convert objects to path

Step 7-4: Generate G code


Goes to "Extensions" => "Laserengraver" and click "Laser...". A dialog box will jump up. You can select "Directory",
"Unites" and modify other preference under "Preference". Under "Laser", type the file name (should appended by .nc
extension). Then click "Apply".

[http://3.bp.blogspot.com/-727rmzJ_wu4/Uq011xLIjLI/AAAAAAAABzw/yNxNr4XAEJI/s1600/path_to_nc.png]
Convert the object to G code

A dialog box will say "laser working, please wait..".


funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

22/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

If "Draw additional graphics to debug engraving path" is checked under "Preferences" before clicking "Apply", Inkscape
will plot a lot of arrows on top of the plot, showing the moves given by the generated G code.

[http://4.bp.blogspot.com/-jUHkwHscDLU/Uq014PgIA8I/AAAAAAAABz4/6q_ezL10tpg/s1600/g_cde.png]
G code is successfully generated! A lot of arrows.

Step 7-5: Pass the G code to RPi


If you use a laptop/desktop to generate the G code, then you have to pass the G code to RPi using ssh or other tools.
The G code should be placed under the same folder together with the python routines.

Step 7-6: Make necessary modification to the python code and then engrave!
At least you want to change the G code file name in Gcode_executer.py [http://hostcode.sourceforge.net/view/1086] (line
25). Some other changes, say, pin numbers (line 29, 31, 32), resolution (line 35, 36), engraving speed (38), can be
changed if you understand them.
Type "sudo python Gcode_executer.py" in terminal to run the python routines and have fun!

Posted 20th October by Xiang Zhai


Labels: Unfinished
91

View comments

91 comments

Add a comment

Top comments

Xiang Zhai via Google+ 4 days ago - Shared publicly


Sorry that I just saw this... I bought laser housing on ebay for $5. And it includes a focusing lens. something
like this
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

23/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]
like this
http://www.ebay.com/itm/Laser-Module-Len-TO-5-9mm-Diode-12x30mm-Houseing-U-S-Seller-FastShipping-808-/251345536347?pt=LH_DefaultDomain_0&hash=item3a855c855b

Matthew Gingerich originally shared this


Oh, and I have a couple questions: Did you take the laser diode housing from the dvd drive, or
did you buy it somewhere? Does it contain a focusing lens?

1 Reply

Xiang Zhai via Google+ 4 days ago - Shared publicly


glad I can help:)
Matthew Gingerich originally shared this
This is the best tutorial on making a CNC that I've ever seen! Thank you so much for making it
so detailed and helpful. It helped me solve all the problems with running my own CNC off of a
Parallax Propeller.

+1
2
1

1 Reply

Xiang Zhai via Google+ 1 month ago - Shared publicly


+7
8
7

1 Reply

View all 4 replies


Xiang Zhai 3 weeks ago
+Nick Twigg
Sorry I haven't recorded any video yet.. The engraver cuts black paper fine with thickness similar to a
regular letter paper. I've also tried to cut paper cardboard, like the one for packaging. It did cut through at
a speed
Read
more
of about
(12 lines)
1in/min. For plastic board, I have to use black marker to paint the surface in order to
engrave. The laser burns the ink right away but after that it can't engrave any deeper. For woods, it
depends
on 3the
roughness
of the surface and the color. I tried a very soft wood, like the materials used
Xiang Zhai
weeks
ago
in
instant
chopstick.
The
laser
is able to cut through about 2mm thick at a speed of with 0.5in/min.
+Jamie M
You are right. 200 mW is not very powerful. But since I cracked down two DVD drives so I just went
Anyway,
the
laser
isdiode
not very
powerful.
you can
findcosts
a 405nm
diode
bluray
I saw
people
ahead and
used
the
inside
for free.Maybe
A 1W laser
diode
about
$40 for
now
as fardrive.
as I am
aware
of...
power
it
at
1W,
although
I
doubt
that
the
diode
lifetime
would
be
decreased.
Can you recommend me some places I can find relatively economic power laser? Thanks!

Chc Nguyn nh 1 week ago - Shared publicly


How to run pythong program?
1 Reply

Xiang Zhai 1 week ago +1


2
just copy those files I listed
above into your pi (either download directly on Pi or via ssh). Put those files
1
in the same folder. Then run the Gcode_executer.py routine by typing:
sudo python Gcode_executer.py
in terminal.
Chc Nguyn nh 1 week ago
thank you!

RaspberryPi Spy 3 weeks ago - Shared publicly


Raspberry Pi powered laser cutter using old DVD writers.
+53
4
3

1 Reply

View all 4 replies


James H 1 week ago
+Xiang Zhai
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

24/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]

+Xiang Zhai
Having a switch on the box opening could make sure the laser will only work when the box is closed.
Xiang Zhai 4 days ago
+James H
great idea!

Charlie Lehardy via Google+ 3 weeks ago - Shared publicly


Yet another project that I'd love to build myself but will probably never get around to... But it looks so cool!!
+2
3
2

1 Reply

View all 5 replies


Patrick Marcus 3 weeks ago
pretty cool. Well if you never get around to building one you can stop by Xerocraft and use their
engraver!
Xiang Zhai 3 weeks ago
Thanks for the interest. Actually once you get all the parts ready, it won't take more than a weekend to
build~

Chc Nguyn nh 3 weeks ago - Shared publicly


i can't find L9110S, which another same L9110S i can find
1 Reply

View all 3 replies


Chc Nguyn nh 3 weeks ago
thanks your answer
Chc Nguyn nh 4 hours ago
+Xiang Zhai
can i use this: http://www.ebay.co.uk/itm/L298N-Dual-H-Bridge-Stepper-Motor-Driver-Controller-BoardModule-Arduino-Ra-Pi-/130968976501?
pt=UK_BOI_Industrial_Automation_Control_ET&hash=item1e7e5bfc75

Star Rain via Google+ 3 weeks ago (edited) - Shared publicly


WoW @@
#RaspberryPi
+3
4
3

1 Reply

View all 5 replies


Infax Lai 3 weeks ago
tag
Translate
Star Rain 3 weeks ago

Translate

MikroVPS 3 weeks ago - Shared publicly


Mini lzergravroz kt rossz DVD rbl, egy Raspberry Pi-bl s 2000 forintnyi tovbbi alkatrszbl
Egyesek szerint a Raspberry Pi semmire sem val, pedig csak a kpzeletkkel van baj. gyes s kreatv
emberek szmtalan rdekes dolgot ksztettek mr az apr gp felhasznlsval. Xiang Zhai egyike
azoknak az embereknek, akik szeretnek hackelni. Xiang sztkapott kt rossz DVD rt, fogott egy
Raspbian-t futtat Raspberry Pi-t, rendelt az eBay-rl kevesebb mint 10 dollrnyi alkatrszt s sszelltott
funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

25/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]
Raspbian-t futtat Raspberry Pi-t, rendelt az eBay-rl kevesebb mint 10 dollrnyi alkatrszt s sszelltott
egy lzergravrozt.

Translate
1 Reply

Andrew Kroll 3 weeks ago - Shared publicly


I'll be using FETs instead of bipolar transistors. Otherwise, looks like something fun to play with :-)
+1
2
1

Yuji Naka 3 weeks ago


FETs are cheaper.
anne coleman 3 weeks ago
Andrew contact me need you to do something for me. Still trying to get out of Egypt

Liane Allen via Google+ 3 weeks ago - Shared publicly


http://funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html
+1
2
1

1 Reply

Andrew Nicholson 3 weeks ago +1


2
This has been making the rounds1today. I haven't checked it out, yet, but I will.

Rob Edlin 3 weeks ago - Shared publicly


"fun of DIY: A Raspberry Pi controlled mini CNC Laser engraver [keep updating]"
http://feedly.com/k/1exNpe7
+3
4
3

1 Reply

William Harrigan 3 weeks ago +1


2
Cool ..I have a laser engraver 1

Andy Taylor via Google+ 3 weeks ago - Shared publicly


Another job on the wish list...
+1
2
1

1 Reply

alex van via Google+ 2 weeks ago - Shared publicly


1 Reply

Jerome Labidurie via Google+ 3 weeks ago - Shared publicly


+1
2
1

1 Reply

CQD The Good via Google+ 3 weeks ago - Shared publicly


Xiang Zhai originally shared this

+2
3
2

1 Reply

Joye Lin via Google+ 3 weeks ago - Shared publicly


funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

26/27

23/12/13

A Raspberry Pi controlled mini CNC Laser engraver [last update Dec 18, 2013]
Joye Lin via Google+ 3 weeks ago - Shared publicly
1

Rostislav Stogov via Google+ 3 weeks ago - Shared publicly


1 Reply

Mari Thomas via Google+ 3 weeks ago - Shared publicly


RaspberryPi Spy originally shared this
Raspberry Pi powered laser cutter using old DVD writers.

+7
8
7

1 Reply

View all 7 replies


Mari Thomas 3 weeks ago +1
2
+Aaron Weathersby
1
oh i would love more pi's .. :D.. secret santa gave me one and i had one already :D.. what i need now is
time :P
Aaron Weathersby 3 weeks ago
+Mari Thomas I Understand there is never enough time.

Johnson Lin via Google+ 3 weeks ago - Shared publicly


DVD !
Xiang Zhai originally shared this

+1
2
1

1 Reply

Jedi Lin 3 weeks ago


BD @@"
Translate
3 weeks ago
(PS3

Show more

funofdiy.blogspot.co.uk/2013/10/a-raspberry-pi-controlled-mini-laser.html

27/27

Você também pode gostar