M4 command code bug

Good morning,
I wanted to report a problem!
I’ll send you a small example of the generated Gcode:

G00 G17 G40 G21 G54
G90
M4
; Cut @ 900 mm/min, 62% power
M8
G0 X182Y140
M3
G0 Z0
M3
G1 F100 S0
G4 P0.002
G1 S0
G0
M3
; Layer C05
G1 Y164S620F900
G1 X206
G1 Y140
G1 X182
G1 Y140.8
G1 S0
M9
G1 S0
M5
G90
; return to user-defined finish pos
G0 X0Y0

As you can see, on the third line, there’s an M4 command that shouldn’t be there! Since I’m using the constant power option, it should only use M3 commands to control the laser. This is causing me problems, because using grblhal as the firmware, I can activate a solenoid valve with the M4 command, and it activates incorrectly even when I have constant power mode checked. Can you fix this problem?

Thanks

Yes, it should. M4 is spindle CCW, but a laser has no spindle, so it is used to tell the controller to use Variable Power. There are a LOT of lasers out there that function quite well with the M4 command.

Having M4 control a solenoid instead of the spindle is unexpected. Your machine is self-built, so can you possibly assign the solenoid to another output?

This is about all the help I can provide. You have not stated which controller board you have, which version of GRBL you selected during Device setup, which dialect of GRBL your controller runs, and whether or not you have Air Assist included.

For a custom build like yours, I recommend using the “Custom Gcode” device type:

This should give you all the control needed to generate working Gcode for your controller.

Another good read:

If you get stuck somewhere, we’re happy to help.

2 Likes

Hi,
I have a K40 with an ESP32 board… Grblhal firmware!
This company allows you to “bind” additional outputs to events!
In my case, I bound the event detected by the M4 command!
Why I did this: when I engrave, I use “variable power M4,” when I cut, I use constant power M3. When I engrave, I don’t need full air assist power, just a little puff to prevent smoke from rising into the nozzle and dirtying the lens!
So I thought about activating a solenoid to throttle the air flow while I engrave with M4!

Hi,
This doesn’t solve my problem! Because even with custom gcode, it sends the first M4 for no reason! Even when I select constant power mode!
I could solve this problem by being able to add command lines to each engraving/cutting level!! Because with grblhal I have the ability to use different custom M commands to activate custom outputs or functions!! I have already made a request! But I have not received any feedback!!

There would also be other functions that I could activate automatically if I could add them to each cutting/engraving level!! Instead, now I have to do one job at a time and press the macro button to change parameters or functions, which are used for engraving and not for cutting, for example! Or for a simple engraving and not for engraving an image!!
Grblhal is increasingly used, and not being able to automatically use all its potential is frustrating!!
Please consider my request!
Thank you very much.

I hope I do not sound like a brat, but there are a bunch of users running GRBLhal with no problem with the M4 command. Expecting Lightburn to rewrite the code for one user when they offered the Custom GCode option is not fair.

The fact that you chose to to use a certain Mcode that has a well established purpose assignment is unfortunate. It is you who chose to call M4 a “custom” M function. I doubt you have the power to rewrite a GCcode Standard. You could have, and should have, used the M7 command, Mist Air.

This would have given you the option for independant control. With your current setup, you have 2 separate and conflicting operations (M3 and M4 are mutually exclusive) shut off with the M5 command. If you built your machine in a non-standard way, do not expect others to comply with your standard.

I used to service CNC machines. If I encountered your setup, I would say I am not touching it and present you with a trip charge. I would not make myself, and my employer, responsible for the eventual repair.

Stomp and scream and cry if you want, but it will change nothing. Standards are there for a reason, to ensure we are all playing by the same rules. And here is another standard for you, Lightburn and the Forum members will continue to help you as best we can. Just don’t make our task impossible. :hugs:

