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

External Pause/Resume Button

Scheduled Pinned Locked Moved
Gcode meta commands
6
22
1.9k
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.
  • undefined
    burtonenator
    last edited by burtonenator 5 Jul 2022, 20:54 7 May 2022, 19:43

    I'm trying to setup an external physical button that will pause and resume a job. I currently can pause from the button as expected, but I cannot resume.

    I've setup a trigger and a file so that I can add logic, but my basic attempt seems to have failed, is there anyway to get the printing state from a macro, I've seen that it'll always show busy, but that didn't seem to match either.

    My current trigger:

    if 	state.status == "Paused" 
    	M24
    if 	state.status == "Printing" 
    	M25
    

    I pause by just replacing that with M25

    undefined undefined 2 Replies Last reply 7 May 2022, 21:24 Reply Quote 0
    • undefined
      OwenD
      last edited by OwenD 5 Jul 2022, 21:06 7 May 2022, 21:05

      By your description it may be that you have not indented your code.
      Looks like you corrected while I was writing.
      If it's actually written as you have posted then the if statements won't do anything and it will execute each line in turn, with M25 being the last.
      Also you need to use the correct object model names and they are case sensitive .
      These are listed here
      The status you see in DWC seems to be altered from that in the object model for readability.

      so the correct code for what you have written would be

      if state.status == "paused"
          M24
      elif state.status =="printing"
          M25
      

      You may find however that as soon as your macro starts, the machine status will become "busy" or "processing" because it's running the macro.
      To get around that and to use a single button you could set up your trigger like this
      In config.g set up a global variable

      if !exists global.lastPress ; if it's not created we do so now
          global lastPress = false
      

      then in your trigger do this

      if job.file.fileName !=null ; if there's a job filename then it's reasonably safe to say we are printing
         if global.lastPress == false ; the button hasn't been pressed so we'll pause
            M25
         else
           M24
         set global.lastPress = !global.lastPress ; toggle the value from whatever it was before use "not"
      
      1 Reply Last reply Reply Quote 0
      • undefined
        OwenD @burtonenator
        last edited by OwenD 5 Jul 2022, 21:25 7 May 2022, 21:24

        @burtonenator
        You will also likely have to to some code in place to avoid issues with "bouncing", where the contacts make and break a few times when you press it.
        Something like this at the start of your trigger will ensure you have to hold the button down for an extended period.
        Change the gpIn number to suit where you have your button connected

        G4 S1 ; put a delay in as your first line,  The buttin must be held longer than this.
        if sensors.gpIn[7].value != 1 ; the button isn't still pressed so we'll abort the macro
           echo "Button wasn't pressed long enough" ; remove this line when done testing
           M99 ; cancel macro
        
        if job.file.fileName !=null ; if there's a job filename then it's reasonably safe to say we are printing
           if global.lastPress == false ; the button hasn't been pressed so we'll pause
              M25
           else
             M24
           set global.lastPress = !global.lastPress ; toggle the value from whatever it was before use "not"
        
        undefined 1 Reply Last reply 8 May 2022, 01:06 Reply Quote 0
        • undefined
          burtonenator @OwenD
          last edited by burtonenator 5 Aug 2022, 01:12 8 May 2022, 01:06

          @owend
          So I gave this a try, but it now triggers the pause, and then immediately the resume.

          I don't see your "Button wasn't pressed long enough" error, even if I push very quickly, and it always does the pause resume, even when I did a longer dwell.

          G4 S5				 ; put a delay in as your first line,  The button must be held longer than this.
          if sensors.gpIn[9].value != 1 ; the button isn't still pressed so we'll abort the macro
          	echo "Button wasn't pressed long enough" ; remove this line when done testing
          	M99 ; cancel macro
          
          if job.file.fileName !=null ; if there's a job filename then it's reasonably safe to say we are printing
          	if global.PausePress == false ; the button hasn't been pressed so we'll pause
          		echo "Pause"
          		M25
          	else
          		echo "resume"	
          		M24
          	
          	set global.PausePress = !global.PausePress ; toggle the value from whatever it was before use "not"
          

          important parts of config.g:

          ;Pause Button
          M950 J9 C"io8.in" 
          M581 P9 T2 S1
          global PausePress = false
          

          and the console:

          5/7/2022, 6:01:39 PM	Printing resumed
          5/7/2022, 6:01:35 PM	resume
          5/7/2022, 6:01:29 PM	Printing paused at X207.1 Y192.9 Z6.6
          5/7/2022, 6:01:24 PM	Resume state saved
          5/7/2022, 6:01:24 PM	Pause
          
          1 Reply Last reply Reply Quote 0
          • undefined
            fcwilt @burtonenator
            last edited by 8 May 2022, 01:26

            @burtonenator

            Take the safe and reliable route - use two buttons.

            Frederick

            Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

            1 Reply Last reply Reply Quote 1
            • undefined
              OwenD
              last edited by 8 May 2022, 01:50

              I suspect it's being invoked twice. So the de-bouncing logic isn't working.
              Maybe reverse it and use a small delay
              Try

              echo "called at " ^ state.time
              G4 P10 ; delay 10ms to debounce
              if sensors.gpIn[9].value=0
              	M99 ; break out if sensor value is zero again (bouncing)
              

              as your first line.
              I expect a different time for the pause and resume lines.

              Do you see the value of the input change in the input model?

              It would be much easier to use two buttons.

              undefined 1 Reply Last reply 8 May 2022, 02:07 Reply Quote 1
              • undefined
                burtonenator @OwenD
                last edited by 8 May 2022, 02:07

                @owend
                This seems to work, although I don't understand why it does and what I had before doesn't:

                ;echo "called at " ^ state.time
                G4 P1 ; delay 1ms to debounce
                if sensors.gpIn[9].value=1
                	;echo "debounce"
                	M99 ; break out if sensor value is zero again (bouncing)
                
                if job.file.fileName !=null ; if there's a job filename then it's reasonably safe to say we are printing
                	if global.PausePress == false ; the button hasn't been pressed so we'll pause
                		;echo "Pause"
                		M25
                	else
                		;echo "resume"	
                		M24
                	
                	set global.PausePress = !global.PausePress ; toggle the value from whatever it was before use "not"
                

                Even with the delay debounce 1ms it now works as expected, So Thank you!

                As for the 2 buttons debate, these buttons are way to cool, and lend themselves to the "One button Pause/Resume" idea:

                Lit Indicator Buttons

                I light and dim the LED in the pause and resume macros so the button is a correct indicator. You can even put a label behind the plastic to mark what its for. The LED is a bit dim on the 3.3v from the output, but I think I can deal with that now that I have this working

                undefined undefined 2 Replies Last reply 8 May 2022, 02:22 Reply Quote 1
                • undefined
                  OwenD @burtonenator
                  last edited by 8 May 2022, 02:22

                  @burtonenator
                  The reason it didn't work before is that when the button bounced it called the macro twice in succession.
                  The long delay was masking this.

                  1 Reply Last reply Reply Quote 0
                  • undefined
                    Nightowl @burtonenator
                    last edited by 12 May 2022, 17:54

                    This is a really interesting thread, @burtonenator, thank you. I'm looking for a way to pause and resume the machine (in my case a CNC machine) with a normally open switch, which you seem to have done here. First press to pause, subsequent press to resume. This was referred to as a "feed hold" switch on my Shapeoko, but it wasn't completely workable with an external switch, so I'm hoping this solution is what I'm looking for on Duet3 MB6HC-controlled machine.

                    Although a flagrant abuse of the code you've shown here (sorry!) is it necessary to have Pause and Resume macros, as I can't see how they are 'called' from this code - or is that what the global.PausePress line refers to?

                    I'm also assuming the : Pause button lines in the config.g file are necessary, too?

                    As you can guess, I'm completely new to this, particularly programming the Duet!

                    I also noted @fcwilt's comment about using two buttons, which the direction I'd probably go in if I can't wrangle your code to fit with my machine.

                    Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                    I'm still on my learning curve, so take everything I say with caution!

                    RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                    undefined 1 Reply Last reply 13 May 2022, 02:28 Reply Quote 0
                    • undefined
                      burtonenator @Nightowl
                      last edited by 13 May 2022, 02:28

                      So far this has worked well for me, the only issue is I do have to push the button until the command is recognized, so if the printer is doing a long line, it won't catch unless I have the button down at the end of the line before the next command goes in. This is probably expected and its not that big an issue in practice.

                      @nightowl999

                      This is all the magic from the config.g side, its the "T2" that sets it to run the second trigger file (trigger2.g) when the button is pushed.

                      ;Pause Button
                      M950 J9 C"io8.in" 
                      M581 P9 T2 S1
                      ;if !exists global.PausePress ; if it's not created we do so now
                      global PausePress = false
                      

                      trigger2.g, its the M24 and M25 that actually call the pause and resume files :

                      ;echo "called at " ^ state.time
                      G4 P1 ; delay 10ms to debounce
                      if sensors.gpIn[9].value=1
                      	;echo "debounce"
                      	M99 ; break out if sensor value is zero again (bouncing)
                      
                      if job.file.fileName !=null ; if there's a job filename then it's reasonably safe to say we are printing
                      	if global.PausePress == false ; the button hasn't been pressed so we'll pause
                      		;echo "Pause"
                      		M25
                      	else
                      		;echo "resume"	
                      		M24
                      	
                      	
                      

                      turning the light on and off was the easy part, just turn the pin for that on or off:

                      M42 P8 S0 ;LED off
                      set global.PausePress = !global.PausePress ; toggle the value from whatever it was before use "not"
                      

                      and its magic in config.g:

                      ;output for pause LED
                      M950 P8 C"io8.out"
                      M42 P8 S0 ; off by default 
                      
                      undefined 3 Replies Last reply 13 May 2022, 07:47 Reply Quote 1
                      • undefined
                        Nightowl @burtonenator
                        last edited by Nightowl 13 May 2022, 07:47

                        That's awesome, thank you @burtonenator!

                        I see you're using "io8" for this (I'll have to change that to io1 as I'm already using io2, 3, 6 and 8!) but I think that should be fairly straightforward.

                        I also understand the "; Pause Button" and "; output for pause LED" lines of code are in the config.g file and the code for the M24 and M25 commands are in the trigger.g file, but what I'm not clear on is where the two M42... lines go. Are these in the config.g file too?

                        I think I've pretty much got the pin outs clear in my head too, but the LEDs in my switch (I think) are 12v, so I may need to get the +ve feed for that elsewhere, probably OUT7, 8 or 9.

                        Anyway, I'm off to experiment!

                        Thanks again!

                        Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                        I'm still on my learning curve, so take everything I say with caution!

                        RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                        undefined 1 Reply Last reply 14 May 2022, 18:33 Reply Quote 0
                        • undefined
                          burtonenator @Nightowl
                          last edited by 14 May 2022, 18:33

                          @nightowl999

                          I have the initial M42 in the config.g because it does actually start with that on, so this sets it off, and then after that its in the pause and resume to set it correctly when pressed.

                          Yea, the out on the io's is 3.3v, I needed a transistor to bring it up to 5v for my LED, which in that one I showed above lists as 12v but looks great at 5v

                          oliofundefined undefined 2 Replies Last reply 15 May 2022, 15:40 Reply Quote 1
                          • oliofundefined
                            oliof @burtonenator
                            last edited by oliof 15 May 2022, 15:40

                            @burtonenator if you used M950 P8 C"!io8.out"you could skip the M42 IIRC.

                            <>RatRig V-Minion Fly Super5Pro RRF<> V-Core 3.1 IDEX k*****r <> RatRig V-Minion SKR 2 Marlin<>

                            1 Reply Last reply Reply Quote 0
                            • undefined
                              Nightowl @burtonenator
                              last edited by 28 May 2022, 14:00

                              @burtonenator said in External Pause/Resume Button:

                              the only issue is I do have to push the button until the command is recognized, so if the printer is doing a long line, it won't catch

                              Following on from this comment, what in 3D printing terms is "...a long line"? I appreciate this is the code within the gcode file, obviously 🙂 , but i'm not familiar with how travel speed/time on a 3D printer compares to that of a CNC machine.

                              Is it a case of CNCers savagely cut their way through stock while 3D printers gently weave their way?

                              Thanks

                              Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                              I'm still on my learning curve, so take everything I say with caution!

                              RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                              Phaedruxundefined 1 Reply Last reply 28 May 2022, 18:14 Reply Quote 0
                              • Phaedruxundefined
                                Phaedrux Moderator @Nightowl
                                last edited by 28 May 2022, 18:14

                                @nightowl999 said in External Pause/Resume Button:

                                .a long line

                                It means that each command would execute and complete before an interruption/pause could take effect before the next command is executed.

                                You can reduce this effect by increasing the segmentation value. This breaks long running commands up into smaller sections which allows the interruption to happen sooner.

                                See the details on the M669 command for how to configure segmentation.

                                https://docs.duet3d.com/en/User_manual/Reference/Gcodes#m669-set-kinematics-type-and-kinematics-parameters

                                Z-Bot CoreXY Build | Thingiverse Profile

                                undefined 1 Reply Last reply 28 May 2022, 18:19 Reply Quote 1
                                • undefined
                                  Nightowl @Phaedrux
                                  last edited by Nightowl 28 May 2022, 18:19

                                  Sorry, I was being slightly flippant, @phaedrux, although it would be interesting to know how these things compare.

                                  I can cut a a 12" slot in a piece of hardwood with a 1/4" end mill quite qhickly, but I guess it would take a lot longer for a 3D printer to build a 1/4" square bar 12" long quite a bit longer, but I suppose it's trying to compare apples and pears...

                                  Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                  I'm still on my learning curve, so take everything I say with caution!

                                  RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                                  undefined 1 Reply Last reply 28 May 2022, 20:08 Reply Quote 0
                                  • Phaedruxundefined
                                    Phaedrux Moderator
                                    last edited by 28 May 2022, 18:22

                                    It's not about the time or speed it takes, it's about the gcode command itself which would be the same in CNC or 3d printer. The point being that in order to interrupt a command in progress it must be segmented to stop it mid execution.

                                    Z-Bot CoreXY Build | Thingiverse Profile

                                    undefined 1 Reply Last reply 28 May 2022, 18:26 Reply Quote 1
                                    • undefined
                                      Nightowl @Phaedrux
                                      last edited by Nightowl 28 May 2022, 18:26

                                      @phaedrux I'm being a plum. I was getting confused with another thread! Sorry.

                                      No, this question was really about the delay when activating the pause command for the external switch.

                                      Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                      I'm still on my learning curve, so take everything I say with caution!

                                      RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        fcwilt @Nightowl
                                        last edited by 28 May 2022, 20:08

                                        @nightowl999 said in External Pause/Resume Button:

                                        it's trying to compare apples and pears...

                                        I like pears but my wife doesn't.

                                        Frederick

                                        Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                                        undefined 1 Reply Last reply 28 May 2022, 22:13 Reply Quote 1
                                        • undefined
                                          Nightowl @fcwilt
                                          last edited by 28 May 2022, 22:13

                                          @fcwilt 🙄 🙂 🙂

                                          Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                                          I'm still on my learning curve, so take everything I say with caution!

                                          RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post
                                          Unless otherwise noted, all forum content is licensed under CC-BY-SA