Archive for the 'Laser' Category

Pololu Compatible Relay Driver

I just got my production boards for my Pololu compatible relay driver. This is a little plug in module that can be used to drive off board relays. It uses the signals that are normally used for step and direction to control two relays with the voltage that is normally used to power motors.

Pololu stepper drivers are great little items.  They are inexpensive and very easy to use.  You only need a step and direction signal to control them.  If you use them in sockets, as I show here, they are portable between projects and experiments.  If you accidentally smoke one, you only need to replace the single driver.

There are a lot of carrier boards for these.  There are Arduino shields and many other applications.  Often, it would be nice to be able to drive a larger external load like a spindle or blower.  You can then use the existing step and direction signals to drive the relays.  It uses the voltage normally used to drive the motors for the coil voltage.  The only wiring required is two wires to the relay.

I chose to put the relays off board because the real estate was pretty limited and I wanted to provide the voltage isolation for AC powered devices. I am also a big fan of DIN rail mounted relays. They are very reliable and inexpensive. They are easy to swap around and have some nice features. The relays shown have a LED indicator and also a manually test button that moves the contacts. The relays shown are about $10 each, including the DIN rail sockets.

I got the boards from Gold Phoenix in 2 sheets of 50. They were not cut out, only V scored. Fortunately I have access to a depanelizer at work and was able to easily separate them. I probably could have snapped them apart too. The depanelizer looks similar to this one. Two slowly spinning sharp disks chop them apart.

The boards have all the components required to drive the relay including a supression diode. I am using a pretty hefty transistor here, but you could substitute a smaller one.

Schematic (PDF)

Gerber Files

DIY Solder Stencil on a DIY Laser

We use a lot of solder stencils where I work (during the day).  We usually buy stainless steel framed stencils for about $300 each.  For prototyping we usually hand paste each pad.  We have an semi-automated dispenser, but it is still tedious work.  I see several places like Pololu selling low cost mylar solder stencils.  I wondered if my 2.x home made laser cutter could do it.

I researched a few blogs and pulled some information from Pololu.  Pololu sells 3mil and 4mil mylar stencils and recommended 3mil for fine pitch work.  I decided to buy the 3 mil mylar.  I picked it up on my way home from McMaster Carr.  It was a life time supply for about $15.

I found a bunch of old small SMT PCBs that I could play with.  I got the top side paste mask  gerber file for it.  I imported the file into a Gerber tool called ViewMate from Pentalogix.  This is a great program that I have be using for years.  A partially disabled version is free.  I have found that it has plenty of useful features.


Most PCB layout software has layers for the solder stencil.  There are industry standards (IPC) for the size of these pads, but they are generally a little smaller than the pad.  Often large pads, like thermal pads under big power ICs are divided into smaller windows or dots.  This prevents excess solder from causing problems.   With this in mind you probably need to shrink the pads even further to deal with the kerf of the laser.

ViewMate has a nice feature that allows you to shrink the apertures.   Apertures are a somewhat archaic term from when artworks were done optically on film.  They basically mean the shapes.  To use this feature select the Setup…D Codes menus.


Select all the shapes in the list and select the Operations…Swell menus.

Enter a negative value to shrink the shapes.

I then printed 1:1 to a PDF.

ViewMate has a lot of export options, but most of them are not available in the free version.  PDF is fine for what I needed to do.  I then imported the PDF into Corel.  I cleaned up a few extra lines and text in Corel and moved it over near the origin.

If you were always going to make your own stencils,  you could probably skip a few of these steps by defining your stencils layers with the right values.  Pololu actually shrinks it differently in X than Y for even better performance.  Many CAD programs could print straight to PDF or other formats then.

Corel is a front end for my DSP laser software, so I was ready to try making the stencil.  The PDF has vector information so you could cut it or engrave it.  Everyone seems to recommend engraving, so I gave that a try.

