Keypad code and questions with keypad hooked to pins

Would like to hook up a keypad to the Pi using the input pins and not USB or serial (which have examples in this forum). I have the keypad hooked up and can see the key presses but I am having the following issues.
I don't seem to be able to detect when a key is pressed so that my code could run. Even if I detect the key press my code doesn't seem to work.
I have a flow with inject nodes and I can use those nodes to detect what key is pressed by turning on and off different pins.
The flow is below and if you crack open the function node there are several sections commented out that I have tried that don't work. I suppose this boils down to two issues.

  1. Detect a keypress - pin changing states to detect when to run code.
  2. How to turn off and on (or take pin high and low) to detect which key was pressed.
    I have to cycle through four pins to be able to detect which key was pressed.
    Any and all thoughts would be appreciated, welcomed, applauded and I would be grateful.
    Thanks
[{"id":"3dc9a7ec.2c1d58","type":"tab","label":"Keypad","disabled":false,"info":""},{"id":"5b557bd6.de3c9c","type":"rpi-gpio in","z":"3dc9a7ec.2c1d58","name":"GPIO 20-38","pin":"38","intype":"tri","debounce":"25","read":true,"x":170,"y":440,"wires":[["1889ba06.14dc1e","26fb9ad3.dce726"]]},{"id":"ca8d8dc.bffc8f","type":"rpi-gpio in","z":"3dc9a7ec.2c1d58","name":"GPIO 21 - 40","pin":"40","intype":"tri","debounce":"25","read":true,"x":170,"y":380,"wires":[["d952b03f.8f9a3","50591fda.001ac"]]},{"id":"9b4457d4.4a69a8","type":"rpi-gpio in","z":"3dc9a7ec.2c1d58","name":"GPIO 12-32","pin":"32","intype":"tri","debounce":"25","read":true,"x":170,"y":500,"wires":[["5d430998.c72a3","ffcd8607.61938"]]},{"id":"d952b03f.8f9a3","type":"function","z":"3dc9a7ec.2c1d58","name":"21","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":380,"wires":[["d02dff4d.314088"]]},{"id":"1889ba06.14dc1e","type":"function","z":"3dc9a7ec.2c1d58","name":"20","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":440,"wires":[["d02dff4d.314088"]]},{"id":"5d430998.c72a3","type":"function","z":"3dc9a7ec.2c1d58","name":"16","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":500,"wires":[["d02dff4d.314088"]]},{"id":"27853807.02ab28","type":"function","z":"3dc9a7ec.2c1d58","name":"14","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":100,"wires":[[]]},{"id":"9e1581ee.c03708","type":"function","z":"3dc9a7ec.2c1d58","name":"15","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":160,"wires":[[]]},{"id":"73c431f9.4add9","type":"function","z":"3dc9a7ec.2c1d58","name":"18","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":220,"wires":[[]]},{"id":"bbe16b99.3e34","type":"function","z":"3dc9a7ec.2c1d58","name":"23","func":"\n\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":280,"wires":[[]]},{"id":"2cdb70f9.c747c","type":"rpi-gpio out","z":"3dc9a7ec.2c1d58","name":"GPIO 14-8","pin":"8","set":true,"level":"1","freq":"","out":"out","x":1090,"y":340,"wires":[]},{"id":"54c21e00.22f534","type":"rpi-gpio out","z":"3dc9a7ec.2c1d58","name":"GPIO 15-10","pin":"10","set":true,"level":"1","freq":"","out":"out","x":1090,"y":400,"wires":[]},{"id":"aab31bc4.57f04","type":"rpi-gpio out","z":"3dc9a7ec.2c1d58","name":"GPIO 18-12","pin":"12","set":true,"level":"1","freq":"","out":"out","x":1090,"y":460,"wires":[]},{"id":"53059eff.01c9d","type":"rpi-gpio out","z":"3dc9a7ec.2c1d58","name":"GPIO 23-16","pin":"16","set":true,"level":"1","freq":"","out":"out","x":1090,"y":520,"wires":[]},{"id":"878c9d6.e5958e","type":"inject","z":"3dc9a7ec.2c1d58","name":"0","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":810,"y":280,"wires":[["2cdb70f9.c747c"]]},{"id":"3507a50f.c9672a","type":"inject","z":"3dc9a7ec.2c1d58","name":"1","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":810,"y":360,"wires":[["54c21e00.22f534"]]},{"id":"155fe75e.c964f9","type":"inject","z":"3dc9a7ec.2c1d58","name":"0","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":810,"y":400,"wires":[["54c21e00.22f534"]]},{"id":"6a83d1f5.58f9a8","type":"inject","z":"3dc9a7ec.2c1d58","name":"1","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":810,"y":460,"wires":[["aab31bc4.57f04"]]},{"id":"a2909f26.c4a908","type":"inject","z":"3dc9a7ec.2c1d58","name":"1","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":810,"y":240,"wires":[["2cdb70f9.c747c"]]},{"id":"437cd9d9.a6fb28","type":"inject","z":"3dc9a7ec.2c1d58","name":"0","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":810,"y":500,"wires":[["aab31bc4.57f04"]]},{"id":"16fd8e79.4ae6e2","type":"inject","z":"3dc9a7ec.2c1d58","name":"1","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":810,"y":560,"wires":[["53059eff.01c9d"]]},{"id":"abb4e0a9.7d40f","type":"inject","z":"3dc9a7ec.2c1d58","name":"0","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":810,"y":600,"wires":[["53059eff.01c9d"]]},{"id":"d02dff4d.314088","type":"function","z":"3dc9a7ec.2c1d58","name":"Logic Node 1","func":"let z = msg.payload;\nlet y = msg.topic;\n\nvar i;\n\n/*\nfor (i = 0; i < 5; i++) {\n    msg1 = {payload: 1};\n    msg2 = {payload: 1};\n    msg3 = {payload: 1};\n    msg4 = {payload: 1};\n    node.send([msg1,msg2,msg3,msg4]);\n} \n*/\n//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nmsg1 = {payload: 0};\nmsg2 = {payload: 1};\nmsg3 = {payload: 1};\nmsg4 = {payload: 1};\nnode.send([msg1,msg2,msg3,msg4]);\n\nif (msg.payload === 0){\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.topic});\n}\n//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nmsg1 = {payload: 1};\nmsg2 = {payload: 0};\nmsg3 = {payload: 1};\nmsg4 = {payload: 1};\nnode.send([msg1,msg2,msg3,msg4]);\n\nif (msg.payload === 0){\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.topic});\n}\n//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nmsg1 = {payload: 1};\nmsg2 = {payload: 1};\nmsg3 = {payload: 0};\nmsg4 = {payload: 1};\nnode.send([msg1,msg2,msg3,msg4]);\n\nif (msg.payload === 0){\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.topic});\n}\n//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nmsg1 = {payload: 1};\nmsg2 = {payload: 1};\nmsg3 = {payload: 1};\nmsg4 = {payload: 0};\nnode.send([msg1,msg2,msg3,msg4]);\n\nif (msg.payload === 0){\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.topic});\n}\n//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n\n\n\n\n//node.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn [null,null,null,null];","outputs":4,"noerr":0,"x":590,"y":440,"wires":[["2cdb70f9.c747c"],["54c21e00.22f534"],["aab31bc4.57f04"],["53059eff.01c9d"]]},{"id":"50591fda.001ac","type":"debug","z":"3dc9a7ec.2c1d58","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":380,"y":320,"wires":[]},{"id":"26fb9ad3.dce726","type":"debug","z":"3dc9a7ec.2c1d58","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":370,"y":560,"wires":[]},{"id":"ffcd8607.61938","type":"debug","z":"3dc9a7ec.2c1d58","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":370,"y":620,"wires":[]},{"id":"7346ab4d.c0e00c","type":"inject","z":"3dc9a7ec.2c1d58","name":"","repeat":".1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":450,"y":280,"wires":[[]]}]

