Controlling an external relay via gcode?
I would like to control a time lapse camera via an external relay that is controlled by a DWF and is triggered momentarily on each layer change.
The duet does not have an extender but the E1 24V output is free if it helps. I can also wire a transistor to a 3.3V output if needed. I prefer not to use mechanical solutions such as the X/Y gantry moves and presses a button.
Any suggestion for the wiring (simpler is better) and the gcode?
bearer last edited by bearer
Just connect it to the E1 heade or terminal. It provides fixed 24v and switched GND, do make sure to add a flyback diode or check if the relay has it built in.
(Edit: Do you need the relay? If what you're controlling has a active low input with a pull up, you could use the E1- and GND without a relay, which is by far the most common interface as it does away with logic levels interfacing)
Do you need the relay?
I plan to use this approach https://www.robotroom.com/Macro-Photography-2.html which requires connecting a 2k resistor between two wires.
Small signal relays generally make much less noise than large current relays, but if you want to make it less audible, reed relays are even quieter, and waste less power, at the expense of well, expense.
@bearer, I am thinking this small relay and a diode on a small PCB
I tried the resistor based remote trigger using a manual switch and a Panasonic camera and it does work. It needs 2 resistors, ~30K in normal state and ~2K when pressed.
I tried to write gcode to trigger a pulse on the E1 (Heater2? Pin 16?) output but am getting an error message. The code is:
M42 P16 S255 ; Extruder E1 24V G4 P20 ; Delay 20ms M42 P16 S0 ; Extruder E1 0V
And the error message is:
M98 P"0:/macros/camera_click" Error: M42: Logical pin 16 is not available for writing Error: M42: Logical pin 16 is not available for writing
Any suggestion what the problem is? Do I need to somehow configure the heater in config.gcode?
My config.gcode is
; Configuration file for Duet WiFi (firmware version 1.21) ; executed by the firmware on start-up ; ; generated by RepRapFirmware Configuration Tool v2 on Mon Mar 18 2019 21:06:52 GMT-0700 (Pacific Daylight Time) ; General preferences G90 ; Send absolute coordinates... M83 ; ...but relative extruder moves M667 S1 ; Select CoreXY mode ; Network M550 P"CoreXY" ; Set machine name M551 P"reprap" ; Set password M552 S1 ; Enable network ;*** Access point is configured manually via M587 M586 P0 S1 ; Enable HTTP M586 P1 S1 ; Enable FTP M586 P2 S1 ; Enable Telnet ; Drives M569 P0 S1 ; Drive 0 goes forwards M569 P1 S1 ; Drive 1 goes forwards M569 P2 S1 ; Drive 2 goes forwards M569 P3 S1 ; Drive 3 goes forwards M350 X16 Y16 Z16 E16 I1 ; Configure microstepping with interpolation M92 X200.00 Y200.00 Z400.00 E415.0 ; Set microsteps per mm ; Based on: ; https://forum.duet3d.com/topic/8689/extruder-acceleration-jerk-and-tuning/2 M98 P"/sys/mode_normal.g" M203 X15000 Y15000 Z3000 E15000 ; Set maximum speeds (mm/min) M204 P1000 T3000 ; Set printing and travel accelerations ;M906 X1000 Y1000 Z1000 E1000 I30 ; Set motor currents (mA) and motor idle factor in per cent M906 X1500 Y1500 Z1500 E1000 I30 ; Set motor currents (mA) and motor idle factor in per cent M84 S30 ; Set idle timeout (secs) ; Axis Limits ; Setting a negative Z limit to allow room for babystepping. ;M208 X-5 Y-15 Z-3 S1 ; Set axis minima (home at min X,Y) ;M208 X300 Y300 Z285 S0 ; Set axis maxima M208 X-2:300 Y-5:300 Z-3:285 ; XYZ min/max ; Endstops M574 X1 Y1 S3 ; X min, Y min, stall style endstops M915 X Y S3 F0 R0 ; Stall detection. Higher S value -> less sensitive ; Z-Probe M574 Z1 S2 ; Set endstops controlled by probe M307 H3 A-1 C-1 D-1 ; Disable heater on PWM channel for BLTouch ; NOTE: the T value determines also the x/y movement speed of the ; leveling macro (which uses G30 commands) ; ; TODO: add B1 parameter to turn off bed while probing to reduce magnetic field that ; may affect BlTouch. ; ; TODO: see M588 param recomendation at https://duet3d.dozuki.com/Wiki/BLTouch_Troubleshooting ; M558 P9 H3 F120 T12000 ; Set Z probe type to bltouch and the dive height + speeds ; See http://www.sublimelayers.com/2017/05/fdffsd.html ; To apply babysteps value, SUBSTRACT it from the Z value here. ; (to raise head -> lower Z value here) ; (to lower head -> raise Z value here) ;G31 P500 X20.5 Y12.9 Z1.400 ; Set Z probe trigger value, offset and trigger height ;G31 P500 X23.5 Y22.9 Z1.500 ; Set Z probe trigger value, offset and trigger height G31 P500 X20.5 Y12.9 Z1.450 ; Set Z probe trigger value, offset and trigger height ; Heaters M305 P0 T100000 B4138 R4700 ; Set thermistor + ADC parameters for heater 0 M143 H0 S120 ; Set temperature limit for heater 0 to 120C M305 P1 T100000 B4138 R4700 ; Set thermistor + ADC parameters for heater 1 M143 H1 S280 ; Set temperature limit for heater 1 to 280C ; Fans M106 P0 S0 I0 F500 H-1 ; Set fan 0 value, PWM signal inversion and frequency. Thermostatic control is turned off M106 P1 S1 I0 F500 H1 T45 ; Set fan 1 value, PWM signal inversion and frequency. Thermostatic control is turned on ; Tools M563 P0 D0 H1 ; Define tool 0 G10 P0 X0 Y0 Z0 ; Set tool 0 axis offsets G10 P0 R0 S0 ; Set initial tool 0 active and standby temperatures to 0C ; Leveling ;M671 X26:266:266:26 Y29:29:269:269 P0.7 ; positions of adjustment screws ;M671 X29:269:269:29 Y39:39:279:279 P0.7 ; positions of adjustment screws M671 X29:29:269:269 Y279:39:39:279 P0.7 ; positions of adjustment screws M557 X23:279 Y30:286 S32 ; Define mesh grid ; Bed temp PID autotune ; To autotune send [M303 H0 P1.0 S60]. Check progress with [M303]. when stage 4 done, ; send [M307 H0] and enter results below. ; ; Heater 0 model: gain 64.1, time constant 277.0, dead time 3.2, ; max PWM 1.00, calibration voltage 24.2, mode PID, inverted no, frequency default ; Computed PID parameters for setpoint change: P239.7, I8.026, D540.3 ; Computed PID parameters for load change: P23 ; M307 H0 A64.1 C277.0 D3.2 V24.2 B0 ; Hotend temp PID autotune ; To autotune send [M303 H1 P1.0 S230]. Check progress with [M303]. when stage 4 done, ; send [M307 H1] and enter results below. ; ; Heater 1 model: gain 549.5, time constant 234.0, dead time 4.7, ; max PWM 1.00, calibration voltage 24.1, mode PID, inverted no, frequency default ; Computed PID parameters for setpoint change: P16.3, I0.495, D53.2 ; Computed PID parameters for load change: P16. ; M307 H1 A549.5 C234.0 D4.7 V24.1 B0 ; Set pressure advance factor, per results of pressure advance calibration script. ; Optimal value for PLA is 0.5. May be overriden in slicer gcode scripts. M572 D0 S0.5 ; set K-factor (from calibration script) ;M572 D0 S0.3 ; set K-factor ; Automatic saving after power loss is not enabled ; Custom settings are not configured T0 ; select extruder
Maybe you need to unconfigure the heater first
M307 H2 A-1 C-1 D-1? and are you sure youre using the correct pin number, try
M42 P2 S1?
@bearer, tried this code
M307 H2 A-1 C-1 D-1 ; Disable E1 PWM M42 P16 S1 ; Heater E1 on G4 P20 ; Delay 20ms M42 P16 S0 ; Heater E1 off
And am still getting 'M42: Logical pin 16 is not available for writing'.
I assume that E1 output is HEATER2 which is listed as pin 16 here https://duet3d.dozuki.com/Wiki/Duet_2_Pinout_table . Firmware version is 2.03beta2 (2019-02-16b1) and I have no expansion board.
try M42 P2 S1
Bingo! P2 does controls the E2 output.
According to https://duet3d.dozuki.com/Wiki/Duet_2_Pinout_table pin #2 is Y_STOP so obviously I looked at the wrong table instead of the one here https://duet3d.dozuki.com/Wiki/Using_servos_and_controlling_unused_IO_pins
Everything is working now and here is my first timelapse, ever.
Nice, glad you got it working. That video was so much more relaxing to watch than the mess where everything bounces around.
Two thumbs up!