I was not sure what to put the mylar on.   I decided to hang it in the air.  I taped inside a wooden frame.  I tried different power levels and speeds and looked for my best result.  I onlt tried about 3 settings combinations before I ran out room.  I looked closely and they all looked pretty good.  I think I got the best at 200mm/s and about 60% power.  The power was not too much of an issue.  It seemed better to cut it with more power than it need.  It tended not to heat the surrounding area.  The step over was 0.15mm.  That probably could have been smaller for more accuracy.   There was a slight smoky haze after cutting that I rinsed off with water.

It matched up perfectly with the PCB.





Open Source 4 Axis Stepper Driver

This is a new 4 axis stepper driver board for use in laser cutter/engravers and general CNC.  Below are the basic features

  • Socket mounted stepper drivers
  • Integral cooling fan with power connection.
  • On board 5V Power supply.
  • Rotary switch selectable microstep resolution (Full,2x,4x,8x,16x).
  • Control connection via terminal blocks or 25 pin ‘D’ connector.
  • Filtering on all step and direction signals.
  • Motor disable/enable feature through ‘D’ connector or external switch connected to terminal block.
Socket Mounted Stepper Drivers
The board uses low cost socket mounted stepper drivers.  These can be Pololu A4983/A4988 drivers or open source Step Stick drivers.  These are easily replaced if ever damaged without any rework to the PCB.  A compatible relay driver is planned that also fits this socket.  This will allow up to (2) relays to be controlled per board.  These are controlled via the set and direction pins associated with that axis and uses the existing terminal blocks for that axis.  This is perfect for a spindle on a CNC router or assist air on a laser cutter.
Cooling Fan
There is an integral cooling fan for the stepper drivers.  It mounts directly to the board and has a dedicated power connection.  It is mounted high enough to allow heatsinks to be mounted to the drivers.  This will allow the drivers to run at their full potential of 2 amps per coil.
5V Power Supply
There is a 1 amp 5V switching power supply on board.  This will not get hot like a linear regulator due to the voltage drop from the motor supply.  This can optionally be 3.3V if your controller requires that.  All other items on the board are 5V – 3.3V compatible.
Rotary Switch Resolution Selection.
The resolution of the drivers can be independently set via rotary switches.  The resolution is selectable between full step, 2x, 4x, 8x and 16x microstepping.  These and the control connector are flush mounted to one side for easy bulkhead mounting.
Control Connector.
The board has a dual pattern for the control connector.  There is a pattern for standard 5mm pitch terminal blocks and a pattern for a ‘D’ 25 pin male connector.  The ‘D’ connector has a standard pinout for direct PC connection for Mach3 or EMC.  The terminal block is perfect for direct connection to laser controllers like the Thunderlaser DSP controller or an Arduino microcontroller.
All step and direction signals are filtered with a RC filter and a schmitt trigger.  This is ideal for a noisy environment like a laser cutter or CNC machine.  The RC filter frequency is high enough to allow 1uS pulse control of the drivers.
Motor Enable/Disable
You can enable or disable the motors via the ‘D’ connector or via an external switch connected to a terminal block.  This can allow hot motors to cool off or allow you to manually rotate them.
Interface Drawing (coming soon)
3D Model (coming soon)
User Guide
There are a limited quantity available for immediate purchase
$40 assembled and tested with fan and mating connectors.
$90 with (4) drivers and heatsinks.

If you would like to comment, please use the forum topic for this post.

Using a ShuttlePro as a Laser Pendant

I have been using a ShuttlePro as a pendant for years on my router.  A pendant is basically a hand held remote control for your CNC.  It allows you to control a set of functions right at the machine.  I typically use it to zero the machine on the part, tweak the feedrate, start/pause/restart the job and do an e-stop.

The router’s pendant is starting to die.  It has been through hell.  I have dropped it about 10 times on the concrete floor.  It has also seen a lot of oil and fine dust.  A couple buttons are getting intermittent.  I have the functions to working buttons, but I was getting worried it would stop working completely.  I could not live without it, so wanted to get a replacement on order.  I found a good deal on eBay ($54) and since they had several, I decided to get one for the laser as well.

