Page 1 of 21

Arduino based Laser Control

Posted: Thu Sep 04, 2014 3:17 pm
by ArtF
Hello All:

  This board is for questions, materials, code and suggestions involved with the Darwin/Mach4
Arduino based Laser Control panel. With Darwin now able to create laser engraving files and
with its requirement that an arduino laser controller be used, this board will contain my original
code and its evolution, along with ( hopefully) any users code suggestions and improvements.

Soon, I will start posting photo's, build suggestions and the code from the original laser panel
and we'll build from there.

What the hell is that you ask? :

    Darwin ( the printer port cnc driver for Mach4 ) has been released, and as of version 1.19 of it,
it can process grey scale images ( such as those made by Gearotic of Celtic knots) and from those
create mapping files so a fast laser system can engrave them with proper power levels. Darwin also creates
GCode files to match the power mapping files. But to do all this it needed more speed and power than a
printer port alone could offer. So a laser control panel was built with an eye to ease of use, creating and low cost
of owning one. The one I ended up with is made of wood, plexiglass and an inexpensive arduino. It connects to
a breakout board on 3 pins to provide the interface with Mach4 and Darwin. As such, its easy to make, inexpensive
and gives an amazing level of control over a DIY laser system while requiring no real knowledge of electronics and only basic
construction skills needed. In future many more cool effects could be done due to the way the power mapping is performed.
The following postings will detail the panel, provide videos and answer questions from those that would like to build
a panel or help the community improve on it, and perhaps we can all learn a lot about engraving techniques on
various materials at the same time. 


Art

Re: Arduino based Laser Control

Posted: Fri Sep 05, 2014 8:04 pm
by ArtF
Hello Everyone.

 So this thread is about a control panel for a laser. But more broadly its about ways to get signals
 from a printer port Mach4 to other devices for things youd like to experiment with. ITs probably best
 to go at this as a "This is the problem I had..and this is what I did" type of discussion as not everyone
 who reads this thread will be thinking of running a laser. An impact needle for engraving tombstones, or
 a unit to apply a known unit of glue to a particular spot, or even perhaps a UV diode to cure 3d liquids
 in various positions at various power may be your thing. All of these things have common features.
 
    My problem was simply to get laser power to a laser, but at the same time I had to control a very accurate
 tickle pulse, Perhaps software could have done it all, but it occured to me that these things called arduino's
 may be able to help and make the solution to my problem acceptable for other problems.
 
   I may as well admit now that this was my first arduino project, and my first arduino program. So dont expect
 any fancy programming skills to be shown. BUT, the fact I could code this arduino very quicky to do what its doing
 should clue you in that you could do such a project to use the same data for many other things. (Or just simply
 copy my code and build a laser panel..should you have a laser. :) )
 
  Here attached is a photo of an arduino leonardo. I use a Arduino Yun, which is basically a leonardo, but with
  a unix system attached running at 400mhz with wireless. I use that part only to allow me to program it wirelessly,
  you can use a normal leonardo if you dont mind having to plug in to usb to reprogram it. I like the fact I can just
  boot up a compiler and send updates to mine but if your not a programmer, than just usb is enough to program it from
  my files.
 
    A leonardo is about 20 bucks each. The total laser panel as I built mine, comprises
   
    1) Leonardo  : $21.00        (Yun: $79.00)
    2) 6 buttons : $2.00 total
    3) 1 led ring button for fire:  $2.00
    4) about 6 1k resistors          $1.00  ( 10k or even 100k resistors should work fine.)
    5) 4x20 LCD display              $6.00
    6) 5k pot for laser power control
    7) A box to put it in..
   
    I built my box from scrap wood, and used plexi on the front as a faceplate. So the whole things is worth about $30.00
    or so without wiress and around a hundred with. ( Although chinese Yun's on ebay are abotu 13.00 each.. dont know
    how they work..
   
      A leonardo is a 16mhz processor. Its pins are analogue, digital and in/out on pretty much all of them. You tell it
      the pins function as you program it. Some are limited to digital, others have PWM others are both, and some have interrupt
      capability.
     
   As I stated, this is my first Arduino project, so Im hopefull people will come along and help me make it better, over
   time perhaps Ill learn more arduino programming, but if a beginner can do it, so can you.
   
   Basic Theory of the device:
   
      OK, so I'm using a synrad laser. This laser is RF based and needs no water cooling or high voltage which is why Im
   using it. With modifications though this project will run a chineese laser or any laser. This laser , like most rf/co2 lasers
   needs a "tickle" pulse every 200us. You can damage the laser if you dont use this AND it has to be fairly accurate
   as if the pulse exceeds 3us, the laser will lase. It wants a 1us width. From 3us to 199us will give a power range of 0-100%
   of power output for that 200us period. High end Laser engravers like the epilog brand use these lasers using two main variables,
   they set power and frequency. SO you tell it for example to do 50%power at 4Khz. To understand this imagine you set 25% power
   at 2500hz, this means the laser should be given a 50us pulse every 400us. ( 1/4 power = 50us. and skipping the next 200us
   period gives you 2.5khz output. ). Its powerfull to combine these two variables. Instead of burning and charing plywood
   when you cut it, having the ability to use a set power at a lower frequency allows the spot to cool before being hit again
   thus reducing charing of material.
   
      Since all that was fairly new to me, I decided this panel I was building had to have a diagnostics mode where I could
   dial up a pulse count, power level, and set a frequency , and then, by pressing a flashing button I could shoot that
   exact amount of energy at that frequency to measure accurately laser's affects on various materials. This is all much
   too complex to do from a printer port accurately...so enter the arduino. Never having used one before, I had heard it should
   have enough power to do what I needed done. BUT , I really dont want to redo my breakout board on my robotic arm, so it
   was decided to build an arduino that simply hooked to 3 spots on the cnc's breakout baord. From those pins we'd make
   sure the tickle was accurate, and photos could be engraved as well as vectors..
   
  <End of Part 1>

Re: Arduino based Laser Control

Posted: Sat Sep 06, 2014 12:35 pm
by tweakie
Hi Art,

Excellent work.
Have a tremendous nice time on your holiday, please make a few notes whilst away so we can have Part II ... upon your return.  ;D  ;D

Tweakie.

Re: Arduino based Laser Control

Posted: Sat Sep 06, 2014 3:47 pm
by ArtF
Hi Tweak:

  I dont leave till later in the month.. so Ill be adding as much as I can till then. :)

