Laser power control using Mach 3 Light burn vs Inkscape

I have been using LightBurn for a few years now to cut wood veneers. It works great for this as I usually run the laser at 100% power. Recently I started an engraving project that requires some different power settings. I am now realizing that I am unable to change the power setting in when I use code generated by LightBurn. I use the GRBL M3 1.1 set up in Lightburn and modify the code with scripts to change M3/M5 to M11Px Sx and M10 Px.

If I generate code with Inkscape I can adjust power easily.

When I compare the M11Px Sx and M10Px code generated by the 2 different program they look identical. But something is preventing the lightburn code from controlling power.

I know LightBurn is not really meant for Mach 3 machines but I have been fairly successful with it…I guess as long as I want it to fire at 100%. But not being able to change the Sx commands is very limiting. I work around this to some degree by changing feed speed but that is also quite limited, the lines get shaky due to vibration when moving very fast on my machine, 3000-4500 mm/min. 1000-2000 looks quite good but I’d still like to be able to control power in LightBurn.

modified light burn code to use M11Px Sx and M10 Px

; GRBL-M11P2 S5 (1.1e or earlier) device profile, user origin
; Bounds: X103.37 Y2308.74 to X125.98 Y2326.4
G00 G17 G40 G21 G54
G90
G0 X0 Y0
G91
; Cut @ 1000 mm/min, 10% power
M5
M10P2
G0 X-18.811Y17.664
; Layer engraved flakes
M11P2 S5
G1 X-2.185Y-1.319S10F1000
G1 Y-3.21
G1 X-1.612
G1 Y-1.709
G1 X1.612
G1 Y-7.459
G1 Y-0.473

InkScape Laser tools code

;Inkscape Lasertools G-code
;GitHub - ChrisWag91/Inkscape-Lasertools-Plugin: A simple plugin to convert inkscape vector graphics to Gcode for DIY laser engravers

G90 ;Absolute programming
G21 ;Programming in millimeters (mm)
M03 S1 ;Activate laser and set power to 0 (CUSTOM)

; START perimeter strategy
G01 F2000.0
M10 P2
G00 X59.19 Y162.39 F2000.0
M11P2 S5 F2000.0
G01 X58.59 Y162.27 F2000.0
G01 X58.02 Y162.22 F2000.0
G01 X57.24 Y162.34 F2000.0

Does anyone have any ideas?

1 Like

Perhaps the M3 is required?

1 Like

I may try using that header in the LightBurn code and see what happens… Thanks for the suggestion.

I found part of the solution. When I take the raw M3 GRBL Lightburn code, load it in Mach 3 and then edit the code within mach3 the power level works perfectly.

This edit is a find>replace and replace all edit changing M3 to M11Px Sxx and M5 to M10Px. Then changing the M9 code to M5.

This takes the Lightburn code and allows mach3 to control power levels. I’m still now sure why my scripted edits don’t work for power level changes, it’s the same code….hmmm more research but getting closer.

1 Like

Today I am not able to recreate what I saw yesterday. I even had ChatGPT analyse code from Lightburn and code from Inkscape. There is essentially no difference in the codes except that the Inkscape code works with S commands but the Lightburn code does not.

Stumped

More progress:

I have found out that the GRBL-M3 profile is set to provide constant power. This is likely the cause of not having any control over my laser power. If I enter S0 it fires at 100%, I would imagine that if I deleted the S command it would still fire at 100%

I have been experimenting with the various GRBL versions.

If I manually add my code of M11P2 S10 I can get the regular GRBL and GRBL LCP and GRBL STM to fire at 10% power or any other S value. But what I can not do is get it to turn off for jogging between cuts/engraving. I have tried adding M10P2 before/after any G0 movement but I can not get it to turn off while jogging like I can with GRBL-M3

I have also found that if I enable constant power in the GRBL profile it will fire at the specified S value as long as I add the M11P2 command to the code but it still will not turn off between cuts/engraving sections.

GRBL-M3 works great if I am cutting the thin veneers that I use for my skis but if I want to engrave those veneers I have to crank up the feed rate so it doesn’t cut through which decreases the quality of the engraving by causing vibration of the laser unit.

But I seem o be getting closer to a solution with being able to use one of the other GRBL profiles. I’ll keep playing with it maybe I can figure it out.

