First time using buttons

As @jbudd and myself said, there is no need for resistors until you want to connect to a physical button. You just need to tell the node what you want it to do.

image

Note the instruction to tell it to use an (internal) pullup.

1 Like

That sounds like you are using the TTL Receive pin, probably not the best choice.

Try and stick to using the pins with a green dot in this table jbudd linked https://pinout.xyz/

Configure the node as shown by Colin and you should find the random activation stops.

Okey, it seems that my button one is stable now.
and button 3,4 and 5 are also stable.

Last challenge left is button 2.
What I need it to check is if any relay 2,3 or 4 is on, if any is on then turn all of them off.
If all are off, then turn all on.
Only I dont know how to make the relay state part of a check. I mean it feels like a if this then that but I dont know how to accomplish that or with what node.

ill use that layout. Just need to figure out how to get the correct resistors before I hook up any physical buttons. My default electronic shop is out of business, so I have to find a new one.

okey, so it seems the relay is not accepting the command thats coming out of the function.
{"relay2":1,"relay3":1,"relay4":1}
maybe there is a way to split this output op so it can directed as a 1 or 0 value to the relays.
I also notice that the function is not checking or ignoring the relay state. every time I press button two is either {"relay2":1,"relay3":1,"relay4":1} or {"relay2":0,"relay3":0,"relay4":0}

Change the function so that it has four outputs, one for each gpio pin.

I can give it 3 outputs no problem, but Im still stuck on the function node that needs to check the status, let alone send different commands to different outputs.
I am asking anyone in my network, but havent found anyone that can help me with the code.
Its the last button I need to get working, the rest work.

Ive read though the document multiple times. I cant figure out how to get that last button work. Every code just flips all to on or off but no checking is taking place. Ive added the set var value in the normal button functions, but I have no way to check if the value is actually being set and I dont know how to summen that value in the function 2.

I am in the process of making something similar, so here is my offer.