I don't understand exactly what problem you are having. You say

But the you go on to say

Which seems to be saying the opposite. Each time a key is pressed it should send a message. Is that happening? If it is then you haven't explained what you want to do next. Please explain better what you want to achieve as a result of the presses.

yea, seems pretty confusing to me when I reread it.
I have the keypad hooked up and the hardware functions. As we all know there are rows and columns and when you press a key a row connects to the column so you have to know which row and which column to figure out what the key is. I can see the keypad key-press in the editor as the pin goes low There is no dashboard yet until I get the code sorted out. So I see the pin go low in the editor but the function node has no idea to run the code. I put in a bunch of inject nodes so I can manually take each row low to figure out what key is pressed. My columns are held high by resistors and I have to interrogate each row as that is how I wired my setup. You can do it the other way if you want but I chose to hold columns high.
So the hardware works, I can prove that. I can get the key but I have to do it manually which seems counter-productive, hence I need the program to be able to figure out a key was pressed then take each row low to get key number. I have tried using for loops and several different methods but none of my "automatic" ways work.
The end result I need is to be able to get a key number on each key press then from there maybe I can work out the rest. The final product is supposed to be a keyed entry that works an electromagnetic door lock.
Hope this makes it clear as mud.

Post example data and describe what each data is. I don't understand what you are saying but if it's a bit pattern you need to extract bits from then it'll be pretty straight forward.

Press a button, capture the output, repeat for each button, post in a reply.

To summarise, if I understand, you need to know at any time the state of all the inputs at once. To do that you need to join the messages from the buttons into one message. To see how to do that have a look at the cookbook example Joining Streams. Once you have all the input states at once then you can work out which key is pressed.

I'll answer @Steve-Mcl first. It's not a bit pattern but the state of pins. Although I suppose if you could read all the pins at once it would be a pattern but you have to take each one of four pins low individually to figure out which key was pressed.
000 STEP-4-296x300
This is a 16 key and mine is a 12 key but the operation is the same. So I hold each column high by a resistor. When I look at the 3 pins when one of the pins goes low that means a key was pressed. Then I have to look at each row to see which row is low to determine the key press. I set each column high then need to reread the pins to see which pin went low then from there you get the key number.
To get the next key you have to set each column pin high and wait for it to go low.


Again a 16 key but the operation is the same.
So I need to scan the three input pins continuously until one pin goes low. Then I need to scan the four row pins to see which one went low. After getting the column number and the row number you know the key number.
@Colin I will look at the join node and see if I can make that work. Thank you

@Steve-Mcl I'm not sure about the data part. In my flow above the pin is either high or low. I need to be able to detect when the pin goes low then scan the four column pins to see which is low. I suppose I could make the input into the function something like 111, from all three pins and then see if it changes, assuming I knew how to do that. Might be something for me to think on.

No you don't, well not the latter bit anyway. The Join node will send on a message each time any input changes, the message will contain the current state of all the inputs so you don't need to scan anything. You will probably need to debounce the Join node output as you will see the first input change then the second immediately after. You can use a Trigger node to do the debounce, but get the Join node going first.

So I'm on to something here thanks to the guidance so I'll pound on this for a few days and see if I get anywhere and I'll let you know the results.
Thanks

Import the example for the cookbook and make sure you understand how it works.

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