If anyone has any ideas please share. I know this is not a straight forward problem. Everything about my system is a workaround and very unique to my set up. But if you have any ideas please share, you might just be the solution to my problem.

1 Like

More research,

After really looking at the code generated by the various GRBL profiles, it seems like M4 allows for variable power.

Could this be as simple as adding an single M4 command in the header for the code like this?

; LightBurn 1.4.01
; GRBL-M4 (1.1e or earlier) device profile, user origin
; Bounds: X263.72 Y734.27 to X297.48 Y747.13
G00 G17 G40 G21 G54
G90
G0 X0 Y0
G91
M4
; Cut @ 1000 mm/min, 10% power
M10P2
G0 X13.837Y0
; Layer inlay pockets
M11P2 S10
G1 X-1.338Y-0.526 S10 F1000
G1 Y-2.686
G1 X-1.643Y-0.452
G1 Y-0.35

I’ll test this later, after having some success earlier with GRBL, GRBL STM and GRBL LPC being able generate code that Sxx commands are not ignored by Mach3, this seems like it is worth testing

1 Like

Constant power does not mean lack of power control. It means there is no active dynamic power management where power is decreased to account for periods of acceleration/deceleration. You’re still fully able to control ‘S’ power levels with M3.

Note that the LightBurn profile chosen only changes the style of g-code generated. It’s up to the controller to interpret the gcode. So whatever method that gets you the output that you need is what you’re really looking for.

I’d suggest working from the Mach3 forward. Find out what minimal gcode is required to drive the machine to your liking. I’d work with something extremely simple like a straight line. Make sure you can sort out how to control power level. Then graduate to two lines with different power levels. Once you build out the syntax for the gcode then you can retrofit the LightBurn device provide to that gets you as close as possible to that target gcode.

1 Like

Thanks for your reply. I realize that constant power does not mean no power control now. I learned this after playing with several of the GRBL profiles, one of them has the option for constant power and I was able to generate code that mach3 responds to for the given Sxx command.

Only the GRBL M3 profile generates M3 and M5 commands before every jog move. This makes it easy to add my M11P2 and M10P2 commands. I have found that I am able to sepecify specific Sxx commands in other GRBL profiles that Mach3 recognizes but for whatever reason the GRBL M3 profile does not. This is now where I am stuck.

Cutting wood veneers with the GRBL M3 profile works great but if I want to engrave that doesn’t work very well as the laser only fires at 100%.

If I use Inkscape I can control laser power very well but Inkscape… is well…Inkscape and is kind of clunky for laser. I really like LB and if I could find a solution to this issue It would be fantastic.

1 Like

After more testing I have found that I can get the regular GRBL profile to fire the laser at the correct Sxx power level using M11Px Sxx and M10Px.

This requires a manual entry of M10Px before every G0 move and M11Px Sxx after every G0 move. If I do this it works great. no delay of the laser firing and the correct power levels on the output voltage display.

The only remaining issue is that if I rewind the program to run it again with either an M30 command or with a manual rewind in Mach3 the program will again only fire at 100% power…explain that one…

If I reload it fresh it fires with the correct power level.

This I can live with as I don’t do a ton of jobs that need a rewind. If I do I just need to reload it between programs. Maybe someone has an idea of why this happens?

Now I just need to write a script to add the right code before and after the G0 moves and I think I may have this figured out.

This may also unlock pic engraving with multiple power levels but I haven’t tested that yet. I’ll have to wait to see if that works until after I have a script that changes the code properly and works.

Just speculating but could it be that you’re thinking about this backwards?

As-in instead of surrounding the G0 commands you should be placing M11Px Sxx before every G1 command and M10Px after every G1 command. I assume this leaves the M10 off state as default when it hits any G0.

Here is the example of the code that was successful. Please take a look and let me know if you see any changes that should be made, but this code worked on my system. I edited the code for brevity.

The M10P2 command before the G0 command turns the laser off. M11P2 S5 after the G0 command turns it back on at the correct power level. Not sure if I can post a video of this or not.

