Arduino + multiple MCP2017 + multiple 8x8 Keypad

Hi All,

maybe you can help me to solve my problem. I have expanded Adruino board with 8 numbers of MCP23017 (I2C protocol).
Each chip was supplied with 8x8 keypad.

My Arduino UNO or MEGA can manage only up to 4 no of MCP23017, but Nano <5.
Is it software or hardware limitation or have I done something wrong?

Most of the code is hided in the local libraries for clarity.

Serial.Monitor is just for monitoring the keys pressed.

#include <Keypad_MC17.h>
#include <Keypad.h>
#include <Wire.h>

#include “Tlc5940.h”

#define Adr0 0x20
#define Adr1 0x21
#define Adr2 0x22
#define Adr3 0x23

const byte MXr = 8;
const byte MXc = 8;

char Mk [MXr ][MXc ] = {
{‘A’,‘E’,‘J’,’(’, ‘B’,‘F’,‘K’,’[’ },
{‘a’,‘e’,‘j’,’)’, ‘b’,‘f’,‘k’,’]’ },
{‘1’,‘W’,‘S’,‘N’, ‘2’,‘X’,‘T’,‘P’ },
{‘5’,‘w’,‘s’,‘n’, ‘6’,‘x’,‘t’,‘p’ },
{‘C’,‘G’,‘L’,’{’, ‘D’,‘H’,‘M’,’<’ },
{‘c’,‘g’,‘i’,’}’, ‘d’,‘h’,‘m’,’>’ },
{‘3’,‘Y’,‘U’,‘Q’, ‘4’,‘Z’,‘V’,‘R’ },
{‘7’,‘y’,‘u’,‘q’, ‘8’,‘z’,‘v’,‘r’ }};

byte rP [MXr] = {15,14,13,12,11,10, 9, 8};
byte cP [MXc] = { 7, 6, 5, 4, 3, 2, 1, 0};

Keypad_MC17 MX0=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr0);
Keypad_MC17 MX1=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr1);
Keypad_MC17 MX2=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr2);
Keypad_MC17 MX3=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr3);

#include “relay_var.h”

void setup() {
Serial.begin(9600);
MX0.begin();
MX1.begin();
MX2.begin();
MX3.begin();
Tlc.init();
}

void loop() {
char kM0 = MX0.getKey();
char kM1 = MX1.getKey();
char kM2 = MX2.getKey();
char kM3 = MX3.getKey();

if ((kM0 != NO_KEY) || (kM1 != NO_KEY) || (kM2 != NO_KEY) || (kM3 != NO_KEY))
{
#include “keys_def.h”
#include “serial_scr1.h”
}

#include “relay_def.h”
Tlc.update(); // or “while (Tlc.update());” TBC
}

// I would be happy for any constructive replay.
//Thank you in advance.
//Regards,
//Peter

peterCyp:
Hi All,

maybe you can help me to solve my problem. I have expanded Adruino board with 8 numbers of MCP23017 (I2C protocol).
Each chip was supplied with 8x8 keypad.

My Arduino UNO or MEGA can manage only up to 4 no of MCP23017, but Nano <5.
Is it software or hardware limitation or have I done something wrong?

Most of the code is hided in the local libraries for clarity.

Serial.Monitor is just for monitoring the keys pressed.

#include <Keypad_MC17.h>

#include <Keypad.h>
#include <Wire.h>

#include “Tlc5940.h”

#define Adr0 0x20
#define Adr1 0x21
#define Adr2 0x22
#define Adr3 0x23

const byte MXr = 8;
const byte MXc = 8;

char Mk [MXr ][MXc ] = {
{‘A’,‘E’,‘J’,’(’,  ‘B’,‘F’,‘K’,’[’ },
{‘a’,‘e’,‘j’,’)’,    ‘b’,‘f’,‘k’,’]’ },
{‘1’,‘W’,‘S’,‘N’,  ‘2’,‘X’,‘T’,‘P’ },
{‘5’,‘w’,‘s’,‘n’,  ‘6’,‘x’,‘t’,‘p’ },
{‘C’,‘G’,‘L’,’{’,  ‘D’,‘H’,‘M’,’<’ },
{‘c’,‘g’,‘i’,’}’,    ‘d’,‘h’,‘m’,’>’ },
{‘3’,‘Y’,‘U’,‘Q’,  ‘4’,‘Z’,‘V’,‘R’ },
{‘7’,‘y’,‘u’,‘q’,  ‘8’,‘z’,‘v’,‘r’ }};

byte rP [MXr] = {15,14,13,12,11,10, 9, 8};
byte cP [MXc] = { 7, 6, 5, 4, 3, 2, 1, 0};

Keypad_MC17 MX0=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr0);
Keypad_MC17 MX1=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr1);
Keypad_MC17 MX2=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr2);
Keypad_MC17 MX3=Keypad_MC17(makeKeymap(Mk),rP,cP,MXr,MXc,Adr3);

#include “relay_var.h”

void setup() {
Serial.begin(9600);
MX0.begin();
MX1.begin();
MX2.begin();
MX3.begin();
Tlc.init();
}

void loop() {
char kM0 = MX0.getKey();
char kM1 = MX1.getKey();
char kM2 = MX2.getKey();
char kM3 = MX3.getKey();

if ((kM0 != NO_KEY) || (kM1 != NO_KEY) || (kM2 != NO_KEY) || (kM3 != NO_KEY))
{
#include “keys_def.h”
#include “serial_scr1.h”
}

#include “relay_def.h”
Tlc.update();        // or “while (Tlc.update());” TBC
}



I would be happy for any constructive replay.
Thank you in advance.
Regards,
Peter

I think you are running out of RAM. If you look at the internals of Keypad_MC17, Keypad, Key you will see a lot of button State storage.

If you are going to support 8 keypads, you are going to have to simplify the logic, and optimize the RAM usage.

I did not study your libraries deeply, but each instance of Keypad creates ten instances of Key.

Chuck.