Node-RED gpio switch state

I'm trying to switch a gpio pin from Low to staying High and switch it back Low with the same signal.
but i cant keep the pin High

I think you will need to give us some more information. What do you mean by 'switching it back low with the same signal.
Once you write it high then it should not go low unless you write it low. You can use a debug node watching the value going to the GPIO node to see what you are doing to it.
Do you mean you want to toggle it each time you get a message? If so then search for toggle on the flows site and you may find something that will help. https://flows.nodered.org

This is what i got now not all my nodes but just this part is what im trying to figure out
its meant to keep the pin High when i click the button once and te second time turn it to Low

[{"id":"7c826ce0.128a94","type":"rpi-gpio out","z":"e4d8382f.f4813","name":"","pin":"32","set":true,"level":"0","freq":"","out":"out","x":796,"y":752,"wires":[]},{"id":"2752d3e2.c353cc","type":"ui_button","z":"e4d8382f.f4813","name":"Start IN","group":"1c37e01a.713448","order":4,"width":"3","height":"1","passthru":true,"label":"Start IN","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"str","topic":"","x":282,"y":750,"wires":[["70f30e17.a5976"]]},{"id":"8a2d755e.789e38","type":"inject","z":"e4d8382f.f4813","name":"test","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":96,"y":749,"wires":[["2752d3e2.c353cc"]]},{"id":"70f30e17.a5976","type":"switch","z":"e4d8382f.f4813","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"","vt":"prev"}],"checkall":"true","repair":false,"outputs":1,"x":518,"y":752,"wires":[["7c826ce0.128a94"]]},{"id":"1c37e01a.713448","type":"ui_group","z":"","name":"Mega-IO","tab":"13f7e980.24574f","disp":true,"width":"6","collapse":false},{"id":"13f7e980.24574f","type":"ui_tab","z":"","name":"Slagboom Sim","icon":"dashboard"}]

One of the flows on the link I suggested looks as if it might do exactly that.

I'm sorry im new to coding and on node-red so i dont understand what u mean by that.

could you explain it for dummies please? Thanks in advance

In fact the easiest way to get what you want is probably to use a Dashboard Switch node rather than a Button.

[{"id":"25c61a11.73c016","type":"ui_switch","z":"812d8077.8aadb","name":"Start/Stop","label":"x","group":"536f7750.317da8","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":176.5,"y":983,"wires":[["fb4ce234.75227"]]},{"id":"fb4ce234.75227","type":"debug","z":"812d8077.8aadb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":374.5,"y":1008,"wires":[]},{"id":"80fa8e8a.a7f438","type":"comment","z":"812d8077.8aadb","name":"GPIO Out goes here","info":"","x":393.5,"y":972,"wires":[]},{"id":"536f7750.317da8","type":"ui_group","z":"","name":"Default","tab":"cefe4a16.8f56d8","disp":false,"width":"12","collapse":false},{"id":"cefe4a16.8f56d8","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]
1 Like

Your flow contains a button. Try using a switch that you can turn on and off which might make it easier for a beginner.

Next you need to understand variable types. In your example your button is outputting a string, but your switch expects a number. If it can only be On or Off personally I stick to boolean.
Have a play with an inject node and changing the data type ( the drop down menu next to payload)

Then look on flows.nodered.org and search for flows with "gpio" you may find one of teh examples turns something on and off which would appear to be what you want to do. The above steps should mean you understand what the flow is actually doing.

1 Like