ESP32 keypad strange behavior: some kind of pin combination doesn't work.

DirectionLee
Posts: 5
Joined: Sat Apr 03, 2021 5:42 am

ESP32 keypad strange behavior: some kind of pin combination doesn't work.

Postby DirectionLee » Sun May 16, 2021 1:57 pm

I'm trying to test keypad with ESP32. the keypad is 4*4, I tried some of combination of pin setting, some of combination works but some fails.

Code: Select all

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

const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
    {'1','2','3','A',},
    {'4','5','6','B',},
    {'7','8','9','C',},
    {'*','0','#','D',},
};


byte rowPins[ROWS] = {14, 27, 26,25};
byte colPins[COLS] = {4, 16, 17, 5,}; 
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin(115200);
  keypad.addEventListener(mykeypadEvent);
}

void mykeypadEvent(KeypadEvent key){
  Serial.printf("in event, key: %d, state=%d\n", key,keypad.getState());
}

void loop()
{
  char key = keypad.getKey();
  if (key != NO_KEY)
  	Serial.printf("key: %c pressed\n", key);
}
this combination works:

byte rowPins[ROWS] = {26,25,33,32};
byte colPins[COLS] = {15,2,0,4};

this combination fails, seems pin16, pin17
byte rowPins[ROWS] = {26,25,33,32};
byte colPins[COLS] = {4,16,17,5};

could anyone know the reason why 2nd combination failed?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 keypad strange behavior: some kind of pin combination doesn't work.

Postby WiFive » Sun May 16, 2021 7:28 pm

What hardware?

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 keypad strange behavior: some kind of pin combination doesn't work.

Postby ESP_Sprite » Mon May 17, 2021 1:49 am

To add to WiFive's (terse as usual) response: if your hardware has PSRAM, you cannot use GPIO16/17.

DirectionLee
Posts: 5
Joined: Sat Apr 03, 2021 5:42 am

Re: ESP32 keypad strange behavior: some kind of pin combination doesn't work.

Postby DirectionLee » Sun May 23, 2021 12:32 pm

thank you, guys, you are right. the hardware is ESP32 devkitC (ESP32-WROVER-IE), so pin16,17 is reserved for internal use, I forgot this one. thank you again.

Who is online

Users browsing this forum: Baidu [Spider] and 186 guests