SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions about processor boards have here!
User avatar
By Tytan
#230044
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
User avatar
By Tytan
#230066
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.
Code: Select all
#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
User avatar
By Tytan
#230141
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.
User avatar
By rpiloverbd
#230144
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.
By paulvha
#230145
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
Code: Select all
if (customKey != NO_KEY)  Serial.println(customKey);
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum