RobTillaart / I2CKeyPad8x8

Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575.
MIT License
11 stars 1 forks source link

Unable to interface 4x4 keypad. #7

Closed chetan1836 closed 3 weeks ago

chetan1836 commented 4 weeks ago

I'm trying to interface 4x4 keypad with pcf8575, I'm having trouble with pins and also with code. Can anyone assist me. Thanks.

RobTillaart commented 4 weeks ago

As I am rather busy (projects), better ask it on the Arduino Forum. Might takes several days before I can dive into thsi.

Note that for a 4x4 you better use the - https://github.com/RobTillaart/I2CKeyPad

chetan1836 commented 4 weeks ago

Thank you for your response. Does this https://github.com/RobTillaart/I2CKeyPad works with pcf8575.

RobTillaart commented 4 weeks ago

(not tested) You need to connect only 4 rows and 4 columns if you want to use a PCF8575. The other rows / columns should not be connected.

chetan1836 commented 4 weeks ago

I tried r1-r3 to p0 to p3 and c1 - c3 to p4 - p7. It's printing code (17) which means fail. Can you help me with wiring. Thanks.

RobTillaart commented 4 weeks ago

Does this https://github.com/RobTillaart/I2CKeyPad works with pcf8575.

No with the PCF8574

RobTillaart commented 4 weeks ago

It's printing code (17) which means fail. Can you help me with wiring. Thanks.

That is not correct (probably bug in documentation

#define I2C_KEYPAD8x8_FAIL                65
RobTillaart commented 4 weeks ago

FYI, indeed a documentation bug, created a develop branch with a fix.

RobTillaart commented 4 weeks ago

I tried r1-r3 to p0 to p3 and c1 - c3 to p4 - p7.

So do you get other values than 17 (which isn't fail) from your setup?

chetan1836 commented 4 weeks ago

No, it just prints 17 continuously and it doesn't take any keypad inputs. Can you help me with the wiring.

RobTillaart commented 4 weeks ago

use the I2CKeyPad8x8 library and connect the PCF8575 I2C to your board. Be sure to use appropriate pull up resistors

1) disconnect the keypad completely 2) run I2Ckeypad8x8_demo01.ino

It should only print its filename (+ path)

Then connect PCF8575 IO pin 0 to IO pin 8 with a wire, just to simulate a keypress.

What do you get?

RobTillaart commented 4 weeks ago

Then connect IO pin 0 to pin 9,10,11,12,13,14,15 This should give you different key values

chetan1836 commented 4 weeks ago

I'll try what you suggested and tell you how it goes tomorrow. Thanks for your help!

chetan1836 commented 4 weeks ago

use the I2CKeyPad8x8 library and connect the PCF8575 I2C to your board. Be sure to use appropriate pull up resistors

1. disconnect the keypad completely

2. run I2Ckeypad8x8_demo01.ino

It should only print its filename (+ path)

Then connect PCF8575 IO pin 0 to IO pin 8 with a wire, just to simulate a keypress.

What do you get?

There seems to be a problem with my PCF8575. Even when no keypad is connected, it still prints values (see attachment). I've used pull-up resistors, by the way.

image

RobTillaart commented 4 weeks ago

You only need pull ups on the I2C lines not on the PCF8575 IO lines.

64 = I2C_KEYPAD8X8_NOKEY so that part looks a bit promising.

chetan1836 commented 4 weeks ago

Yes, I've connected pull-up resistors to the I2C lines only, not to the I/O lines. Then I tried shorting IO pin 0 to pin 9, 8, 10. It is showing different values.

RobTillaart commented 4 weeks ago

Then I tried shorting IO pin 0 to pin 9, 8, 10. It is showing different values.

That are probably successful keypresses, when e.g. 0 connects 9 the value should be stable. The difference in value between connecting 9 or 10 should be 1 or 8. Can you confirm?

chetan1836 commented 4 weeks ago

When P00 is connected to P10, it shows 0. For P11, it shows 8; for P12, it shows 16; and for P13, it shows 24. I can confirm that the values are stable when connected.

RobTillaart commented 4 weeks ago

So that looks like the library is working as it should. It does not explain why there are FAIL's repeatedly.

If you now reconnect the 4x4 keypad rows to P00..P03 and columns to P08..P11 Does it give stable values?

chetan1836 commented 4 weeks ago

My board doesn't have P08, P09 and P10. I've attached the image. image

RobTillaart commented 4 weeks ago

OK, rows to P00-P03 columns to P10-P13

chetan1836 commented 4 weeks ago

The keypad is working and shows different values for different key presses. How can I load a keymap for this? Thanks.

RobTillaart commented 4 weeks ago

something like this (to be elaborated)


// global variable
char km[65] ;

I2CKeyPad8x8  keypad(...);

void setup()
{
  ...
  //  configure the keymap
  km[0] = '1';
  km[8] = '2';
  // etc;
  // load the keymap.
  keypad.loadKeyMap(km);
  ...
}
chetan1836 commented 4 weeks ago

Thanks for the code. I used the keymap example from your 4x4 Keypad library. It is working, but the issue is that whenever a key is pressed and held, it shows some random values that are not present in the keymap. Please see the attachment. Thanks.

image

Update: I'm using the key as an index value for the keymap, and now it is working fine. I have one more question: is it possible to use the remaining I/O pins for other functions like controlling Led's and stuff?

RobTillaart commented 4 weeks ago

I have one more question: is it possible to use the remaining I/O pins for other functions like controlling Led's and stuff?

Good question, think you need to modify the library for that as the lib uses all pins to efficiently scan an 8x8 matrix.

Thinking out loud, I expect you need to mask the rows and columns so the current algorithm only takes the half of the bits into account. Not tested.

chetan1836 commented 4 weeks ago

I think I'll leave those pins unused for now. Thank you so much for your incredible support and contributions. Your expertise and assistance have been invaluable, and I truly appreciate the time and effort you've put into helping me. You've made a significant difference in the success of this project, and I'm deeply grateful. You can close this issue.

RobTillaart commented 3 weeks ago

An experiment you could try is to use the I2CKeyPad library for the PCF8575. As the PCF8574 and 75 are quite alike it might be possible to use only P00-P07 for the keypad. This could leave the P10-P17 free to use without interference.


if you have loaded the keyMap, you should use the getChar() function, this does the lookup fot you. See documentation.

RobTillaart commented 3 weeks ago

As problem is solved, the issue is closed. Feel free to add comments if needed.