Trouble wiring 3x4 keypad to PCF8574AN

I couldn't figure out the best board to post this into. Sorry if this isn't the correct one.

I'm having trouble getting a 3x4 numeric keypad matrix wired properly to a PCF8574AN i2c I/O expander.

The keypad is the Adafruit one, not the "phone style":

Pinout is this:

So, using this pinout for reference:

And the wiring diagram here, I've wired as follows:
1 -> P5
2 -> P0
3 -> P4
4 -> P3
5 -> P6
6 -> P2
7 -> P1

(first column is pin# on keypad, 2nd # is the pin on the chip). This apparently isn't quite right. I'm using Rob Tillaart's I2CKeyPad.h library. the raw index value returned by keyPad.getKey() is:

1 = 0 (correct)
2 = 1 (correct)
3 = 2 (correct)
4 = 4 (should be 3)
5 = 5 (should be 4)
6 = 6 (should be 5)
7 = 8 (should be 6)
8 = 9 (should be 7)
9 = 10 (should be 8)

  • = nothing (should be 9?)
    0 = 13 (should be 10?)

= 14 (should be 11?)

The code I'm using is basically the same test code he uses, simple and straightforward:

  uint8_t idx = keyPad.getKey();
  if (idx != lastKey & keys[idx] != 'N') {
    Serial.println(idx);
    lastKey = idx;
    }

I've checked my wiring several times so it is what I describe above. I must be misunderstanding something fundamental about the keypad or chip, but I'm not clear how to take the output and translate it to an answer of what is wrong and needs to be fixed.

Let's see

1 = C2 = P5
2 = R1 = P0
3 = C1 = P4
4 = R4 = P3
5 = C3 = P6
6 = R3 = P2
7 = R2 = P1

Check. That is correct.

His library is for a keypad of 4x4. What did you do with P7 ? It think it needs to be open, but I'm not sure.

Can you show the full sketch ? There is a website for that: https://snippets-r-us.com/.
Now I have to guess what you sketch is.

Suppose you have this:

char keys[] = "123A456B789C*0#DNF";  // N = Nokey, F = Fail

Then you have to adapt that for your own keyboard, and put 'N' for the keys that you don't have.
Perhaps this:

char keys[] = "123N456N789N*0#NNF";  // N = Nokey, F = Fail

But that is just a guess, I don't know why there are 18 characters for a 4x4 keypad.

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