Art

Re: Arduino based Laser Control

Posted: Sat Sep 06, 2014 5:19 pm
by Mooselake
You're awfully busy for a retired guy :)

Maybe in your spare time you could figure out how to use Tweakie's jet engine to build a really high power laser.

Kirk

Re: Arduino based Laser Control

Posted: Sat Sep 06, 2014 8:02 pm
by SkyMoBot
Am following this thread with a great deal of interest as I have a Epilog Summit laser engraver with a burnt out control board.  It uses the same Synrad laser tube that you all have.  I converted it over to use Gecko's and Mach3 for the motion control.  I have a modified version of Tweakie's control panel and I was just about to convert over to his version that uses the parallel port breakout board.

I tried getting an Arduino to output the tickle pulse and could never get the pulse down to under 4 msec,  I do a lot of laser cutting and being able to change the pulse width and speed on the fly would be very very handy.

Since you are doing low level parallel port stuff, why not have Darwin output the tickle pulse?

Regardless, whatever you get working, I'm bound to try and replicate.  I have a full time regular job and 4 kids so my free time is somewhat limited so I have to let you all do my experimentation.

Re: Arduino based Laser Control

Posted: Sat Sep 06, 2014 8:37 pm
by ArtF
Hi:

  Darwin is incapable of timing to the requirements of the laser. The Arduino though finds it trivial. It tickles with exactly 1us every 200us religiously, and each pulse is adjustable form 1 to 199us in 5000 discrete steps. Darwin uses only 100 steps of about 50 in that range. Darwin , as was mach3, was also limited in that it couldnt do pwm at 5khz, but had to use much lower.

  So this panel has 3 modes, diags mode where you manually shoot what you wish.. CNC mode where it accepts pwm and fires on each step, and NGrave where speed is also taken into account to stop charing or burning in corners, all things Darwin on its own cannot do.

  Now Im sure in the future Smoothsteppers and the like WILL do all that, but till then I needed it from a printer port,so the arduino was the obvious choice for tight control pulse to pulse..

Thx
Art

Re: Arduino based Laser Control

Posted: Sun Sep 07, 2014 12:05 am
by ArtF
Hi Guys:

  Here is a video on how the panel operates.

https://www.youtube.com/watch?v=o6MbP672xzY


Art

Re: Arduino based Laser Control

