Problems when using 2 Keypads with i2ckeypad Library.

Hello,

I have 2 x 4x4 Keypads that are connected to two Seperate PCF8574AP Chips. Each set to a different address.

I’m using this library:
http://arduino.cc/playground/Main/I2CPortExpanderAndKeypads

The Library works perfectly fine when using only one instance (One Keypad).

At first I couldn’t get the library to work at all with two instances. So I made a small modification to the Library as follows:

Changed (i2ckeypad.h):

private:
  void pcf8574_write(int, int);
  int pcf8574_byte_read(int);
};

TO (i2ckeypad.h):

private:
  void pcf8574_write(int, int);
  int pcf8574_byte_read(int);
  int pcf8574_i2c_addr;
};

Then in “i2ckeypad.cpp”, I commented out the line:

// PCF8574 i2c address
// int pcf8574_i2c_addr;

It now works “somewhat” with two instances.

i am now able to access both keypads, however under the serial monitor, when I press a key once, the key is displays over 20 times per keypress. It should only display each keypress once.

I also noticed if I add a 30ms delay between the checking the two instance, the amount of times it shows in the serial monitor is cut down from 20 to about 5 displays per keypress.

I have attached a zip file with the modified library and a working (One Instance) and non-working (Two Instances) example sketch as well as pictures of the Serial Terminal Output.

Does anybody have any idea how to fix this issue?

i2ckeypad.zip (70.5 KB)

// Current search row
static int row_select;

// Current data set in PCF8574
static int current_data;

A library shouldn't have static data if you are making multiple instances. It will "remember" the row, and then when you call it for the second keypad, get confused.

I would move both of those into the class.

I got it working by doing what you suggested, plus one other modification.

I had to also move “static int temp_key;” into the class to make it work!
Seems to work good now!