I'm trying to get a 4x4 matrix keypad, connected to a PCF8574A module, to work.
Because this keypad is passive and the PCF8574A needs logic levels, I need to do some magic to read the pressed key. So I searched the good old Internet and came up with this, where the steps are described as follows:
So I created some rules to get the actual pressed key.Finding out which button was pressed is done in two phases: the first phase finds the row, and the second phase finds the column. First phase: scan the row lines and see which line is now low. Second phase: set column lines high and row lines low and see which column line is low (one column line is pulled low by the short circuit in the keypad even though you just set the column lines high).
At boot, all GPIOs on the PCF8574A are in HIGH state. Therefore, my first rule ist this:
Code: Select all
On System#Boot do
pcfgpio,97,0
pcfgpio,98,0
pcfgpio,99,0
pcfgpio,100,0
pcfgpio,101,1
pcfgpio,102,1
pcfgpio,103,1
pcfgpio,104,1
EndOn
Lets assume, the key I press is at column 1 (which is pfcgpio 101 and device K5) and on row 2 (which is pcfgpio 98 and device K2). The rules for this actually read the correct column, but fail at the row. First I set the GPIOs for the columns to HIGH and for the rows to LOW and create an event. As long as the key is pressed, the correct state LOW can be measured at the PCF8574A pin, because the LOW row state pulls the column state also to LOW, even if I did set it to HIGH with the pcfgpio command.
Code: Select all
On K5#Switch do
pcfgpio,97,1
pcfgpio,98,1
pcfgpio,99,1
pcfgpio,100,1
pcfgpio,101,0
pcfgpio,102,0
pcfgpio,103,0
pcfgpio,104,0
Event K5pressed
EndOn
Code: Select all
On K5pressed do
if [K4#Switch]=0
lcd,1, 8, A
endif
if [K3#Switch]=0
lcd,1, 8, B
endif
if [K2#Switch]=0
lcd,1, 8, C
endif
if [K1#Switch]=0
lcd,1, 8, D
endif
pcfgpio,97,0
pcfgpio,98,0
pcfgpio,99,0
pcfgpio,100,0
pcfgpio,101,1
pcfgpio,102,1
pcfgpio,103,1
pcfgpio,104,1
EndOn
Code: Select all
pcfgpio,97,1
pcfgpio,98,0
pcfgpio,99,1
pcfgpio,100,1
pcfgpio,101,0
pcfgpio,102,0
pcfgpio,103,0
pcfgpio,104,0
Code: Select all
pcfgpio,97,0
pcfgpio,98,0
pcfgpio,99,0
pcfgpio,100,0
pcfgpio,101,1
pcfgpio,102,1
pcfgpio,103,1
pcfgpio,104,1
Any idea, how this can be solved, if it's possible at all?
I have seen an effort for getting such a keypad to work in this thread. So maybe some others are interested too?
Thanks,
daniel