How can I detect if a Raspberry Pi GPIO pin changes?

Node-RED on my Raspberry Pi came installed with the node-red-node-pi-gpio module. It has a [rpi gpio in] object that can read the state of any of the Raspberry Pi GPIO pins.

However, how can I detect when the GPIO pin value changes? (i.e. goes from 0 to 1 or 1 to 0)

I actually need to detect whenever any one of three pins change. When any of them change I need to read the state of all three and then convert it into a number (0 to 6).

I added the function node for checking the pin state using flow context.

Try this flow! :slight_smile:

[{"id":"3c85057d.ccf3c2","type":"rpi-gpio in","z":"149c4183.9f951e","name":"","pin":"11","intype":"tri","debounce":"25","read":false,"x":301,"y":192,"wires":[["8a007729.76fc88"]]},{"id":"85c67717.9cc928","type":"rpi-gpio in","z":"149c4183.9f951e","name":"","pin":"13","intype":"tri","debounce":"25","read":false,"x":300,"y":266,"wires":[["fbaddec3.e2f93"]]},{"id":"8a1b1c0a.fba1d","type":"rpi-gpio in","z":"149c4183.9f951e","name":"","pin":"15","intype":"tri","debounce":"25","read":false,"x":303,"y":351,"wires":[["e649dbcc.689df"]]},{"id":"8a007729.76fc88","type":"function","z":"149c4183.9f951e","name":"Set State","func":"if(!flow.get(\"state1\"))\n flow.set(\"state1\",msg.payload)\n\n\nlet state = flow.get(\"state1\")\nflow.set(\"state1\",msg.payload)\n\nif(state !== msg.payload)\n msg.payload = {isChanged : true}\nelse\n msg.payload = {isChanged :false}\n\nreturn msg;","outputs":1,"noerr":0,"x":507,"y":193,"wires":[["cb72d425.8b936"]]},{"id":"fbaddec3.e2f93","type":"function","z":"149c4183.9f951e","name":"Set State","func":"if(!flow.get(\"state2\"))\n flow.set(\"state2\",msg.payload)\n\n\nlet state = flow.get(\"state2\")\nflow.set(\"state2\",msg.payload)\n\nif(state !== msg.payload)\n msg.payload = {isChanged : true}\nelse\n msg.payload = {isChanged :false}\n\nreturn msg;","outputs":1,"noerr":0,"x":505,"y":269,"wires":[["cb72d425.8b936"]]},{"id":"e649dbcc.689df","type":"function","z":"149c4183.9f951e","name":"Set State","func":"if(!flow.get(\"state3\"))\n flow.set(\"state3\",msg.payload)\n\n\nlet state = flow.get(\"state3\")\nflow.set(\"state3\",msg.payload)\n\nif(state !== msg.payload)\n msg.payload = {isChanged : true}\nelse\n msg.payload = {isChanged :false}\n\nreturn msg;","outputs":1,"noerr":0,"x":508,"y":350,"wires":[["cb72d425.8b936"]]},{"id":"cb72d425.8b936","type":"switch","z":"149c4183.9f951e","name":"Check ","property":"payload.isChanged","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":735,"y":268,"wires":[["8857693c.f0f8d8"]]},{"id":"8857693c.f0f8d8","type":"debug","z":"149c4183.9f951e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":949,"y":266,"wires":[]}]

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