How do I trigger a macro during Certain Machine operations



  • I have Neopixel Bed lighting that can be controlled using macros. I have one macro that is run when I home the machine since It triggers when clicking the Home All button in DWC which runs the "homeall.g" file in the video you can see the lights turn green.

    But... How can I trigger from other actions such as when a print starts, ends, pauses, etc. when there isn't a file I can place code in calling the macro? There are some files that can work but what about when the filament sensor detects an out of filament condition what could be used to trigger a macro for that? Any help and Ideas with this would be greatly appreciated.



  • Most of those have Macros. For example, begin.g when a print starts, pause.g when filiment out (although, there are several possible reasons for a pause, so there may be a better way).

    As for those that don't, you can put the same commands you'd have in the macro directly in the G-Code.

    The above covers a lot of ground. If you have an example of something else, post it, and we'll see if there is an easy way.



  • Thanks Danal for the positive comments! As the video shows, the lights change to green when the printer is "calibrating" such as homing or bed leveling and after it's done, another GCode dims the lights back to an "Idle" color. I have GCode in the homeall.g file. I also have matching code in the Homez.g, homex.g and homey.g files. My bed lights run from a small arduino connected to a GPIO pin on the DUEX5 board and I'm using M42 to send commands to change the color.
    Is it as simple as knowing which file is called during each operation? You mention a begin.g file, I don't have one with that name. Is there a Duet docs link that might explain more about all the various files I could make use of?

    Here are some other examples I would like to change color with:
    When a print starts, which file could the GCode/macro be called from? I don't have a begin.g file....
    When a print ends, my gcode would be called from stop.g?
    When a print pauses, my gcode would be called from pause.g?
    When a print resumes, my gcode would be called from resume.g?

    Maybe I was simply over analyzing this. I have about 5 colors I'd like to trigger depending on the printer's status.



  • Macro Names. I believe this is the whole list:

    bed.g
    pause.g
    resume.g
    cancel.g
    start.g
    stop.g
    sleep.g
    config-override.g
    deployprobe.g
    retractprobe.g
    heightmap.csv
    load.g
    config.g
    unload.g
    resurrect.g
    resurrect-prologue.g
    filament-change.g

    You can search the various documents for the nuances of each.

    P.S. I said "begin.g", it is really 'start.g', and if you don't have one, create it (in 0:/sys/)



  • You could put custom gcode in the slicer for the start and end of prints, and if there's anything you want to do at layer change.



  • Thanks so much Danal, that's quite a list of possible macros. This should definitely help me out. mrehorstdmd thanks for the tip about using the slicer I may try that as well but I was hoping to keep the printer and the light changes to itself so I don't have to do custom programming in the slicer. Its definitely an option though! Thanks!


  • Moderator

    @Danal said in How do I trigger a macro during Certain Machine operations:

    heightmap.csv

    I dunno if I'd consider this one a macro. It's also system created, so if you added anything to it I'm not sure how well it would be parsed afterwards and it would be overwritten next time you ran G29. 😉



  • Yes, I recognized that one as well. I make use of the mesh bed compensation and each time I run it, a new heightmap.csv file is created. Thanks!



  • @Phaedrux said in How do I trigger a macro during Certain Machine operations:

    @Danal said in How do I trigger a macro during Certain Machine operations:

    heightmap.csv

    I dunno if I'd consider this one a macro. It's also system created, so if you added anything to it I'm not sure how well it would be parsed afterwards and it would be overwritten next time you ran G29. 😉

    Good point. That list was derived from regex applied to a module in RRF source. Should have taken that one out by hand.


  • Moderator

    I doubted that you'd typed those all by hand. Well done.


Log in to reply