joeyoung / arduino_keypads

arduino libraries for keypad interface on I2C bus
GNU General Public License v3.0
154 stars 102 forks source link

not work for me ? #16

Closed EldritchE closed 1 year ago

EldritchE commented 1 year ago

I connected everything correctly but unfortunately the CustomKeypad example does not work for me. I use PCF8575, I correctly specified the address at 0x20> I connected one button to pins P0 and P6 on the expander, but no effect.

On the serial monitor, I have no reaction to pressing a button.

include

include // GDY120705

include

define I2CADDR 0x20

const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols on the buttons of the keypads char hexaKeys[ROWS][COLS] = { {'0','1','2','3'}, {'4','5','6','7'}, {'8','9','A','B'}, {'C','D','E','F'} }; byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad byte colPins[COLS] = {12, 11, 10, 9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad Keypad_I2C customKeypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR);

void setup(){ Wire.begin( ); // GDY200622 customKeypad.begin( ); // GDY120705 Serial.begin(9600); }

void loop(){ char customKey = customKeypad.getKey();

if (customKey != NO_KEY){ Serial.println(customKey); } }

EldritchE commented 1 year ago

OK ! I found a solution! Actually an error. I did not specify the PCF8575 parameter in object creation :) My mistake.

The code that works correctly with PCF8575 :) looks like this :)

/* @file CustomKeypad.pde @version 1.0 @author Alexander Brevig @contact alexanderbrevig@gmail.com
@description
Demonstrates changing the keypad size and key values.
#
Use with I2C i/o G. D. (Joe) Young Feb 28/12

*/

include

include // GDY120705

include

define I2CADDR 0x20

const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols on the buttons of the keypads char hexaKeys[ROWS][COLS] = { {'0','1','2','3'}, {'4','5','6','7'}, {'8','9','A','B'}, {'C','D','E','F'} }; byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad Keypad_I2C customKeypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR,PCF8575);

void setup(){ Wire.begin( ); // GDY200622 customKeypad.begin( ); // GDY120705 Serial.begin(9600); }

void loop(){ char customKey = customKeypad.getKey();

if (customKey != NO_KEY){ Serial.println(customKey); } }

joeyoung commented 1 year ago

I'm glad you have worked it out, thanks for documenting an easy oversight--I'm sure others share this kind of frustration. I think this issue is now completed, so I'll close it.

joeyoung commented 1 year ago

Missing parameter in object creation.