Toggle gpio with external trigger on/off/on
-
@OwenD said in Toggle gpio with external trigger on/off/on:
if sensors.gpIn[2].value=0 M42 P2 S1 else M42 P2 S0
Just tried that and that doesn't work either.
-
Then you either found a bug, of your pin is always determined to be 0.
Writing out the value before the if statement with
echo
is probably a good idea to see whats going on.If it always writes out 0 then you either wired something wrong, or it could be the pin has been damaged.
-
@bearer said in Toggle gpio with external trigger on/off/on:
ined to be 0.
If I write M42 P2 S1 or M42 P2 S0 into the console it changes.
echo sensors.gpIn[2].value=0
results in a false, regardless if the M42 P2 is S1 or S0I don't really know what to do next...
-
sensors.gpIn[2] is the same pin as you're setting with M42 P2?
maybe poke around with m409 to see if that should be gpOut or something?
https://duet3d.dozuki.com/Wiki/Gcode#Section_M409_Query_object_model -
@bearer Yes - I'm checking the state of the same pin I want to change depending on the value.
-
Then i suspect you should use sensors.gpOut[2] instead og sensors.gpIn[2] but you can test with m409.
-
@bearer said in Toggle gpio with external trigger on/off/on:
Then i suspect you should use sensors.gpOut[2] instead og sensors.gpIn[2] but you can test with m409.
Thanks - I've ran out of time today but will have a go next time I am in. I actually need to change from the e1 and e0temp pins I'm currently using as I've noticed they toggle on briefly on start up - although not enough current to turn the relay module on but that could change. I can see the GPIO pins on the duex5 but not on the Duet 2. Are those what you were referring too?
-
Whatever pin you define in M950 as output Pn will need to be addressed as sensors.gpOut[n]
(or maybe one is index'ed from 1 and the other 0, but still need to address it as an output i think)
-
@bearer I think my head is a bit clearer today. I don’t know what I was doing last weekend… I wrote
M42 P3 S0
to turn the pin low / off and
M409 K"state.gpOut[3]"
to check the pin state getting this back.
{"key":"state.gpOut[3]","flags":"","result":{"pwm":0}}
I then wrote M42 P3 S1 so the pin was high / on and queried the state again:
M409 K"state.gpOut[3]"
{"key":"state.gpOut[3]","flags":"","result":{"pwm":1.00}}
I then changed my trigger to
If state.gpOut[3].pwm==0 M42 P3 S1 else state.gpOut[3].pwm==1 M42 P3 S0
Thanks again for pointing me in the right direction. I’m going to place the relevant M42 commands into M10.g and M11.g and simplify the trigger file to refer to those.
-
If state.gpOut[3].pwm==0 M42 P3 S1 else state.gpOut[3].pwm==1 M42 P3 S0
condition in else is obsolete, and more "elegant" way is
If state.gpOut[3].pwm != 0 M42 P3 S0 else M42 P3 S1