Hi
Maybe you didn’t read that carefully…or maybe you didn’t even look at the gcode I sent! The first M4 command is useless; it shouldn’t even be there, since in that case I’m using the constant power option!
I have no problem with M4!! And I don’t want Lightburn to make custom gcode for me! But I don’t understand why you’re launching the first M4!!
If there were options to add commands to each cutting and engraving level, I certainly wouldn’t have used the event triggered by M4 to activate the solenoid!! Since with GrblHall, I have the M64 command to activate the outputs as I please!!!
I already use M7 correctly to activate the suction and M8 to activate the air assistant!!! I’m not stupid!!!
I build industrial automation, I know what I’m doing! Don’t worry, you can come to me for maintenance without any risk!!
I don’t think I’m asking for something stupid and useless!!!
Giving the user the ability to add some M commands to each cutting/engraving level could be useful to many users, not just me!! By the way, I’m not the only one asking for it; other users have asked for it before me!
I never said I wanted to change the standard things!! I don’t know why you think that!!!

I repeat, reducing the airflow is just one of many things!! You can activate M commands to manage some plugins present in GrblHat for the destination of power, speed and many other things that could be managed automatically! Without stopping after every operation and having to press the macro button to then continue working!
Believe me, I really don’t understand the point of your answer! And above all, I don’t understand why you can’t grasp the importance of my request!!

And I’m not talking about removing that M4 command at the beginning of the code! But about being able to add M commands to the beginning/end of each cutting/engraving layer!!
I’ve been using Lightburn since it was born and it’s been on the market!
I think it’s a fantastic Cam. I think this would make it even better!!

I don’t understand another thing!
I reported a problem! In the Gcode generated by Lightburn, there’s an M4 command (variable power management) that shouldn’t be there! Because I activated the Constant Power option on that cutting layer! So there should only be M3 commands (constant power management) for laser power management!
This, in my opinion, is a bug!!! And that’s a fact, and facts are not up for debate!
You, on the other hand, focused on how I intercept the command and what I do with it!!!
That’s not the problem!!!
The problem is: Why is an M4 command issued for no reason???

This I cannot answer. Having been a programmer by trade, I can only presume there was a reason. Without access to the source code, I am in the dark.

I searched Google (your posting is already listed) and found no other mention where the M4 was causing a machine issue, other than yours.

I understand how you are feeling, but you do not like my saying that it is a problem because you made it one. What you are calling a bug (and it could well be one) is really an inconvenience you could solve by moving a wire to a different pin and remapping the output. Until Lightburn calls it a bug, I am going to stick with my position. If they do, then I will say “Good catch, glad you found it.”

But indeed you have received feedback from a Lightburn staff (@Aaron.F ) member, so they are aware of your concern.

The M4 at the start is the default mode for GRBL and the "Constant Power Mode’ allows an override at the the layer level.

I’m not sure I’d say it’s a bug, because it would normally be benign.

Another way you may consider approaching this is to have the default state of the air be low (comes on with the machine), and when ‘Air’ is enabled at the layer, the M8 could be used to open the throttle up (open a bypass).

1 Like

Good morning
Thank you for your reply.

OK now I understand the reason for that M4 command at the beginning of the code…

No, it’s certainly not a bad bug! I think 99.9% of the time it won’t cause any problems and no user has noticed.

Thanks for this idea!
I’m mad at myself for not having thought of it! In fact, M8 (air assist) is currently the only thing I can activate/deactivate at each engraving/cutting level…
I can easily activate the compressor with an AUX output (available in grblhal) at the start of a job and turn it off at the end, and modulate the flow rate at each level with the M8 control!

I’d like to take this opportunity to reiterate the importance of being able to add commands to each engraving/cutting level!
Modulating the airflow may seem trivial, but how many users complain that their engravers won’t cut or engrave? Only to find out that the most common cause is that their laser lens has become dirty from engraving fumes!? I think if their firmware/boards had this option, they’d definitely enable it!
And this is just a small example… Grblhal has numerous plugins: eventout, bltouch, pwm_servo_m280, feed_override_m220, Laser_Overdrive, trinamic (dynamic driver control), yerk-accelleration, and so on…
These plugins can dynamically interact with M commands, as needed, in various processes to improve the performance of your engraver and optimize engraving and cutting processes! But to take full advantage of them, some plugins must be activated only in certain processes. For example, the Laser_Overdrive plugin improves image engraving with a CO2 laser, but it isn’t used during cutting! Hence the need to be able to automatically control it in the engraving layers and modify its parameters in the cutting layer, without having to interrupt processes and press the macro button to do so! I won’t list all the other options and features of all the other plugins here, but adjusting the yerk, based on the engraving or cutting speed, would improve the fluidity of the movements… Like it happens with 3D printers!And so on for all the other options!!
Sorry to insist on this topic…
Hoping you’ll consider my request, I greet you and thank you for your work and support!!
Best regards

