Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    How can I create a toggle macro?

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    7
    16
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PaulHewundefined
      PaulHew
      last edited by

      @dc42 said in How can I create a toggle macro?:

      state.gpout

      Appreciate the input you have given, maybe I need to start at the beginning.
      This is my config for my Lights

      ;Lights
      M950 F10 C"out1"
      M106 P10 S0 H-1 C"Front Lights"
      M106 P10 S1
      
      

      It looks correct, it works. Personally it would be better if it was an on/off and not PWM'd, Do not think I require mood lighting on my chamber lights 😉

      So after enabling Object Model Browser, I found F10 under Fans and it shows the correct info as in my config.
      I change the lights on and off and it changes 'actualValue'

      Not being as clever as you guys but willing to learn, how do I query 'Fan.10' actualValue'?
      I sort of understand the 'if' part
      if 'actualValue' = 1
      then set to 0
      Elif 'actualValue' = 0
      set to 1

      Personally, it would be handy if there were some basic 'Meta Guides' to help us understand how to write queries and some simple ones we could implement to advance our learning.
      Like if the printer is not homed, then home it and how to turn on /off lights with a one button macro!

      Much like you have done with the RRF configurator, it explains the function which has helped me learn a lot.

      I did search for the "state.gpout[n].pwm" and variations in the dozuki and could not find any reference to it.

      Again, Thanks in advance.

      RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
      Voron 2.4 disassembled..... Waiting for the RailCore Mini....

      OwenDundefined 1 Reply Last reply Reply Quote 0
      • OwenDundefined
        OwenD @PaulHew
        last edited by OwenD

        @paulhew said in How can I create a toggle macro?:

        @dc42 said in How can I create a toggle macro?:

        state.gpout

        Appreciate the input you have given, maybe I need to start at the beginning.
        This is my config for my Lights

        ;Lights
        M950 F10 C"out1"
        M106 P10 S0 H-1 C"Front Lights"
        M106 P10 S1
        
        

        It looks correct, it works. Personally it would be better if it was an on/off and not PWM'd, Do not think I require mood lighting on my chamber lights 😉

        So after enabling Object Model Browser, I found F10 under Fans and it shows the correct info as in my config.
        I change the lights on and off and it changes 'actualValue'

        Not being as clever as you guys but willing to learn, how do I query 'Fan.10' actualValue'?
        I sort of understand the 'if' part
        if 'actualValue' = 1
        then set to 0
        Elif 'actualValue' = 0
        set to 1

        Personally, it would be handy if there were some basic 'Meta Guides' to help us understand how to write queries and some simple ones we could implement to advance our learning.

        try here
        https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands

        Like if the printer is not homed, then home it and how to turn on /off lights with a one button macro!

        If you look through the meta commands topic section of the forum there are many examples which should help you understand.
        https://forum.duet3d.com/category/34/gcode-meta-commands

        Much like you have done with the RRF configurator, it explains the function which has helped me learn a lot.

        I did search for the "state.gpout[n].pwm" and variations in the dozuki and could not find any reference to it.

        Again, Thanks in advance.

        You have to use the object model to reference the proper name & syntax for the GPIO output, fan or whatever.
        In our case, you're using a fan output, not a GPIO pin.
        So you need to look in the fans section of the object browser.
        Fan outputs are PWM capable, so that you can set a fan to any speed.
        In your case, you can just set it to 0 or 1 using M106.
        A GPIO output would be set by M42

        in terms of code you could have something like

        if fans[10].actualValue = 1
        	M106 P10 S0
        else
        	M106 P10 S1
        

        This example is only meant for an LED connected to a fan ouput that is only ever set full on, or full off.

        PaulHewundefined 1 Reply Last reply Reply Quote 4
        • PaulHewundefined
          PaulHew @OwenD
          last edited by

          @owend said in How can I create a toggle macro?:

          if fans[10].actualValue = 1

          Thank You for your reply.
          I did not know there was a Meta Commands section in the forum.

          I have learnt and understand a little more now, thank you.

          Regards,

          Paul.

          RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
          Voron 2.4 disassembled..... Waiting for the RailCore Mini....

          1 Reply Last reply Reply Quote 0
          • Yaoundefined
            Yao @dc42
            last edited by Yao

            @dc42 is something like this (led toggle on/off with if-else macro) also possible for OUT1 on duet3 board ?
            I can't seem to get it to work...
            Thanks.

            OwenDundefined 1 Reply Last reply Reply Quote 0
            • OwenDundefined
              OwenD @Yao
              last edited by

              @yao
              Yes it is.
              Please post what you have so far.
              Both config.g and macro so we know how you're configuring the pin and how you're controlling it.

              Yaoundefined 1 Reply Last reply Reply Quote 0
              • Yaoundefined
                Yao @OwenD
                last edited by Yao

                @owend Hi, thanks for your response,

                in the config:

                ; white led chamber light ALL
                M950 P25 C"out1" ;use main out1 for full Chamber light
                M42 P25 S0.5 ;on 50%

                this can be adjusted with:
                ; chamber lights hi
                M42 P25 S1
                ; chamber lights low
                M42 P25 S0.02

                I was trying:
                if out1[25].actualValue >= 0.8
                M42 P25 S0.02
                else
                M42 P25 S1

                whatever I try i get unknow value 'out1'

                OwenDundefined 1 Reply Last reply Reply Quote 0
                • OwenDundefined
                  OwenD @Yao
                  last edited by

                  @yao
                  What board are you using?
                  On my Duet 2 running RRF3.4 , the output port limit seems to be 20.
                  Do you really need it to be 25?
                  Try using a lower number

                  And your code should look like
                  if state.gpOut[nn].pwm >= 0.8

                  Yaoundefined 1 Reply Last reply Reply Quote 1
                  • Yaoundefined
                    Yao @OwenD
                    last edited by

                    @owend !!! that works!
                    I am running a duet3. my lights start at P20.
                    originally from the 3HC (hence the P20 range) but I ran out of connections so moved back to the main. for clarity for myself I kept the lights within the P20 range.

                    using the following now:

                    if state.gpOut[25].pwm >= 0.8
                    M42 P25 S0.02
                    else
                    M42 P25 S{state.gpOut[25].pwm + 0.2}

                    I now have 5 steps to full brightness and then it toggles to almost off.

                    Thanks for this. I have to investigate more into correct names and designations for usage of pins. I am not C minded, more of a mechanical guy. It amazes me every time how garbled the expression stackups need to be..

                    what does the 'pwm' mean? and why does it need to be there?

                    OwenDundefined 1 Reply Last reply Reply Quote 0
                    • OwenDundefined
                      OwenD @Yao
                      last edited by OwenD

                      @yao
                      Is not really that complicated
                      It's a hierarchical structure no different to your street address. Country/state/city/street/number/unit
                      These are not official designations but...
                      State - refers to functions on the board you might normally monitor
                      GPout[] - refers to the GP output pins as a whole (analogous with your street). It's an array, so you need a port number to identify an individual pin (house number)
                      pwm - refers to the PWM (pulse width modulation) value of that pin. You need that because the pin may have many different properties that are applied. e.g (name, inversion etc). Just as a street number may have one or 100 dwellings. If you don't address the right one, your letter may not get there.

                      If you use the object model browser it becomes easy and you can copy the correct syntax with the button provided.

                      Yaoundefined 1 Reply Last reply Reply Quote 2
                      • Yaoundefined
                        Yao @OwenD
                        last edited by

                        @owend @owend Never had such a clear explanation is this!
                        But, is there a clear 'roadmap' where i can find all these specific DUET adresses, numbers, extensions and designations?
                        Where can I find the 'object model browser' :
                        this ?: https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-Documentation#overview
                        I can't find the specific addresses you mention in that list.
                        M409 gives me an empty list of strings...

                        OwenDundefined 1 Reply Last reply Reply Quote 0
                        • OwenDundefined
                          OwenD @Yao
                          last edited by

                          @yao
                          This post shows you how to look at the object model browser
                          https://forum.duet3d.com/post/277538

                          apakundefined 1 Reply Last reply Reply Quote 1
                          • apakundefined
                            apak @OwenD
                            last edited by

                            some where I found this some time ago

                            Macro "leds on/off"

                            if state.gpOut[1].pwm == 1
                               M42 P1 S0
                            else
                               M42 P1 S1
                            

                            in config files

                            ; LEDS
                            M950 P1 C"e1heat" Q500							;use heater 1 outupt for LED
                            M42 P1 S1										; turn off LEDS
                            
                            
                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA