The Wave Shield uses 8 pins, and the shift registers will need another 3. The 4x3 keypad takes up 7 pins, plus the 2 I2C pins needed for the RTC. I realised I was going to run out of pins so I purchased the MCP23017 from Adafruit with the intention of connecting the keypad to it.
I was able to get it working with buttons and LEDs using I2C, even with the RTC connected at the same time to the same pins (both on different addresses, of course). However the Arduino Keypad library doesn't support I2C out of the box, and my attempts at creating a modified keypad library were unsuccessful.
I found several forum topics on here pointing users to this I2C Keypad library for Arduino:
https://github.com/joeyoung/arduino_keypads
This is where I'm stuck, I haven't been able to get it working with the MCP23017, it's designed for the MCP23016. I was under the impression the 016 wasn't too different to the 017, I even tried changing the definitions in the library to match but that was unsuccessful too.
Here's how far I got with that:
Code: Select all
// New Code
#define GP0 0x12 //MCP23017 GPIO reg
#define GP1 0x13 //MCP23017 GPIO reg
#define IODIR0 0x00 //MCP23017 I/O direction register
#define IODIR1 0x01 //MCP23017 I/O direction register
#define IOCON0 0x0A //MCP23017 I/O configuration register
#define IOCON1 0x0B //MCP23017 I/O configuration register
// original Code
/*#define GP0 0x00 //MCP23016 GPIO reg
#define GP1 0x01 //MCP23016 GPIO reg
#define IODIR0 0x06 //MCP23016 I/O direction register
#define IODIR1 0x07 //MCP23016 I/O direction register
#define IOCON0 0x0a //MCP23016 I/O configuration register
#define IOCON1 0x0b //MCP23016 I/O configuration register*/
So my project has ground to a halt until I can figure this out. I've posted my request on the Github repository for the library, but I'm not confident I'll get a response (it looks dead quiet there).
I believe these are my options:
- Hope that the developer releases an update
- Ditch the MCP23017 and find an alternative which has a keypad library (PCF8574, PCF8575, MCP23008, MCP23016)
- Buy an Arduino Mega with more pins (preferably not )
- Write my own code for reading the keypad over I2C without all the benefits of the Arduino keypad library
- See if anyone here has any other ideas (or knows how to fix the library)
Thanks!