0
\$\begingroup\$

I am trying to use a 1x4 keypad with an ESP32. I am using this keypad and this ESP32 (30 pins); I am also using this keypad library.

I have only pins 14, 15, 34, 36 (VN), and 39 (VP) free on the ESP32, the others are in use.

When I think of it on paper, I should be able to use the input-only pins for the keypad.

My code looks like this and is not working. Only the "2" button is working properly.

#include <Keypad.h>

const byte ROWS = 1; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', '4'}
};
byte rowPins[ROWS] = {14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {39, 15, 34, 36}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop() {
  char key = keypad.getKey();

  if (key) {
    Serial.println(key);
  }
}

Why this code is not working I do not understand, but I know pins 34, 36 and 39 are input-only pins and those pins don't have an INPUT_PULLUP function. But in the library there is this code in keypad.h:

#ifndef INPUT_PULLUP
#warning "Using  pinMode() INPUT_PULLUP AVR emulation"
#define INPUT_PULLUP 0x2
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
#define _mypinMode(_pin, _mode)
do {                
  if (_mode == INPUT_PULLUP)
    pinMode(_pin, INPUT);
    digitalWrite(_pin, 1);
    if (_mode != INPUT_PULLUP)
      pinMode(_pin, _mode);
} while(0)
#endif

In my opinion this code is the problem. I've tried all the possibilities I could think of, but it still doesn't work.

\$\endgroup\$
2
  • \$\begingroup\$ Do not use the keypad library because this is not a key matrix, just 4 switches. It is absurd to use 5 pins to read 4 switches. Connect the common contact to GND and the switches to 4 inputs. Enable the internal pull up resistors of these inputs (if available) or use external resistors and just read the inputs. \$\endgroup\$
    – Jens
    Jun 2, 2022 at 2:35
  • \$\begingroup\$ well if I use normal GIOP pins with this library, everything working normal \$\endgroup\$
    – mehmet
    Jun 2, 2022 at 5:35

1 Answer 1

1
\$\begingroup\$

Pins 35, 37, 38, and 36 are input-only and do not have an internal pull-up resistor. It is required to use an external pull-up resistor in order to detect changes. Many guys talk about a 10 resistor, I just tested with a 2 kΩ one.

Hope this helps somebody.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.