The ShuttlePro was designed for video editing.  One thing you do a lot in video editing is jogging the video forward and backward.  Typically you want to race forward until you get close then slow down and even go frame by frame until you get to the desired spot.  Sounds like CNC doesn’t it?  It has three dedicated functions for this.  Full speed forward and back via buttons, variable speed via a spring loaded jog dial and a frame by frame little detented rotator wheel.  It also has a lot of redefinable buttons.  These buttons have clear snap on caps, so you can add labels to them.  I have a Corel and PDF template at the end of the post.  Someone at the Mach3 forum dicovered this product and within days there was a plugin for it.

Setting it up is easy.

Download the ShuttlePro plugin from the Mach3 downloads page.  Place the ShuttlePro.m3p file you download in a convenient place like your desktop.  Double click on it.  That will launch a program that registers it with Mach3.  Plug in the ShuttlePro into your computer.  It uses the built in Human Interface Driverss (HID) so you do not need to install a driver.  It comes with some software to test it, but you must uninstall it before using Mach3.  Start Mach3.

Use the config Plugins menu pick to open the

Make sure the plugin is enabled with a green check.  Now click on the word config to the right of the plugin name.

That will bring up the screen above.  Each button can be associated with any of many functions.  My config is shown above.  You probably want some keys across the top to select the current axis.  I like to have the two buttons to the outside of the central wheels be rapid movement buttons.  It is also handy to be able to lock the pendant so accidental button pushes do not screw up a run.   I used the second button from the lower right.  The rest are up to you and how you use your laser.

Below is a video demonstration on my laser.

Open Source Rotational Engraving Adapter (Part 1)

This is the new open source rotational adapter for laser engraving.  This allows you to engrave on a round surface.  This design uses a friction drive method to rotate the workpiece.  This has the advantage of keeping a consistent surface resolution regardless of diameter.  This was designed to be 1000 steps/inch resolution.  The length was sized to fit the 2.x laser, but you could easily scale it up to much longer or shorter.  One design goal was absolute minimum height.  This allows Z challenged engravers to be able to do some rotational engraving

The main feature of the design is the the two drive wheels.  These serve several functions.  They hold the rubber o-rings used to provide traction on the work piece.  They have built in MXL drive pulleys and they have a spacer to ride directly on the bearings.  These were 3D printed at Ponoko.  With 3D printing, complexity is free.   This encourages you to make the part do as many jobs as possible.  I was initially concerned about the strength of these, but they turned out to be quite strong.  I can probably reduce the material to take some cost out.  I used the basic, cheapest, white flexible material.  I was impressed with the detail level the material was able to hold.  The belt fit perfectly.

I started the design using convensional design techniques and off the shelf parts because I was concerned about the 3D printed part cost.  I soon realized that it was going to take 3-4 separate parts to do the job of one 3D printed part.  The cost was quickly getting close to even.  The convensional parts were also starting to look a little mismatched.  While I am a form follows function, type of designer, I am a big fan of a clean design.
Once I started playing with the 3D printed part approach, I quickly decided that was the route to take.  It was fun knowing that increaing the details on the part has no affect on the cost and in some cases actually reduces the cost.  The spokes and radiuses retain the strength, reduce the material and I think add a retro mechanical design asthetic.  Dealing with a single supplier, with a fast turn around and no minimum order, was very nice.
I have done 3D printing from other vendors, but decided to give Ponoko a try on this part.  Since this is an open source project, their online tools would allow others to easily order parts.

At the other end of the assembly are the idler wheels.  These also are Ponoko 3D printed items.  They have bearings that press on each side.  This allows them to roll freely with virtually no wobble.  One idler has a flange on it.  This acts as an end stop to the workpiece.  It prevents it from “walking” while it is spinning.  The stepper motor pulley serves the same function on the other end.  This end is highly adjustable.  There are three positions the wheels can be placed in.  The plate can slide on the extrusions and you can flip it over.  While all the adjustments are manual, they only take a few seconds to do.

Below is a video of some testing I did.  I was trying to test a variety of shapes to see how they performed.  In actual use the speed is very slow, because the the laser is primarily rastering along the length of the workpiece and this adapter just advances it a faction of millimeter at a time.

