PCB Keypad Matrix Help

Hello. I need some assistance in understanding how to go about my project involving a PCB keypad that utilizes diodes to reduce the amount of I/O pins used.

I was given some sample code on what the original design was supposed to represent, however as designs change, the code is no longer relevant. I have taken the sample code and tried to make it work with my project with no success. Currently, the serial monitor only scrolls endlessly with nothing recognized.

I cannot upload or share pictures because of being a new account, but here is the wiring explained in text:

  • I have 69 keys on the keypad.
  • We are running ground to each key
  • We have 9 rows (rows 0 - 8 is how they are labeled)
  • These rows are associated with the pins as row 0 - pin 2, row 1 - pin 3, etc.
  • The design allocates one diode for each row on the opposite end of the pushbuttons. (some designs have one diode per button which ours differs from)

I have a separate library associated with the obvious enumerators inside the array which should have no impact on the issue.

Here is the code I am attempting to utilize:

#include "ControlExports.h"

long lastTime3 = 0;
long interval2 = 350;

// for the switches
int d,b,readOutT,column;
const int row[9] = {2,3,4,5,6,7,8,9,10};
byte readOut[9];
const String trans[9][8] = {
  {"CID_UFC_IDT,1","CID_UFC_WPN,1","CID_UFC_COM,1","CID_UFC_EGI,1","CID_UFC_DST,1","CID_UFC_APP,1","CID_UFC_FPL,1","CID_UFC_MRK,1"},
  {"CID_UFC_ENT,1","CID_UFC_UL1,1","CID_UFC_9,1","CID_UFC_UL2,1","CID_UFC_6,1","CID_UFC_UL3,1","CID_UFC_3,1","CID_UFC_UL4,1"},
  {"CID_UFC_A,1","CID_UFC_B,1","CID_UFC_C,1","CID_UFC_HUDBRT,1","CID_UFC_HUD,1","CID_UFC_TST,1","CID_UFC_UFCBRT,-1","CID_UFC_UFCBRT,1"},
  {"CID_UFC_S,1","CID_UFC_L,1","CID_UFC_M,1","CID_UFC_N,1","CID_UFC_O,1","CID_UFC_P,1","CID_UFC_Q,1","CID_UFC_R,1"},
  {"CID_UFC_RTN,1","CID_UFC_0,1","CID_UFC_7,1","CID_UFC_8,1","CID_UFC_4,1","CID_UFC_5,1","CID_UFC_1,1","CID_UFC_2,1"},
  {"CID_UFC_HUDBRT,-1","CID_UFC_ALT,1","CID_UFC_SET,1","CID_UFC_VTR,1","CID_UFC_WIT,1","CID_UFC_ACK,1","CID_UFC_CLK,1","CID_UFC_BULL,1"},
  {"CID_UFC_J,1","CID_UFC_K,1","CID_UFC_D,1","CID_UFC_E,1","CID_UFC_F,1","CID_UFC_G,1","CID_UFC_H,1","CID_UFC_I,1"},
  {"CID_UFC_T,1","CID_UFC_U,1","CID_UFC_V,1","CID_UFC_W,1","CID_UFC_X,1","CID_UFC_Y,1","CID_UFC_Z,1","CID_UFC_SP,1"},
  {"CID_UFC_UR1,1","CID_UFC_IFF,1","CID_UFC_UR2,1","CID_UFC_UR3,1","CID_UFC_UR4,1","","",""},
};


void setup() {
  Serial.begin(9600);
  for(int l=0;l<9;++l){pinMode(row[l], INPUT_PULLUP);}
}


void readSwitch(){
  for(d=0; d<9; ++d){
    pinMode(row[d],OUTPUT);
    digitalWrite(row[d], LOW);
    readOutT = 0;
    
    for(int j=0; j<9; ++j){
      readOut[j] = digitalRead(row[j]);
      readOutT += readOut[j];
    }
    if(readOutT < 9) {transLator();}
    pinMode(row[d], INPUT_PULLUP);
  }
}

void transLator() {  
  int newArr[9];
  int pos=0;
  
  for(int a=0; a<9; ++a){
    if(a == d){continue;}
    newArr[pos] = readOut[a];
    pos++;
  }
  for(b=0; b<pos; ++b){
    if(newArr[b] != 1){
      column = b;
    }
  }
  wording(d, column);
}