Posted: Sun Sep 07, 2014 10:42 pm
by ArtF
What the arduino does internally::

Well, as the video in the last post shows the panel itself,before building one we just need
to know what its doing internally. Let me point out that the point here is to make a device that can take
power and fire commands from mach4 with a time dependency that allows a laser or impactor or whatever
to do its job. There's a lot of microprocessors available to do that kind of thing, TI's launchpad,
Arduino's, beagleboards..etc, and I woudlnt rule out building another panel with another micro at
some point. Hopefully by that point more a few of us will be getting commands from Darwin.

  The software in the arduino isnt very complex, as my first arduino experiment you can imagine that
it wont be up to a knowledgable arduino programmers level. One of my hopes here is we attract such
people or we learn together how to do this better. Also worth noting is that while it was important
to me to have a diagnostics panel at the machine for testing and calibrating future engravings to the
material at hand, you may not want a diagnostics mode at all, and if so, just a simple arduino with
no box, buttons or LCD display would work fine, the program would simply require a bit of recoding
and you could hot glue the arduino into your cnc control box to permanently control your laser power
with no interaction. Point is.. there's lots of room for altering what we're doing here.

So.. that having been said, whatever controller we use,  (a leonardo in this case) has the
primary job of supplying PWM to the laser. Synrads require ( as do many others) a 5khz base
tickle frequency at 1us. The leonardo has a complex timer chip in it with envelope outputs, this allows
us to program that chip to do 5khz pwn with 1us pulses as tickles.

  To make any specific pulse longer than 1us ( up to the full 200us of the 5khz period..)
you simple change a register.  In our case thats OCR1A , a register that sets the duty
cycle of the pwm. this is all really hardware so its very accurate and controllable. 

So we then need to change it on the fly. SO I turned on an interrupt that the timer can generate
at the beginning of every period. In that interrupt call, we calculate based on current conditions
what length (duty cycle) this upcoming pulse should be. If we leave it at 1us, the laser will
not fire, but from 3.5us to 199us the laser will fire fully for that time frame. This then is what
we consider varying power, in reality the power is always at 100% but at varying lengths of time.

As the video shows,I didnt want the laser to fire all the time. SO a second interrupt is hooked up
to the StepFlag output of Darwin which gives a pulse whenever a step pulse is put out to any motor.
We have then, two interrupts going on so far, a timer interrupt that triggers at the start of each pwm
pulse, and a Step interrupt that happens whenever a step is taken. Now the diag mode has a fire button
which when pressed fires off a set number of pulses depending on what one selects for count.
So in NGrave mode, the interrupt on the step flag reloads the pulse count( usually set at one) and
internally presses the button. This makes it fire one pulse. As the CNC unit moves, each pulse
resets the counter to its setpoint and tells it to fire. The laser fires once and does nothing until the
next step pulse. Youd set higher pulse count numbers to cut materials and can use frequency and pulse count
settings on the panel to control charring or overburn in various materials.

  So that leaves us with just needing a way to get the power of each shot. For that Darwin now has a clock
and a data output. When Darwin sees your in Laser mode, it will constantly send a stream of power
data, if the spindle is off it sends zero's.. if spindle is on it sends the last SWord.. ( 0-100%),
and if a photo is linked to Darwin, it sends the grey scale of the photo point in the spot
the axis is at currently..otherwise zero. The Data clock runs at full kernal speed, so 30khz on my system,
so to be sure the arduino doesnt miss it, it uses another interrupt. This means we have 3 interrupts
running constantly in the arduino to sync output to whatever Darwin is doing. This leaves most of the
complexity on the PC side in Darwin. If not doing a photo, Darwin calculates a TOF(Time of flight)
for your vector line, calculating a power level for each set of steps to maintain a level amount of power
throughout your motions.

  So thats it really, not very complex, and from a programming standpoint not very hard to implement
  so far. Ive cut many photo's and each is an interesting lesson in power vs speed vs output. :)
 
  Ill post the arduino code here later this week, Im happy to help as well if anyone has questions
  about how this all works, or has ideas for other ways to make it all work better.
 
 
  Art

Re: Arduino based Laser Control

Posted: Mon Sep 08, 2014 4:15 am
by SkyMoBot
That makes a lot more sense to me now.    I never did more than a set of digitalOn/DigitalOff and sleep for a few us to get the pulse.  I never fooled around with the OCR1A register.

How about posting a snippet of code that does just the tickle so I can try it for myself while I wait for the rest of it?