They all performed quite well.  The only item that did not test well was a roll of duct tape (not shown).  It was not very round so it wobbled a bit.  It also has a sticky edge so it did not ride against the stops real well.  The screwdriver at the end is an interesting example.  While it did spin smoothly, it shows that if the image is not going to be at the same diameter as the drive area, some image scaling will be required before engraving.  The bit is only 1/8″ diameter!

The design will be open source.  There are a few tweaks to make before I release the drawings and 3D files.  I may sell a complete kit for this.  I estimate it will cost less than $100 with motor and extrusions included.  I have not tested it in my laser yet.  I don’t have the time right now, so I am going to have another 2.x laser owner do that for me….stay tuned for part 2.

Items Shown in video

  • Drumstick
  • Beer Bottle
  • Odd Shaped Oil Can (remove oil before lasering)
  • Wine Glass
  • Tiny Screwdriver

View Assembly Drawing
 View Plastic Parts
 Bill Of Materials
 Assembly Instructions

Laser Interface/Driver PCB

This a the new Laser Interface PCB.  It adds a lot of new features including the stepper motor drivers.   This board is designed to reduce the wiring requirement of a home build laser cutter/engraver.  This should significantly reduce the cost of a laser cutter.  If you use this with EMC2 (free) you should be controlling your laser for less than $100. There is a video at the end of the post.

Controller Connector

This is a standard 25 pin ‘D’ connector.  The pinout is compatible with PC control (Mach3, EMC2) or the FSE Retina Engrave controller.

Stepper motor Drivers

The PCB provides three slots for Pololu stepper motors drivers.  It can use the A4983 or the A4988 stepper drivers.  The PCB provides the logic power so you use the cheaper versions of the boards.   These drivers can provide up to 2amps of power at resolutions up to 1/16 step.  The microstep mode is easily adjustable through rotary DIP switches.  These are placed along the edge with the control connector so they can be made accessible through the enclosure wall.   If you ever blow a driver, you can simply replace the broken one.  There is a built in fan to cool the drivers that cools them to within a few degrees of the ambient temperature.

Safety Loop

The board creates a safety loop of switches to protect the user and laser tube.  The loop runs through the emergency stop button, the cover switch and the water flow switch.  If any of these items are are not in the run position or if there is a break in the loop, the laser tube cannot be enabled.

Laser Power Control

The board allows two different laser power control modes.  The default mode is via a remotely located manual potentiometer.  This is usually mounted on the front panel.  You can also use a switch to change to PWM mode.   This allows an external controller to provide a digital PWM power level control.  This switch would be located on the front panel.  The PWM signal can be configured to use pin 14 or pin 15 on the 25 pin connector.

Dual Relay Drivers

The board has two high current MOSFETs that can be used to drive external relays.  these are controlled via pins 1 and 8 on the 25 pin control connector.  These are typically used to control assist air and exhaust blowers.  They can easily be configured through Mach3 or EMC and G-Code as if they were mist and flood coolant devices.

Laser Power Supply Connector

There is a direct 1:1 connection to standard laser power supplies.  The board takes car of connecting all the grounds and safety interlocks.

Water Switch

There is a three pin terminal block to connect to the water switch.  The switch can be a simple mechanical switch, plus there is a 5V power source to use if you want to power a more complex water monitor.

Enclosure Connections

There is a connector dedicated to the enclosure connections for the limit switches and cover interlock.  The board provides the pull up resistors for these items so they can be wired in a mode where a break in the wiring would trigger signal an open circuit.  The pull up value can be either 5V or 3.3V.

User Guide 2.x Laser

