ESP32 Thing with a matrix keypad 4*4

Hoi

I try to connect a matrix keypad (4*4) to an ESP32 thing.

When I run the code on a Arduino uno board I don’t have any issues, but running the same code on the ESP32 I receive not only the key press but also a strange character.

I have tried several GPIO’s but always the same issue.

Should I place some resistor between the ROW pins and the keypad?

Greetings Miguel

Hello There,

Which tutorial are you following? This one https://www.youtube.com/watch?v=X3gtHnkPTBE or something else?

The code is simple, read key pressed and print on the terminal

On an Arduino Uno everything is ok, but when using on ESP32 thing I also get a special char on every loop.

#include <Arduino.h>
#include <Keypad.h>

// Keypad init
const byte ROWS = 4; 
const byte COLS = 4; 
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {32, 33, 25, 26}; 
byte colPins[COLS] = {27, 14, 12, 13}; 
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 
char customKey;

// Setup
void setup()
{
  Serial.begin(9600);
}
// Setup

// Loop
void loop()
{
  char customKey = customKeypad.getKey();
   Serial.println(customKey);
}
// Loop

So, you are getting a garbage followed by the real character. Am I right? Is it the same if you chose any baud rate other than 9600?

This is the console output. I have press the “1” key once, but I also receive on evry loop a null value from the getkey function?

Ps the terminal is configured correct.

Executing task in folder esp32-alarm: platformio device monitor <

— Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time

— More details at https://bit.ly/pio-monitor-filters

— Miniterm on /dev/ttyUSB0 9600,8,N,1 —

— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H —

1

— exit —

Terminal will be reused by tasks, press any key to close it.

Did you try changing the baud rate? What happens if you deliberately add a space after the character ? Suppose, if you write

Serial.print(customKey);

Serial.print(" ");

What change do you see? Thank you.

receiving a NULL key is correct. getkey() will return NO_KEY (defined as \0) if no key was pressed.

Instead of print everything , do a check for it

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

Thxs