int wording(int x, int y){
  unsigned long currentTime = millis();
  String load = trans[x][y];
    
    if((currentTime - lastTime3) > interval2){
      lastTime3 = currentTime;
      Serial.println(load);
    }

}

void loop() {
  readSwitch(); //--------readSwitch runs the functions above to read the switch panel. upto 80 switches can be used with this functions array sizes.
}

Does anyone have any hints that I am missing? I am strictly programming side typically, but trying to wrap my head around the electrical logic side has me in a bind.


#include "ControlExports.h"

long lastTime3 = 0;
long interval2 = 350;

// for the switches
int b, readOutT, column;
const int row[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
byte readOut[9];
const String trans[9][8] = {
  {"CID_UFC_IDT,1", "CID_UFC_WPN,1", "CID_UFC_COM,1", "CID_UFC_EGI,1", "CID_UFC_DST,1", "CID_UFC_APP,1", "CID_UFC_FPL,1", "CID_UFC_MRK,1"},
  {"CID_UFC_ENT,1", "CID_UFC_UL1,1", "CID_UFC_9,1", "CID_UFC_UL2,1", "CID_UFC_6,1", "CID_UFC_UL3,1", "CID_UFC_3,1", "CID_UFC_UL4,1"},
  {"CID_UFC_A,1", "CID_UFC_B,1", "CID_UFC_C,1", "CID_UFC_HUDBRT,1", "CID_UFC_HUD,1", "CID_UFC_TST,1", "CID_UFC_UFCBRT,-1", "CID_UFC_UFCBRT,1"},
  {"CID_UFC_S,1", "CID_UFC_L,1", "CID_UFC_M,1", "CID_UFC_N,1", "CID_UFC_O,1", "CID_UFC_P,1", "CID_UFC_Q,1", "CID_UFC_R,1"},
  {"CID_UFC_RTN,1", "CID_UFC_0,1", "CID_UFC_7,1", "CID_UFC_8,1", "CID_UFC_4,1", "CID_UFC_5,1", "CID_UFC_1,1", "CID_UFC_2,1"},
  {"CID_UFC_HUDBRT,-1", "CID_UFC_ALT,1", "CID_UFC_SET,1", "CID_UFC_VTR,1", "CID_UFC_WIT,1", "CID_UFC_ACK,1", "CID_UFC_CLK,1", "CID_UFC_BULL,1"},
  {"CID_UFC_J,1", "CID_UFC_K,1", "CID_UFC_D,1", "CID_UFC_E,1", "CID_UFC_F,1", "CID_UFC_G,1", "CID_UFC_H,1", "CID_UFC_I,1"},
  {"CID_UFC_T,1", "CID_UFC_U,1", "CID_UFC_V,1", "CID_UFC_W,1", "CID_UFC_X,1", "CID_UFC_Y,1", "CID_UFC_Z,1", "CID_UFC_SP,1"},
  {"CID_UFC_UR1,1", "CID_UFC_IFF,1", "CID_UFC_UR2,1", "CID_UFC_UR3,1", "CID_UFC_UR4,1", "", "", ""},
};


void setup() {
  Serial.begin(115200);
  for (int l = 0; l < 9; ++l)pinMode(row[l], INPUT_PULLUP);
}

void transLator() {
  int newArr[9];
  int pos = 0;

  for (int a = 0; a < 9; a++) {
    if (a == d)continue;

    newArr[pos] = readOut[a];
    pos++;
  }
  for (b = 0; b < pos; b++)    if (newArr[b] != 1)      column = b;
  wording(d, column);
}

int wording(int x, int y) {
  unsigned long currentTime = millis();
  String load = trans[x][y];
  if ((currentTime - lastTime3) > interval2) {
    lastTime3 = currentTime;
    Serial.println(load);
  }
}

void loop() {
  for (byte d = 0; d < 9; d++) {
    pinMode(row[d], OUTPUT);
    digitalWrite(row[d], LOW);
    readOutT = 0;
    for (int j = 0; j < 9; j++) {
      readOut[j] = digitalRead(row[j]);
      readOutT += readOut[j];
    }
    if (readOutT < 9)transLator();
    pinMode(row[d], INPUT_PULLUP);
  }
}

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