5x2 Button Matrix With Diodes Doesn't Work

Hello all,

I recently made a custom PCB with a 5x2 Cherry MX button matrix and 5 slide potentiometers, all powered by a Mega 2560. The sliders work great, however I am unable to get the Keypad library to work nicely with the button matrix. I have tried and adapted example code from many different places, but some only work partially or not at all. Help is much appreciated

/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>

const byte ROWS = 2; //two rows
const byte COLS = 5; //five columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3','4'},
  {'5','6','7','8','9'},
};
byte rowPins[ROWS] = {2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7, 8}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
}

Circuit diagram, PCB and modified code from the example sketch from the Keypad library:

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

if it doesn't work as a 2x5 keyboard with your diodes, just make it a 5x2 keypad:

const byte ROWS = 5; // five rows
const byte COLS = 2; // two columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0', '5'},
  {'1', '6'},
  {'2', '7'},
  {'3', '8'},
  {'4', '9'}
};
byte rowPins[ROWS] = {4, 5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3}; //connect to the column pinouts of the keypad

This worked - cheers

What is the purpose of the diodes ?

I have keypads, both commercial and home made that work perfectly well without them

Just for reliability purposes, in case two buttons are pressed at the same time etc. They didn’t cost much more to add so there wasn’t any harm in doing so

Seb

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