The second generation open source laser cutter/engraver design from is complete.  The new machine is called the 2.x Laser.   The name comes from the fact that this is the second generation machine and it is basically a 2 axis design.  The third, vertical axis, is manually controlled with an optional upgrade to digital control.  The 2.x Laser takes all the optimizations learned from the first laser and all the other lasers documented on forum.
The usable work envelope is just under 12” x 20” x 4”.  The internal design has been optimized so the overall size of the machine is much smaller than the previous design and can easily fit on a small table.  It is designed to work with 40W CO2 lasers sealed gas lasers.  The frame is built from inexpensive 20mm aluminum T Slot extrusions and the skin is made from a painted aluminum and HDPE laminate.
The first major improvement is in the linear bearing system.  The 2.x Laser uses Delrin V groove wheels running on V rails.  The custom Delrin bearings are a lot cheaper and run smoother and quieter than the previous metal on metal system.
The next major improvement is in the electronics layout.  All the primary electronic systems are contained in a simple electronics module.  This has an interface PCB that makes wiring a simple 1:1 connection for each item.  The module is removable so all assembly can be done outside the enclosure.  The electronics are compatible with 3.3V or 5V control systems whether they are PC based like EMC2 or Mach3 or dedicated commercial or open source controllers.
The original laser attempted to be self replicating with regards to most of the fabricated parts.  That limited the materials that could be used.  The 2.x Laser drops that goal and concentrates on a more robust design with stronger metal parts.  Shimming, drilling and tapping fragile parts is no longer required.  The rest of the design was simplified wherever possible.  There are less parts and many of the parts self align.

The design is completely open source with all drawings, schematics, BOMs (with sources and prices), 3D models, build instructions, software and Gerber files available.  There are kits for anything that is not readily available for people who cannot fabricate their own.  Due to the smaller size, the enclosure skins can now be fabricated on smaller home routers or can be purchased as a kit.

The design is supported by a robust community of laser builders and users at the forum.

Drawings Page

Bill Of Materials Page

Kits Page

Pimp My Laser

After working like mad for several days to release the 2.x Laser, I decided to take a break and have some fun.  I thought it would be fun to add some interior lighting to the laser.  It is not really necessary if the room is at all bright because the top is so big and clear, but I thought it would be fun.

I searched around some PC case mod sites for a while, but was not sure what would work right.  They fall into two categories: LED and Cold Cathode (CCFL) lights and virtually all of them run on 12V.  I use 24V, so I had to deal with that.

I had few negative issues with CCLF.  Most have a big power supply thing that is probably very noisy and I was not sure how happy they would be to run in series to deal with the 24V.  I decided LED were very flexible and very clean.

I was not happy with the stuff I found on line, so I ran off to Micro Center.  They only had one LED strip that was white.  Frys is just down the road, so I went there.  They did not have any white LED strips.  I decided to check their lighting section and found what looked to be a perfect solution.  It is made by Trend Sources Inc, but I could not find much on line about them.  I paid about $19.

This is a two pack 12V flexible LED strip.  It looks like a flex circuit with a molded silicone boot over it.  It just so happens that it can be pushed into a 20mm Misumi extrusion.  You need to gentry work it in, but it is not coming out on it’s own.

I fired up one strip, then 2 in series.  They worked perfectly and quite bright.  I pushed them into the extrusion the is located right behind the cover hinge.  I hid the wires using Misumi slot cover material and wired it over to the central 24V supply.

It looks great.  The LEDs stick out about 1/8″, but you really don’t see the individual LEDs until you look at a low angle.  The camera is actually held inside the laser, below the level of the cover here.   This only shows one of the strips.  I separated them by about 2.5 inches.

Using Vectric Cut2D With A Laser

Cut2D is 2D CAM program from Vectric.  It is designed to quickly and easily import DXF plus several other vector formats and create G Code for CNC cutting.  It is primarily designed for traditional mills and routers.  While I would not recommend purchasing it to only use on a laser,  people who have both a CNC router and a DIY laser will find this to be a very capable and inexpensive product.

I have used Vectric products for years.  I started with VCarve, then upgraded to Aspire.   A forum member recently asked for help using Cut2D.  Vectric was gracious enough to give me free evaluation copy.  This is probably due to the fact that I already own their top of the line product.  They did say that they are not really interested in selling it for laser use only because the program may be confusing to them and they only want 100% satisfied customers.

