# ESP32 Thing with a matrix keypad 4\*4

**URL:** <https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157>\
**Category:** MicroMod\
**Tags:** processor\
**Created:** [December 9, 2021, 2:53pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157 "2021-12-09T14:53:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tytan](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@Tytan](https://community.sparkfun.com/u/Tytan)\
**Post date:** [December 9, 2021, 2:53pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/1 "2021-12-09T14:53:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpiloverbd](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rpiloverbd](https://community.sparkfun.com/u/rpiloverbd)\
**Post date:** [December 10, 2021, 12:26pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/2 "2021-12-10T12:26:29Z")

</div>

Hello There,

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

---

<div class="post-metadata">

**Author:** ![Tytan](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@Tytan](https://community.sparkfun.com/u/Tytan)\
**Post date:** [December 10, 2021, 8:05pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/3 "2021-12-10T20:05:18Z")

</div>

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.

```auto
#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

```

---

<div class="post-metadata">

**Author:** ![rpiloverbd](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rpiloverbd](https://community.sparkfun.com/u/rpiloverbd)\
**Post date:** [December 11, 2021, 7:54am UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/4 "2021-12-11T07:54:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tytan](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@Tytan](https://community.sparkfun.com/u/Tytan)\
**Post date:** [December 15, 2021, 10:26am UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/5 "2021-12-15T10:26:27Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![rpiloverbd](https://avatars.discourse-cdn.com/v4/letter/r/cab0a1/32.png) [@rpiloverbd](https://community.sparkfun.com/u/rpiloverbd)\
**Post date:** [December 15, 2021, 1:01pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/6 "2021-12-15T13:01:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulvha](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@paulvha](https://community.sparkfun.com/u/paulvha)\
**Post date:** [December 15, 2021, 2:32pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/7 "2021-12-15T14:32:33Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Tytan](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@Tytan](https://community.sparkfun.com/u/Tytan)\
**Post date:** [December 23, 2021, 7:05pm UTC](https://community.sparkfun.com/t/esp32-thing-with-a-matrix-keypad-4-4/43157/8 "2021-12-23T19:05:55Z")

</div>

Thxs