; LightBurn 1.4.01
; GRBL device profile, user origin
; Bounds: X192.94 Y1454.62 to X226.7 Y1467.48
G00 G17 G40 G21 G54
G90
G0 X0 Y0
G91
M4
; Cut @ 1000 mm/min, 5% power
M8
G0 X13.837Y6.432
M11P2 S5
; Layer inlay pockets
G1 X-1.338Y-0.525S5F1000
G1 Y-2.68
G1 Y3.211
G1 X-0.536
M10P2
G0 X-25.099Y-3.211
M11P2 S5
G1 X-2.104
G1 Y3.211
G1 X-0.536
G1 X2.104
G1 Y0.803
M10P2
G0 X14.95Y-4.754
M11P2 S5
G1 X0.22Y-0.133
G1 X0.457Y-0.246
G1 X0.231Y-0.118
G1 X0.148Y0.347
G1 X0.117Y0.359
G1 X-0.545Y0.24
M5
G1 S0
M10P2
G90
M10P2
; return to user-defined finish pos
G0 X0 Y0

M2

Can you try this code:

; LightBurn 1.4.01
; GRBL device profile, user origin
; Bounds: X192.94 Y1454.62 to X226.7 Y1467.48
G00 G17 G40 G21 G54
G90
G0 X0 Y0
G91
M4
; Cut @ 1000 mm/min, 5% power
M8
M10P2; adding a stop command before the G0
G0 X13.837Y6.432
M11P2 S5
; Layer inlay pockets
G1 X-1.338Y-0.525S5F1000
G1 Y-2.68
G1 Y3.211
G1 X-0.536
M10P2
G0 X-25.099Y-3.211
M11P2 S5
G1 X-2.104
G1 Y3.211
G1 X-0.536
G1 X2.104
G1 Y0.803
M10P2
G0 X14.95Y-4.754
M11P2 S5
G1 X0.22Y-0.133
G1 X0.457Y-0.246
G1 X0.231Y-0.118
G1 X0.148Y0.347
G1 X0.117Y0.359
G1 X-0.545Y0.24
M5
G1 S0
M10P2
G90
M10P2
; return to user-defined finish pos
G0 X0 Y0

M2

looks like you added an extra M10P2 right after M8. What should it do?

The thought process is to ensure that the laser is off before the G0 move.

I’m not sure how the rewind process works but I assume that it retains the last state. If so, then you’d want to make sure that the laser is off when executing the G0 move even if the last state was “laser on”.

The code you wanted me to try did not work. The code I generated gives me control with the correct power and on/off timing with M11/M10. I definitely have to manually close G-code and load G-code in mach3 or else it fires at 100% power. Not sure why this is but I can live with it as long as I know this is the deal.

Everything about my system is a work around. Just add this to the long list of things I do to get this to work.

Thank you for your help.

I just need to find a script to convert the code now. I’m not someone that can just write script. I’m a ski builder not an AppleScript expert by any means.

I’m trying to get chatGPT to write one but I have to be smart about what I ask for…

I got ChatGPT to write an AppleScript to look for every G0 command, add M10P2 above and M11P2 Sxx below. I’ll test this tomorrow. Fingers crossed.

If this works I’ll try to have several power changes in the same program.

I was able to test multiple power in the same program this morning and it works!

This requires you to have M10/M11 and PWM set up properly in Mach3. In LB use the regular GRBL profile for your machine.

At every G0 move add your M10Px command one line above G0 and your M11Px Sxx command one line below G0. Be sure all M3 and M5 commands are also changed for your M11/M10 code for your system.

The script I had ChatGPT write changes all of this for me. I will have to have it write another one that pays attention to the power level set in each layer so I don’t have to do that manually.

It may be possible to do some raster engraving with this once I get the proper script written.

I’m having a hard time getting ChatGPT to extract the power level from the comment line and write that to the Sx command. Does anyone have any ideas on how I can do this? I’m not a programmer, I’m a ski builder and woodworker. Any ideas?

I have an apple script that automatically adds the required code before and after every G0 move for the regular GRBL profile.

This requires that M11Px/M10Px be set up in Mach 3 correctly. M3/M5 are too slow in Mach 3 and give poor results.

If anyone is interested please let me know.

What I don’t have yet is a script that will extract the power level from the comment line and insert it into the code in the right place. So for now if I want various power levels in the same program I have to do that manually.

I’ll post the script here later.

I also do not yet have a solution to the program firing at 100% power if it is re-ran or rewound.