I want to use an ESP-32 to read keypresses and show it on an OLED screen. I can't get it to detect keypresses

richterlevania3
Posts: 1
Joined: Thu Aug 17, 2023 3:22 am

I want to use an ESP-32 to read keypresses and show it on an OLED screen. I can't get it to detect keypresses

Postby richterlevania3 » Thu Aug 17, 2023 3:25 am

I'm using the following code. The ESP32 goes on a loop printing gibberish and doesn't detect any keypresses. I'm using a Wroom32 with 38 pins.
I'm using diodes on the columns.

Code: Select all

#include <Arduino.h>

const int numRows = 4;
const int numCols = 12;

const byte rowPins[numRows] = {1, 3, 17, 4};
const byte colPins[numCols] = {16, 0, 2, 15, 13, 12, 14, 27, 26, 25, 33, 32};

char keyMap[numRows][numCols] = {
  {'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '\b'},
  {'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '\n'},
  {16, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 16},
  {' '}
};

void setup() {
  Serial.begin(115200);

  for (int i = 0; i < numRows; i++) {
    pinMode(rowPins[i], OUTPUT);
    digitalWrite(rowPins[i], LOW);
  }

  for (int j = 0; j < numCols; j++) {
    pinMode(colPins[j], INPUT_PULLDOWN);
  }
}

void loop() {
  for (int row = 0; row < numRows; row++) {
    digitalWrite(rowPins[row], LOW); // Activate the current row
    for (int col = 0; col < numCols; col++) {
      if (digitalRead(colPins[col]) == HIGH) {
        char key = keyMap[row][col];
        if (key == '\t') {
          Serial.print("TAB");
        } else if (key == '\b') {
          Serial.print("BACKSPACE");
        } else if (key == '\n') {
          Serial.print("ENTER");
        } else if (key == 16) {
          Serial.print("SHIFT");
        } else if (key != ' ') {
          Serial.print(key); // Send the captured key to the serial console
        }
        delay(50); // Debounce delay
      }
    }
    digitalWrite(rowPins[row], HIGH); // Deactivate the row
  }
}
I'm at my wits end. Please help me.

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

Re: I want to use an ESP-32 to read keypresses and show it on an OLED screen. I can't get it to detect keypresses

Postby ESP_Sprite » Thu Aug 17, 2023 7:26 am

GPIO 1 is your TxD, that normally is the output from your serial port. If you're using that for your keyboard instead, you won't get sane serial output anymore.

Who is online

Users browsing this forum: No registered users and 64 guests