-
Notifications
You must be signed in to change notification settings - Fork 102
Home
####Welcome to the arduino_keypads wiki!
The arduino_keypads
libraries add I2C I/O to the Keypad library by using
parallel port expander ICs. Different ICs require subtly different versions
of the I2C access functions to remain compatible with the Keypad
base
library. Consequently, several versions of the library have been implemented.
The user should just select the one library that supports the IC that is
included in the system being developed.
Different devices have more or less elaborate I2C access functions, and thus require different numbers of bytes of code space..as the following table indicates.
####Memory use comparisons for Keypad libraries with I2C I/O
May 29, 2014 - G. D. (Joe) Young [email protected]
Using the HelloKeypad
example sketches as being essentially empty of useful
code except for bringing in the Keypad
libraries, the following code sizes
are reported by the arduino 1.05 compilation:
| | HelloKeypad | |
| library | size | I2C devices supported |
| :------: | :-----------: | :------------------- |
|Keypad alone | 4046 bytes | none |
|Keypad_I2C | 6530 |PCF8754, PCF8575, PCF8575C(needs pullups)
|Keypad_I2Ca | 6842 |PCA9554, PCA9555, PCA9534, PCA9539, TCA6408,
| | |TCA6416, others in family (may need pullups)
|Keypad_MCP | 6626 |MCP23008 (pullups needed)
|Keypad_MC16 | 6774 |MCP23016 (pullups needed)
|Keypad_MC17 | 6858 |MCP23017
Adding the I2C I/O adds approx. 2500..2800 bytes to the code space in addition to that already needed for the keypad support.
###HelloKeypad
simple example program using PCF8574 I2C port expander
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#define I2CADDR 0x38
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Digitran keypad, bit numbers of PCF8574 i/o port
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad
Keypad_I2C kpd( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR, PCF8574 );
void setup(){
Serial.begin(9600);
while( !Serial ){ /*wait*/ }
Wire.begin( );
kpd.begin( );
Serial.print( "start with pinState = " );
Serial.println( kpd.pinState_set( ), HEX );
}
void loop(){
char key = kpd.getKey();
if (key){
Serial.println(key);
}
}
Notes:
-need to include the `Keypad_I2C.h` and `Wire.h` with `Keypad.h`
-The constructor is the same as for Keypad, but has two extra arguments, the I2C
address, and the device type
-in setup Wire.begin( ) is added
###Constructor arguments, function reference ####Memory use comparisons for Keypad libraries with I2C I/O