I’d like to take this opportunity to reiterate the importance of being able to add commands to each engraving/cutting level!

I saw the related requests in Fider, it’s really interesting to see how people are pushing the limits of the software and using new features of newer firmware.

While it might be nice to have extra controls in Cut Settings, the task could I think, could still be handled just by the Custom GCode device.

As you know, one way you can currently achieve layer-specific start/end GCode is by leveraging the ‘Air’ assist toggle. But did you also know that the Custom GCode device allows you to use multiple lines of GCode where there might typically been one line previously?

For example, in the example of grblHAL’s ‘Laser Overdrive’ plugin, you could potentially use these lines to:

-change/reduce the air flow using M8
-switch to dynamic power with M4*
-insert commands as needed to activate the plugin such as ‘Mxxx Pxx’

*M3 ‘constant power’ switching isn’t enabled yet in this device.

For more granular control, new Custom GCode insertion fields such as “Engraving Start/End” might be needed, or perhaps support for statements like this, allowing conditional injection of code based on layer name, mode, or other properties? Just thinking out loud here to keep the discussion going…

1 Like

Hello
Good morning
The “new” firmware offers the ability to automate certain operations and simplify or improve the process! This is very useful, but you also need the CAM, which allows you to take advantage of them!

Yes, of course I’ve seen these possibilities! But the fact remains that I would have to perform them all at once and only using air assistance! Which is currently the only option that can be changed at any level!!
Now that Lightburn has begun its journey into CNC machine control, you’re sure to receive more requests, because it’s even more important! For example, for level changes that require tool changes, or other processes that require custom commands to optimize the entire machining process… Grblhal, for example, has many plugins dedicated to CNC control, as it was created specifically for them!

Yes of course, you could add a box inside the layers window where you can insert the additional gcode for the start and end of the level…

Yes, I remember that software…
I don’t think it’s necessary! It would be cumbersome and difficult for some users to understand…
I think adding something similar to the existing one (start/end job Gcode) on each engraving/cutting layer is a simple, functional, and easy-to-understand option for all users.

Yes, of course, thinking out loud and sharing ideas is the first step in what is called “research and development”!And I’m glad you’re doing that in this discussion!

Before I forget, there is another layer-level option which could be repurposed… the “Laser 2” switch, which is enabled by populating the ‘2nd Tool On’ for example:

Good morning
Thanks for your advice…
I’m currently trying the custom version of Lightburn.
Using Tool_1 and Tool_2, the “variable/constant power” option doesn’t work… but that doesn’t matter since you can set M3 for tool_1 and M4 for tool_2.
I had some trouble importing the macros and the cut/engrave settings for the various layers, as I couldn’t import from a “normal” version to a “custom” version! I solved the problem by manually copying the macro and layer sections from the export file!
Maybe I’m just not that good at it… but in any case, I solved the problem by doing what I explained.
But this topic perhaps requires another discussion…

I have a proposal for you… now I’ll try to explain it to you, thinking out loud…
Your advice got me thinking about an alternative solution to my request…
What if in the “custom” version you added (like with the tools) the ability to have multiple types of Air Assist! Let me explain: in the layers window, add the enablement for Air assist_1, Air assist_2, Air assist_3, Air assist_4, etc…
With the ability to edit the text! Example: Air assist_2 → Laser_Overdrive(custom username).
And add the code section in the custom gcode!
This way, in the layers window, you only add the checkboxes to enable/disable the commands and the code remains in the custom gcode page!
It would be like having “macros” that automatically activate when enabled in the layers.
A functional and clean solution! And also easy for users to use…
It doesn’t allow detailed customization for all layers, but it’s definitely a good compromise!
I hope I’ve explained myself clearly with my example…
What do you think of my solution?

I do like the idea of the Custom GCode profile allowing additional checkboxes including “Air” for triggering MCode functions.

Maybe the additional columns could show if the Custom GCode settings for “Air2,Air3” were populated and it would be ideal if the titles could be renamed, but might need to be limited to 4 characters to be tidy.

I don’t think you would need any more than two extra boxes?

Worth updating your Fider request?