ESP32 Thing connect keypad with mcp23017

Hoi

I’m trying to connect a keypad via MCP23017, but I don’t get any key press value.

I started wit scanning the I2C:

Scanning…

I2C device found at address 0x20 !

done

=>MCP23017 is at address 0x20

Wiring:

MCP23017_pA0 => GND

MCP23017_pA1 => GND

MCP23017_pA2 => GND

MCP23017_p12 => 4.7K resistor => ESP32_p22 (SCK)

MCP23017_p13 => 4.7K resistor => ESP32_p21 (SDA)

MCP23017_p18 => VCC

MCP23017_pGPA0 => keypad R1

MCP23017_pGPA1 => keypad R2

MCP23017_pGPA2 => keypad R3

MCP23017_pGPA3 => keypad R4

MCP23017_pGPA4 => keypad C1

MCP23017_pGPA5 => keypad C2

MCP23017_pGPA6 => keypad C3

MCP23017_pGPA7 => keypad C4

Code (simple key press to serial console):

#include <Arduino.h>
#include <Keypad_MC17.h>
#include <Keypad.h>        // GDY120705

#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] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 1, 0}; //connect to the column pinouts of the keypad

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

void setup(){
  customKeypad.begin( );
  Serial.begin(9600);
  Serial.println("Test with MCP23017");
}
  
void loop(){
  char customKey = customKeypad.getKey();
  if (customKey != NO_KEY)
  {
    Serial.println(customKey);
  }
}

Hello, are you getting no value at all? Or getting garbage values? It will be more helpful if you please share the screenshot of your serial monitor.

I don’t recieve anything.

Looking at the source of Keypad_MC17.cpp I get the impression that you first need to call Wire.begin( ); before calling customKeypad.begin( ); try that.

That was the issue.

Adding Wire.begin();

Thxs