Conflict between 4x4 KeyPad and LiquidCrystal_PCF8574 ?

Hello,

I have a problem with simultaneous use of "4x4 keypad" together with "2x16 LCD with PCF8574" connected via i2c

I'm trying to use: "Keypad library" together with "LiquidCrystal_PCF8574 library"

I connected my keypad to pins: D2-D8 of my Leonardo and “2x16 LCD” via i2c pins (SDA, SCL).

My code works OK.. till the moment when I use "lcd.begin(16, 2)".. then... half of my keypad stops responding (right part 3..A to #.. D).

It's look like that LiquidCrystal_PCF8574 library to use digital pins ignoring the fact that LCD is connected by i2c.

How can I cope with this situation?

I would be grateful for help.

Greetings,
ML

Any suggestions?

While not obvious, you have pin collisions.

Have a look at the pinout photo for the leonardo and take notice of digital pins 2 and 3 as they are shared with i2c pins.
You will need to use other pins for your keypad.

On a side note, be aware that the LiquidCrystal_PCF8574 library has licensing and copyright issues.
While the library may say it is BSD and the author may really want to use a BSD license, it cannot be licensed this way as it started with some LGPL 2.1+ code and the LGPL 2.1+ license does not allow it or any derivatives from the work be converted to a BSD license.
See here: https://github.com/mathertel/LiquidCrystal_PCF8574/issues/4

Alternate i2c lcd libraries with clean licenses (GPL) are LiquidCrystal_I2C and hd4480.
Both are available in the IDE library manager.
LiquidCrystal_I2C in the library manager should not be confused with the LiquidCrystal_I2C class that comes bundled with fm's newLiquidCrystal library. newLiquidCrystal has similar but even more severe copyright and licensing issues than LiquidCrystal_PCF8574.

LiquidCrystal_I2C is hard coded to work backpacks that use a particular pin wring but since LiquidCrystal_PCF8574 uses the same hard coding mapping, if LiquidCrystal_PCF8574 works for you, LiquidCrystal_I2C should work as well.
Just keep in mind that there are many different backpack designs and only 1 of them works with LiquidCrystal_I2C and LiquidCrystal_PCF8574.

hd44780 includes an i/o class called hd44780_I2Cexp that is for i2c backpacks.
It is more feature rich than LiquidCrystal_I2C. It can auto locate the i2c address and automatically determine the pin mappings/wiring used on the backpack so it can work with any of the backpack designs.

--- bill

Bill,

Thank you for such a comprehensive answer.
I reconnected my keypad to different pins and... all sketch started to operate properly :wink:

Greetings,
M

bperrybap:
While not obvious, you have pin collisions.
https://github.com/Bouni/Arduino-Pinout
Have a look at the pinout photo for the leonardo and take notice of digital pins 2 and 3 as they are shared with i2c pins.
You will need to use other pins for your keypad.

...

--- bill