Duet 3 / RPi Power Toggle Script

  • We are using two power supplies within our printers - a dedicated 5v and a 24v. The goal was to allow the Duet/RPi to run in a low power mode and toggle power to the 24v supply as needed. There were a few "gotchas" in this as we discovered a potential defect that we've reported with M999, but overall this is working well.

    We'll update this thread as the macro matures. Note that we are currently running 3.2b1 on all our machines.

    First up are changes to our config.g. We used conditional gcode to verify if vIn was above 23v. If so, the assumption is made that the 24v power supply is On. We are using a SSR to toggle this through "pson" using M80 and, eventually M81 S1 after the M999 issue is resolved.

    Here is how our config.g is now formed:

    ;== General Settings ===================
    G90			; Sends absolute coordinates..
    M83			; ..but relative extruder moves
    M550 P"Printer Name"	; Sets printer name
    M669 K1			; Selects CoreXY mode
    ;== PanelDue ===========================
    M575 P1 B57600 S1	; Configures PanelDue
    ;== Determines if the 24v rail is enabled ==
    if boards[0].vIn.current < 23
      M563 P1 H1 S"n/a"	; Define "Default Tool" so macros show up on PanelDue
      ; everything else in our config goes here with the
      ; proper indentation to remain within the if statement

    We then created a macro named 01_Toggle Power so it would be at the top of the macro list. This is where we ran into an issue. What we wanted to use in the power off section was M81 S1 (wait for all thermostatic fans to cool), followed by M999. What we experienced is that the M999 would immediately reboot the system not allowing M81 S1 to process and properly cool the hot end. So as a workaround, we added the while loop, but note that it is currently set to only monitor a single extruder set as Tool1.

    if boards[0].vIn.current > 23
      M291 S3 R"Turn off power?" P"Are you sure you want to turn off power?"
      M0				; unconditional stop
      if heat.heaters[1].current > 60
        M291 S1 R"Please Wait" P"Waiting on hot end to cool before turning off power"
        while heat.heaters[1].current > 60
          G4 P1			; continuous loop until hot end has cooled (workaround for M81 S1 issue)
        M999			; soft-reset the system to reload config.g
        M999			; soft-reset the system to reload config.g
      M80				; turn on 24v power supply
      G4 P1000			; wait for power to stabilize
      M98 P"config.g"		; reprocess config.g

  • FYI - I've decided to wait on the introduction of variables before moving forward with this.. there are a few scenarios that just can't be covered without them. I'll pick this back up as soon as they are made available and provide a more robust script.

  • Have you considered moving your power-on config into a "config-on.g" to avoid having to indent everything and messing that up, calling it with M98?

  • @oliof that's a good idea and would be easy to implement.. I have a lot of ideas to add into this before calling it complete, but just haven't revisited until variables are made available. However, I did think about beefing it up through a custom execonmcode script for the time being..

Log in to reply