Using same momentary switch to power on and off
-
I have
Duet 3 with RRF3.3
24v PSU
RPI4 powered off of it's own power supply
A momentary on/off button
5v relay
5v PSU to provide Duet3 PS_ON 5vThe RPI is always on. When the 24v PSU is off the Duet 3 is in standby mode.
I can power the Duet 3 on and off with the ATX buttons in DWC.The momentary button is wired to an IO port configured as an external trigger. When the button is pressed it sends M80 to turn the printer on. PS_ON grounds the relay switching the 24v PSU on.
My hope was to quick press the button to send M80 and long press to send M81. I've tried configuring G code meta commands but with no luck.
config.g
M950 J1 C"0.io3.in" ; Create GPIO pin for On button wired NO M581 T2 P1 S1 R0 ; T2-Run Trigger 2; P1-J1; S1-When button pressed; R0-trigger any time
"trigger2.g" I configured trigger2 to run a macro because I can run Macro files directly from DWC, it's easier for troubleshooting.
M98 P"/macros/Power On"
"Power On" macro
M291 P"Powering on" S1 T2 ; M80 ; Power on G4 S3 if sensors.gpIn[1].value = 1 ; check if button still pressed M291 P"Power off" S1 T2 ; M81 ; turn off power
-
@dhusolo In other applications, I used to use a double throw relais with a momentary switch.
When the relais gets activated, the second circuit keeps up the GND connection, even when I release the button.
I guess it's called self-holding or self entertaining.
When I pushed the button again, I also interupt the secondary GND connection. Then, when I release the button , the relais falls OFF.//edit my memory must've fooled me: I tried to find schematics, but they all use two buttons?!
-
@o_lampe
I guess, you'd also need an RS-flipflop or a macro expression of it.
Everytime you push the button, a boolean variable changes state ( output != output) -
-
@dc42 That worked perfectly! Thanks