[{"id":"7d251d22c0032334","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"b24a0d3014627bee","type":"junction","z":"7d251d22c0032334","x":660,"y":160,"wires":[["914b35805c25e1ed","10f1beba0c2fc18e"]]},{"id":"85d29c2682d59b78","type":"junction","z":"7d251d22c0032334","x":660,"y":260,"wires":[["37d367a30a521bba","59db5799d8ed456a"]]},{"id":"a1c2df78836eb44d","type":"junction","z":"7d251d22c0032334","x":660,"y":360,"wires":[["b23f88a8d5b95d85","6cf9d9782da9d32f"]]},{"id":"86ebd135637bc771","type":"junction","z":"7d251d22c0032334","x":380,"y":440,"wires":[["c6712ee6195f2f35"]]},{"id":"ea5f10c9de9df017","type":"junction","z":"7d251d22c0032334","x":400,"y":200,"wires":[["c6712ee6195f2f35"]]},{"id":"c6712ee6195f2f35","type":"function","z":"7d251d22c0032334","name":"function","func":"let msg1 = {}\nlet msg2 = {}\nlet msg3 = {}\n\nlet Relay2 = flow.get('Relay2') ?? 0\nlet Relay3 = flow.get('Relay3') ?? 0\nlet Relay4 = flow.get('Relay4') ?? 0\n\nconst invar = msg.payload\nnode.status(invar)\n\nswitch (invar) {\n\n    case 'relay2':\n        Relay2 = Relay2 ^ 1\n        break\n\n    case 'relay3':\n        Relay3 = Relay3 ^ 1\n        break\n\n    case 'relay4':\n        Relay4 = Relay4 ^ 1\n        break\n\n    case 'toggle':\n        if(Relay2 || Relay3 || Relay4) {\n            Relay2 = 0; Relay3 = 0; Relay4 = 0\n        } else {\n            Relay2 = 1; Relay3 = 1; Relay4 = 1\n        }\n        break\n\n    case 'Reset':\n        Relay2 = 0; Relay3 = 0; Relay4 = 0\n        break\n\n}\n\nflow.set('Relay2', Relay2)\nflow.set('Relay3', Relay3)\nflow.set('Relay4', Relay4)\n\nmsg1.payload = Relay2\nmsg2.payload = Relay3\nmsg3.payload = Relay4\n\nreturn [msg1, msg2, msg3]\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":260,"wires":[["b24a0d3014627bee"],["85d29c2682d59b78"],["a1c2df78836eb44d"]],"info":"// nrlint function-eslint:off\n"},{"id":"10f1beba0c2fc18e","type":"debug","z":"7d251d22c0032334","name":"Relay2","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":140,"wires":[]},{"id":"59db5799d8ed456a","type":"debug","z":"7d251d22c0032334","name":"Relay3","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":240,"wires":[]},{"id":"6cf9d9782da9d32f","type":"debug","z":"7d251d22c0032334","name":"Relay4","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":340,"wires":[]},{"id":"5aab6e1218f93d3c","type":"rpi-gpio in","z":"7d251d22c0032334","name":"Button 1gp(17)","pin":"17","intype":"down","debounce":"25","read":false,"bcm":true,"x":120,"y":80,"wires":[["8d95399650789b0e"]]},{"id":"8d95399650789b0e","type":"trigger","z":"7d251d22c0032334","name":"400ms","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"400","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":370,"y":60,"wires":[["e07a05aa38b1db0c","7bb6b7867873c612","86d150aa0531a3e5"]]},{"id":"b2d412737bc9a911","type":"inject","z":"7d251d22c0032334","name":"Button 1","props":[{"p":"payload"},{"p":"Repeat","v":"none","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"flow","x":120,"y":40,"wires":[["8d95399650789b0e"]]},{"id":"e07a05aa38b1db0c","type":"rpi-gpio out","z":"7d251d22c0032334","name":"Relay1(22)","pin":"22","set":false,"level":"0","freq":"","out":"out","bcm":true,"x":690,"y":80,"wires":[]},{"id":"7bb6b7867873c612","type":"debug","z":"7d251d22c0032334","name":"debug 263","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":660,"y":40,"wires":[]},{"id":"86d150aa0531a3e5","type":"function","z":"7d251d22c0032334","name":"All ON","func":"if(msg.payload === '1') {\n    flow.set('Relay2', 1)\n    flow.set('Relay3', 1)\n    flow.set('Relay4', 1)\n}\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":160,"wires":[["ea5f10c9de9df017"]]},{"id":"914b35805c25e1ed","type":"rpi-gpio out","z":"7d251d22c0032334","name":"Relay2(16)","pin":"16","set":"","level":"0","freq":"","out":"out","bcm":true,"x":830,"y":180,"wires":[]},{"id":"37d367a30a521bba","type":"rpi-gpio out","z":"7d251d22c0032334","name":"Relay3(18)","pin":"18","set":"","level":"0","freq":"","out":"out","bcm":true,"x":830,"y":280,"wires":[]},{"id":"b23f88a8d5b95d85","type":"rpi-gpio out","z":"7d251d22c0032334","name":"Relay4(23)","pin":"23","set":"","level":"0","freq":"","out":"out","bcm":true,"x":830,"y":380,"wires":[]},{"id":"981e6c19b83125a7","type":"inject","z":"7d251d22c0032334","name":"Reset","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"Reset","payloadType":"str","x":290,"y":200,"wires":[["ea5f10c9de9df017"]]},{"id":"f784959592a7c514","type":"rpi-gpio in","z":"7d251d22c0032334","name":"Button 3gp(13)","pin":"13","intype":"down","debounce":"25","read":false,"bcm":true,"x":120,"y":360,"wires":[["82025b33bf7e2aee"]]},{"id":"86ea5712e87f1646","type":"rpi-gpio in","z":"7d251d22c0032334","name":"Button 2gp(6)","pin":"6","intype":"down","debounce":"25","read":false,"bcm":true,"x":110,"y":260,"wires":[["3b13d16d9cf2dd2e"]]},{"id":"fa0f13b192fa7381","type":"rpi-gpio in","z":"7d251d22c0032334","name":"Button 4gp(19)","pin":"19","intype":"down","debounce":"25","read":false,"bcm":true,"x":120,"y":460,"wires":[["a5b323ebee1906b2"]]},{"id":"3b13d16d9cf2dd2e","type":"function","z":"7d251d22c0032334","name":"On or OFF","func":"if(msg.payload === 1) {\n    msg.payload = 'toggle'\n}\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":240,"wires":[["c6712ee6195f2f35"]]},{"id":"50d4ea272bec4f90","type":"inject","z":"7d251d22c0032334","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":220,"wires":[["3b13d16d9cf2dd2e"]]},{"id":"82025b33bf7e2aee","type":"function","z":"7d251d22c0032334","name":"Relay2","func":"if(msg.payload === 1) {\n    msg.payload = 'relay2'\n}\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":340,"wires":[["c6712ee6195f2f35"]]},{"id":"a5b323ebee1906b2","type":"function","z":"7d251d22c0032334","name":"Relay3","func":"if(msg.payload === 1) {\n    msg.payload = 'relay3'\n}\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":440,"wires":[["86ebd135637bc771"]]},{"id":"85ba8216522c19a3","type":"inject","z":"7d251d22c0032334","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":420,"wires":[["a5b323ebee1906b2"]]},{"id":"2365266e3cbf4c50","type":"inject","z":"7d251d22c0032334","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":320,"wires":[["82025b33bf7e2aee"]]},{"id":"2784e7b5f4930f88","type":"inject","z":"7d251d22c0032334","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":520,"wires":[["de1376f44c2e3cc0"]]},{"id":"986e3c70dd43edd4","type":"rpi-gpio in","z":"7d251d22c0032334","name":"Button 5gp(26)","pin":"26","intype":"down","debounce":"25","read":false,"bcm":true,"x":120,"y":560,"wires":[["de1376f44c2e3cc0"]]},{"id":"de1376f44c2e3cc0","type":"function","z":"7d251d22c0032334","name":"Relay4","func":"if(msg.payload === 1) {\n    msg.payload = 'relay4'\n}\n\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":540,"wires":[["86ebd135637bc771"]]}]
1 Like

way better then my attempt!
Button 2gp(6) seems to have some trouble. But thank you so much for giving this. Its very helpfull.
I did not think this would be such a challenge when I started.

I dont follow the toggle command.
it seems to envoke relay 3 but relay 3 seems to ignore the command,
also on a fresh deploy the Button 2gp(6) seems to trigger a loop

toggle command, if one of the relays is active, all will turn off, otherwise they will turn on.

Try disconnecting your inputs and see if that makes a difference. Perhaps there are problems with one of the inputs.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.