The Vectric products ship with 100+ pre-made post processors.  There are several flavors of Mach3 post processors that will work right out of the box for most mills and routers.  It is also very easy to customize your own post processor.  I created one for Aspire last year and found that it worked perfectly for Cut2D as well.  I wrote a blog post about it and the file is available here.  All Z movement is removed from the post processor, so the actual Z values used below are not going to affect your machine while cutting.

I am not going to explain how to use Cut2d.  Vectric does a great job of that.  I will just explain the differences when using a laser cutter.

Creating a Laser Tool

The first step is to setup a “tool” in the tool library for the laser beam.  The beam can be thought of as an end mill.  It is basically a cutting cylinder with a fixed width.  The major difference is that it has an “infinite” depth of cut.  In reality most lasers are not going to cut anything thicker than an inch or so due to beam divergence.

Many values you set are just default values and can be changed when you use the tool for a cut.

Tool Name

I called my tool “Laser Beam 0.003”.  If you want to go crazy, you could setup dozens of tools with default values that work well with certain materials.  You could name the tools “1/8 Plywood laser cut” or “6mm Acrylic laser cut”, for example.  This way you do not need to remember what speeds and feeds are needed for each material.

Tool Diameter

Cut2D will use this when calculating how much to offset the cut line from the geometry when cutting inside or outside features.  An easy way to determine this is to cut out a 1 inch square on the geometry lines with no offsets.  Measure the actual size of the part.  The amount you are less than the inch will give you the beam diameter.  If you want to be as accurate as possible, you could define multiple tools based on different materials and thicknesses.

Pass Depth.

You cannot realistically use Cut2D to control the depth of a laser cut.  Therefore, this value is not important.  You do want to make sure this value is larger than any value that you will use when specifying tool paths so the cut is always one pass.  I suggest setting this to a value of 1 inch.  This default value can always be changed when you are setting up a toolpath if you actually want to play games with multiple passes.


This does not apply for lasers, because we will not be doing pocketing.  Just set it for 45% to keep Cut2D happy.

Spindle Speed

This value is also not really important at this point.  You could use it to control beam power if your laser supports that.  If your laser can use this for beam power then set it for the number that would yield max power, otherwise a value of 1000 should be fine.

Feed Rate

Again, this is a default number that can be changed at each tool path, so pick number that is close to t typical number you might use.

Plunge Rate

This does not apply so just put in any reasonable value.

Here is what a typical laser might look like.


I will explain one cut using the wing_spar example file that comes with Cut2D.  The cut will be the inside features of the wing spar.

Select all the inside features and then click the Create Profile Toolpath icon on the toolpaths flyout menu on the right.

Cutting Depths.

These values do not matter.  You just want to make sure the cut depth is less than the pass depth set for the tool.  This will insure that only one pass is done.  Advanced user could of course use this to setup multiple passes.


This is where you select your laser tool.  Use the edit button to set the actual cutting speed you want.

Machine Vectors.

Use this to tell Cut2D what side you want the tool offset to.  The direction setting (climb or conventional) is primarily for spinning tools, like end mills, but if you care which way the cut goes around the loop, you can change this.

Ramp moves

Don’t use this.


Tabs are primarily used to keep parts in place with spinnig tools, but you might want to take advantage of it to keep light parts from blowing around, or if you want all the parts to stay on the material after cutting.

Outputting the G Code file.

The last step is to output the file using the custom laser post processor.  A copy of the file is available here.

Good luck.  You might want to try a few dry runs with the laser disabled and you hand on the e stop button to make sure it works for you.

Modbus, Arduino, Mach3 and Brains..oh my

Laser power control via modbus.

Mach3 is a great program.  People have used it to control a vast diversity of machine, but it has some issues when controlling lasers.  This is especially true when it comes to the beam control.

The beam can be compared to the spindle of a mill.  It does the cutting and has an on/off state and power level (like RPM).  On a mill, the spindle can safely stay on during rapid moves above the work and dwell at points without issue.  A laser cannot do that because it does not retract from the material.  It must only be on during G1 feed moves and must not dwell at any point or excessive burning will occur.  The normal spindle logic does not work well with lasers.

