Keypad - one column not working

I'm making a keyboard, and wanted to start small by making a 2 x 3 keypad just to test if I can get that to work.
In a separate project I got all HID stuff working, including media keys, etc.

Everything seems to work as expected, except for the last column (on both rows).
One thing to note is that I have the arduino just sitting on some connector pins on the breadboard, but moving it around doesn't change anything, but that does sometimes cause the other columns to not work.

Here's the code:

#include <Keypad.h>

const byte ROWS = 2; // Four rows
const byte COLS = 3; // Three columns

char keys[ROWS][COLS] = {
  {'7','8','9'},
  {'#','0','*'}
};

byte rowPins[ROWS] = { 3, 2 };
byte colPins[COLS] = { 6, 5, 4 }; 

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

void setup() {
  Serial.begin(9600);
  while (!Serial) ; 

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
  char keyA = kpd.getKey();

  for (int i = 0; i < 6; i++) {
    PrintKey(i);
  }
  Serial.println("---------------------------------");

  delay(400);
  
  if(keyA)
  {
    switch (keyA)
    {
      case '*':
        digitalWrite(LED_BUILTIN, LOW);
        break;
      case '#':
        digitalWrite(LED_BUILTIN, HIGH);
        break;
      default:
        Serial.println(keyA);
    }
  }
}

void PrintKey(int i) {
  Serial.print(i);
  Serial.print(" : ");
  switch(kpd.key[i].kstate) {
    case IDLE:
      Serial.println("IDLE");
      break;
    case PRESSED:
      Serial.print(kpd.key[i].kchar);
      Serial.println(" PRESSED");
      break;
    case HOLD:
      Serial.print(kpd.key[i].kchar);
      Serial.println(" HOLD");
      break;
    case RELEASED:
      Serial.print(kpd.key[i].kchar);
      Serial.println(" RELEASED");
      break;
    default:
      Serial.println(" UNKNOWN");
  }
}

Is something wrong with how I've wired everything up or the code, or is it a bad connection somewhere?

Which Arduino ? Is the Arduino soldered to the pins that go into the breadboard ?

Hi, sorry, Arduino Micro and no. Just started playing around with Arduino last week, so didn't really know if it was necessary or not.

If the Arduino is not soldered to the pins then there is no guarantee that they are making contact so I suggest that you solder the pins in place

Tested again, now all button presses are detected.

But, now I face another issue; when all keys in 1 row are pressed, and I press 1 key of the other row (so 4 keys in total), it reports that all 6 keys are pressed. How do I avoid that?

Here’s a nice article that covers ghosting:

https://www.dribin.org/dave/keyboard/one_html/

a7

Thanks a lot, that covers it perfectly. I have some more things to test then :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.