RepRapFirmware allows you to define external 'triggers' (such as a button press) that will run an associated system macro. This could be for an emergency stop, but can be used for many other purposes, as the GCode commands that are run are held in a macro file for each trigger.
Below are two examples:
These examples have been updated for Duet3 and RRF 3.x.
Buttons for pause, ATX on, disable steppers, home all and reset were required.
Wire the switch in the same way as an endstop. Connect one side of the switch to the GND pin of your chosen IO_x connector (or the negative coming from your power supply), and the other to the IN pin of the IO_x connector.
It is worth noting that IO output pins can be used as inputs, but are only 3.3V tolerant.
For a reset button, on Duet 3 mainboard 6HC there is a 'reset' header near the USB port, with reset and GND pins. On the Duet 3 Mini 5+, the reset pin is on the 12864_EXP2 header, pin 3.
In the example, the following pins could be used :
Connect one side of the switch to a GND pin (or the negative coming from your power supply), and the other to the chosen STP/IN/E#_STOP pin. In the example below, the E#_STOP pins of the expansion header are used.
In the image above, 2P Dupont connectors were used, but only one of the pins has a wire going to it. This is because 1P connectors kept falling off so I put a wire in one side of a 2P connector with just an empty pin in the other side.
In the example, the following pins are used:
Pin 44 forces a reset when shorted to ground, no additional configuration is needed.
M950 is used to define each pin, then M581 configures the trigger. In order to get buttons for pause, home, ATX on, and disable steppers, the following were added to config.g:
; Input/Output M950 J1 C"!io1.in" ; Input 1 uses io1.in pin, inverted M581 P1 S0 T1 R1 ; Pause - built-in, no trigger.g needed M950 J2 C"!io1.out" ; Input 2 uses io1.out pin, inverted M581 P2 S0 T2 R0 ; ATX On - trigger2.g M950 J3 C"!io2.in" ; Input 3 uses io2.in pin, inverted M581 P3 S0 T3 R0 ; Home All - trigger3.g M950 J4 C"!io2.out" ; Input 4 uses io2.out pin, inverted M581 P4 S0 T4 R0 ; Disable Steppers - trigger4.g
; Input/Output M950 J1 C"!^e2stop" ; Input 1 uses e2stop pin, inverted, pullup enabled M581 P1 S0 T1 R1 ; Pause - built-in, no trigger.g needed M950 J2 C"!^e3stop" ; Input 2 uses e3stop pin, inverted, pullup enabled M581 P2 S0 T2 R0 ; ATX On - trigger2.g M950 J3 C"!^e4stop" ; Input 3 uses e4stop pin, inverted, pullup enabled M581 P3 S0 T3 R0 ; Home All - trigger3.g M950 J4 C"!^e5stop" ; Input 4 uses e5stop pin, inverted, pullup enabled M581 P4 S0 T4 R0 ; Disable Steppers - trigger4.g
In RRF 2.x, only M581 is required to set up a trigger. Triggers can only be connected to endstops (X, Y, Z, E#).
In order to get buttons for pause, home, ATX on, and disable steppers, the following were added to config.g:
; Input/Output M581 E2 S1 T1 C1 ; Pause - PIN4/E2_STOP M581 E3 S1 T2 C0 ; ATX On - PIN9/E3_STOP - trigger2.g M581 E4 S1 T3 C0 ; Home All - PIN14/E4_STOP - trigger3.g M581 E5 S1 T4 C0 ; Disable Steppers - PIN19/E5_STOP - trigger4.g
Finally, add macro trigger files to the /sys folder. These are just text files containing the respective commands saved as trigger#.gcode.
;trigger2.g M80 ; ATX ON
;trigger3.g M400 ; Finish current moves G28 ; Home all axes
;trigger4.g M400 ; Finish Current Moves M18 ; Disable Steppers
A spare IO header (Duet 3) or endstop (Duet 2) can be used to trigger a full system reset. Here, an arduino is used to convert the flow sensor signal into an on or off state, for flow or no flow.
Duet 3: Connect Arduino Nano 'status' pin (D3) to the IN pin of your chosen IO connector (eg io1.in), and the Arduino 'GND' pin to the 'GND' pin of the IO connector.
Duet 2: See image below. Connect Arduino Nano 'status' pin (D3) to STP/IN pin of your chosen endstop connector, and the Arduino 'GND' pin to the 'GND' pin of the endstop connector. These are the outer 2 pins of the 3-pin connector.
Duet 2 WiFi/Ethernet boards prior to version 1.04 cannot tolerate voltages on endstop pins of more than 3.3V. Add 4 diodes in series to drop the voltage to 3 ish volts.
All other Duets (Duet 3, Duet 2 WiFi/Ethernet v1.04 and later, Duet 2 Maestro) tolerate voltages of at least 5V on IO/endstop connectors.
Duet 3, RRF 3 M950 J1 C"io1.in" ; Arduino is connected to io1.in pin M581 P1 S1 T0 C0 Duet 2, RRF 3 M950 J1 C"^e1stop" ; Arduino is connected to e1stop pin, pullup enabled M581 P1 S1 T0 C0 Duet 2, RRF 2 M581 E1 S1 T0 C0 ; Arduino is connected to endstop E1
And thats it!!! You can test by unpluging your pump or pinching a line, it should reset within a few seconds.