I thought it would be a fun experiment to try to enhance the control using a Modbus slave device.  Modbus devices are basically remote device that allow a host to read and write data registers.  The remote device can then use the data registers to give information to the host or do a task when a register is written to by the host.  The devices typically communicate using a serial port or Ethernet.  You can view the Modbus protocol here.

There are a lot of commercial Modbus devices like ModIO and the Automation Direct PLCs, but I wanted a cheaper home grown version.  I thought an Arduino would be a good choice because it has a built in USB to serial port, it is less cheap (less than $20) and it is open source.

My first task was to see if an existing Modbus library existed.  I found a extremely well written and documented one by Juan Pablo Zometa written here.  I read the code and determined that I could start by testing it as is without changing anything.  I would setup Mach3 to match the port settings and try to read and write to the default memory register setting.  I loaded the program into my Arduino Duemilanove.
Setting up Mach3 Modbus

I created a new Mach3 profile by cloning an existing working profile.  Modbus is turned on via the Ports and Pins dialog.  Check the Modbus dialog.  Skip the second check box for now.  I used the simpler old Modbus plug in

I needed to restart Mach3 to make the changes available.  Next, go to the plugin dialog.  Setup the serial ports to match the Arduino settings.

Now try to read from the Arduino using the Test Modbus button.  The arduino starts at register 1  and initially has only 1 register.

Setup the Comm Port setting per above, but don’t bother with anything else.  We will manually test the Modbus now.

I set the Slave Addr to 1 the Start to 1 and the Num Regs to 1.  I clicked read and got 0000 with no errors.  All registers are 16 bit integers and by default they are displayed in hex format.  I changed 0000 to 1100 and clicked Write.  I then cleared the number and clicked Read.  I got 1100 back.  This meant both read and write were working.
Modifying the Arduino code.

I changed some Arduino code to allow more registers by adding “ = 6” after MB_REGS.

enum {
MB_REGS = 6   /* total number of registers on slave */

Now I was able to read and write multiple registers.  To have a little more fun a wrote a function that runs every time a write command was received.  One register toggled an LED and the other set the value of a PWM.  That worked perfectly.

Automating the Modbus

That is all cool and fun, but manual control is not gaining us much.  Now it is time to put Mach3 in automatic control of it.  To do this we will write a macro that is triggered from G-Code.  I wrote a macro the would run whenever Mach3 encountered a special bit of G-Code.  I chose to use an M666 code.  I would use that with a “P” parameter for the PWM value.  So “M166 P50” would set the PWM value to 50.

The code is very simple.  It reads the parameter.  Param1() always gets “P” parameters.  It then sends the value out via the second register in the slave Modbus device.

Edit the post processor
The next task is to create a post processor to create the custom G-Code.  I used Vectric Cut2D as my CAM program for this exercise.
First I setup the spindle speed to output as Pxxxx.  The + sign comments out the original post processor line.

The next change is to add the new M666 line before each first feed move to set the power level.

“[N]M666 [S]”

Next steps

The next step is to use a Mach3 feature called “Brains”.  This is a ladder logic type programming method that works much faster than macros and can run in parallel with Mach3.  This can allow some really interesting ideas.

Possible Future Ideas.

  • Tie power level to feed rate.  When a move starts out it accelerates to the desired feed rate.  Therefore the power per speed is not constant.  A Brain could adjust for this.
  • Control beam enable on with “is move G1” logic.  Rather than using the E1P1 method common with many laser users, you could have a Brain toggle the beam on whenever the code is in a G1 move.
  • Return water temp to Mach3.  The Arduino could read water temp and Mach3 could display it on in a DRO.  Mach3 could act on a high temperature value and do a feed hold and turn off the beam.
  • LCD display.  The Arduino could control a simple LCD display of feed rates, power levels, axes positions.
  • Jog buttons.  A simple jog button panel could be implemented.
  • Feed rate offset.  A pot could be used to adjust the feed rate plus or minus while the job is running.
  • Feed hold with beam off:  A feed hold button could be implemented where the motion stop and the beam goes off at the same time.