switching via an unused pin a relay (to drive bigger loads)



  • Hi guys,

    I also would like to switch a load via one of the unused pins that doesn´t switch the load directly but a relay (on a duet2ethernet1.0.4 with RRF3.1.1. for now).

    Also the 1st use-case is also a LED-stripe on/off with a macro directly by g-code or user-interaction (I saw the similar post here https://forum.duet3d.com/topic/19731/led-on-off-macro-or-toogle I decided to make a new one, because I do not want to use e1).

    Why this setup:
    Having a relay in between, gives freedom to use another Voltage, although it costs a bit more. There might be also benefits regarding EMI.


    So first of all which unused pin to use?

    -> I took a look here for the unused IO-Pins: https://duet3d.dozuki.com/Wiki/Using_servos_and_controlling_unused_IO_pins, to get started I would like to take the following one, because there are no "notes":

    Logical pin, Signal name, Expansion connector label, Expansion connector pin number, PWM capable?, Servo capable?, Notes
    60, CS5, CS5, 50, no, no

    And finally double-checking for the pin-name
    https://duet3d.dozuki.com/Wiki/RepRapFirmware_3_overview#Section_Pin_names_for_Duet_2_WiFi_Ethernet

    -> „duex.cs5“ seems to be the „CS5“ from the table above

    To find where it is, we look here https://duet3d.dozuki.com/Wiki/Duet_Wiring_Diagrams
    and click on the picture to open that separate in a window to zoom in
    https://d17kynu4zpq5hy.cloudfront.net/igi/duet3d/4k56ZjaaAHrTJI6Z.huge

    So its location is on the lower left corner of the additionalpins.


    SO NOW THAT WE KNOW:

    • which one we want to take
    • where we find it
    • how it is named in RRF

    WE CAN GO ON HOW TO INTEGRATE IT outlined here https://duet3d.dozuki.com/Wiki/RepRapFirmware_3_overview#Section_GPIO_and_servos:

    1st:
    From RRF3 on, we first have to initialize it with M950, I take a look here https://duet3d.dozuki.com/Wiki/Gcode#Section_M950_Create_heater_fan_or_GPIO_servo_pin, so it should be something like

    M950 P88 C“cs5“ ; From what I understand C must be the exact pin name, & P could be whatever is not taken yet, so just for fun we take 88
    

    (I do not really get it, what it means in the reference by ";M950 command must have exactly one of the H, F, J, P or S parameters
    " any help appreciated, they way I understand it is "must have not more then 1 H, F, J, P/S parameters"?)

    And later in code, the M-command to use those (un-used) IO-pins is M42, I take a look here https://duet3d.dozuki.com/Wiki/Gcode#Section_M42_Switch_I_O_pin, and to change pin-state, the code seems to be:

    M42 P88 S0		; Put Pin P___ to State S___  0=off/low
    M42 P88 S1		; Put Pin P___ to State S___  1=on/high
    

    (I do not get what is written in the reference "P parameter is the GPIO port number, not the logical pin number", so the way I understand it from the table above is that it does not need to be "60"(?) but just needs to be whatever was defined within m950? If somebody know what it means, any help appreciated)
    Is that correct so far?

    The real question I have, is how to use it with 1 macro that toggles it on/off, how to address the pin, is it like this(?):

    if state.gpOut[88].pwm == 0
       M42 P88 S1
    else
       M42 P88 S0
    

    The ".pwm" looks wrong to me, since this pin cannot do pwm, but I guess I have to wait for RRF3.2 for the whole meta-command-structure/-tree to be able to dig into the "reference"?

    Any help appreciated... also hints to wait for RRF3.2, for which I would otherwise wait anyway 🙂


  • Moderator

    @LB said in switching via an unused pin a relay (to drive bigger loads):

    (I do not really get it, what it means in the reference by ";M950 command must have exactly one of the H, F, J, P or S parameters
    " any help appreciated, they way I understand it is "must have not more then 1 H, F, J, P/S parameters"?)

    It means that your M950 must be for EITHER a single (F)an, (H)eater, Input pin (J), Output pin(P)/(S)ervo pin.

    So it depends on what the pin will be used for which of the F/H/J/P/S you would use.

    In M42 the P value must match the pin number you created for it in M950

    So M950 P88 means your must be M42 P88

    The 88 is just an index number and could be any unique number from 0 on up. The important thing is that it matches.

    Have you tested your conditional gcode yet?

    @LB said in switching via an unused pin a relay (to drive bigger loads):

    since this pin cannot do pwm

    I thin that would mean the pin you choose isn't switchable, and not really suitable for switching a relay.


Log in to reply