Custom Keypad

Hello,

I followed the “The Matrix Keypad how-to” tutorial at https://playground.arduino.cc/Main/KeypadTutorial and did the mapping as defined in https://playground.arduino.cc/Main/KeypadTutorial#Identify and got the results as in the attached image.
I am using the Keypad library from the same page as above.

There are 21 buttons on my keypad and 13 wires.

Can someone please guide me how to define this keypad in the code.

Thank you for your help.

Keymap.jpg

Please find the code below that I tried -

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;

//define keypad structure
/* defination of special keys
F1 - #
F2 - $
F3 - %
F4 - &
//UP - (
//DOWN - )
ESC - <
ENT - >
//CALL - ?
//ALERT -
//ANNOUNCE - @
/
char hexaKeys[ROWS][COLS] = {
{‘1’, ‘2’, ‘3’},
{‘4’, ‘5’, ‘6’},
{‘7’, ‘8’, ‘9’},
{’
’, ‘0’, ‘#’}
};

//defining the pins where rows and cols are connected
byte rowPins[ROWS] = {9,8,7,6};
byte colPins[COLS] = {12,11,10};

//Initialize the instance of the Keypad
Keypad localKpd = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
Serial.begin(9600);
while (!Serial){
delay(100);
}
//localKpd.begin(makeKeymap(hexaKeys));
Serial.println(“Initialized”);

}

void loop() {
//just getting the keypress and showing on the serial monitor
char keyPress = localKpd.getKey();

if (keyPress) {
Serial.println(keyPress);
/* switch (keyPress) {
case ‘&’:
Serial.println(“F4”);
break;
case ‘%’:
Serial.println(“F3”);
break;
case ‘$’:
Serial.println(“F2”);
break;
case ‘#’:
Serial.println(“F1”);
break;
case ‘(’:
Serial.println(“UP”);
break;
case ‘?’:
Serial.println(“CALL”);
break;
case ‘*’:
Serial.println(“ALERT”);
break;
case ‘@’:
Serial.println();
break;
case ‘<’:
Serial.println();
break;
case ‘>’:
Serial.println();
break;
case ‘.’:
Serial.println(“ERROR”);
break;
default:
Serial.println(keyPress);
} */
}
}

You are stuck with a difficult keypad layout. They show each pin as being both a row pin and a column pin but the keypad library can't do that. You have to arrange things so the each pin is either a row or a column.

It looks like pins 13, 10, 11, and 12 are for three LEDs.

The DOWN button (pins 1 & 2) will be the hardest. If you use 2 as a 'row' to get CALL, 0, 8, 5, and 2 you would have to use 1 as a column to get DOWN but then you couldn't use 1 as a row to get UP, ESC, 7, 4, and 1. If 1 is a row to get UP, ESC, 7, 4, and 1 you would have to use 2 as a column to get DOWN. But then you couldn't get CALL, 0, 8, 5, and 2.

To get the DOWN button you will have to abandon the Keypad library and do your own keyboard scanning. Connect pins 1 through 9 of your keypad to Arduino pins (maybe 2 through 10). Set all to pinMode INPUT_PULLUP. To scan, set each pin (of the first 4 anyway) to OUTPUT and LOW and see what other pins go LOW. The button at the intersection of those two pins is pressed. Then set the pin back to INPUT_PULLUP before going on to the next pin.

They must be numbering COL 1-13 and then ROW 1-13 on separate headers. If you look at just the nodes with names, you should have 14 wires. It is possible that one is missing? I don't know anything about the library but I think most expect a 4x4 matrix. You have a 7x7 matrix. The LEDs, not being a switch, my have some modified connection which is why it seems a wire short.

Hello johnwasser,

Please see inline reply

You are stuck with a difficult keypad layout. They show each pin as being both a row pin and a column pin but the keypad library can't do that. You have to arrange things so the each pin is either a row or a column.

KK> Sorry the representation of that document is confusing. What I show in that excel is as follows- There are 13 pins and the table shows connectivity of 2 wires (row and column of excel) when a button is pressed. For example - when "0" is pressed, wire 2 (row of excel) and wire 6 (col of excel) are short. Sorry for the confusion.

It looks like pins 13, 10, 11, and 12 are for three LEDs. KK> Yes

The DOWN button (pins 1 & 2) will be the hardest. If you use 2 as a 'row' to get CALL, 0, 8, 5, and 2 you would have to use 1 as a column to get DOWN but then you couldn't use 1 as a row to get UP, ESC, 7, 4, and 1. If 1 is a row to get UP, ESC, 7, 4, and 1 you would have to use 2 as a column to get DOWN. But then you couldn't get CALL, 0, 8, 5, and 2. KK> I understand this is the biggest challenge and I am not sure how to address this. To get things started, I just need numbers 0-9, ESC, ENT, F1-F4 keys. Rest can wait for the next version. Though it will be good to have a solution so that I can finish it in one go.

To get the DOWN button you will have to abandon the Keypad library and do your own keyboard scanning. Connect pins 1 through 9 of your keypad to Arduino pins (maybe 2 through 10). Set all to pinMode INPUT_PULLUP. To scan, set each pin (of the first 4 anyway) to OUTPUT and LOW and see what other pins go LOW. The button at the intersection of those two pins is pressed. Then set the pin back to INPUT_PULLUP before going on to the next pin. KK> Thank you. I will try this.

Hello boolrules,

Sorry for confusion. Please note below - What I show in that excel is as follows- There are 13 pins and the table shows connectivity of 2 wires (row and column of excel) when a button is pressed. For example - when "0" is pressed, wire 2 (row of excel) and wire 6 (col of excel) are short. Sorry for the confusion.

What I need is how do I define a table (associate wire to ROW / COLUMN) with the above data.

What I need to capture at the start is 0-9, ENT, ESC, F1-F4

NOTE: I am not sure what you mean by wire 14.

mr_confusion: KK> I understand this is the biggest challenge and I am not sure how to address this. To get things started, I just need numbers 0-9, ESC, ENT, F1-F4 keys. Rest can wait for the next version. Though it will be good to have a solution so that I can finish it in one go.

To get started you can use 9, 8, 7, 6, 5 as rows and 1, 2, 3, and 4 as columns. That will get you:

| v-Row\Column-> | 1 | 2 | 3 | 4 | | - | - | - | - | - | | 9 | 1 | 2 | 3 | F4 | | 8 | 4 | 5 | 6 | F3 | | 7 | 7 | 8 | 9 | F2 | | 6 | ESC | 0 | ENT | F1 | | 5 | UP | CALL | ANNOUNCE | ALERT |

Each key is assigned a non-zero byte value, typically a character, but any non-zero value will work:

char Keys[ROWS][COLS] =
{
  {'1', '2', '3', 'D'},
  {'4', '5', '6', 'C'},
  {'7', '8', '9', 'B'},
  {'*', '0', '#', 'A'},
  {'U', 'c', 'N', 'L'}
};

'A' -> F1 'B' -> F2 'C' -> F3 'D' -> F4 '*' -> ESC '#' -> ENT 'U' -> UP 'c' -> CALL 'N' -> ANNOUNCE 'L' -> ALERT

mr_confusion: Hello boolrules,

Sorry for confusion. Please note below - What I show in that excel is as follows- There are 13 pins and the table shows connectivity of 2 wires (row and column of excel) when a button is pressed. For example - when "0" is pressed, wire 2 (row of excel) and wire 6 (col of excel) are short. Sorry for the confusion.

Exactly as I suspect. Your ROWs are 1,2,3.4,10,11,12 and COLs are 2,5,6,7,8.9, 13. A 7x7 matrix

What I need is how do I define a table (associate wire to ROW / COLUMN) with the above data.

What I need to capture at the start is 0-9, ENT, ESC, F1-F4

So you only need ROW: 1,2,3,4 and COL 6,7,8,9 (pins on you keypad). That's only a 4x4 matrix. Follow John's answer. You may be causing yourself a lot of grief later on by not starting with a 7x6 matrix from the start.

NOTE: I am not sure what you mean by wire 14.

Dollars to doughnuts the wire for COL 13 is not there because you might have a PWR connection to the LEDs somewhere else.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Ops image;
Keymap.jpg

Tom… :slight_smile:

johnwasser: To get started you can use 9, 8, 7, 6, 5 as rows and 1, 2, 3, and 4 as columns. That will get you:

| v-Row\Column-> | 1 | 2 | 3 | 4 | | - | - | - | - | - | | 9 | 1 | 2 | 3 | F4 | | 8 | 4 | 5 | 6 | F3 | | 7 | 7 | 8 | 9 | F2 | | 6 | ESC | 0 | ENT | F1 | | 5 | UP | CALL | ANNOUNCE | ALERT |

Each key is assigned a non-zero byte value, typically a character, but any non-zero value will work:

char Keys[ROWS][COLS] =
{
  {'1', '2', '3', 'D'},
  {'4', '5', '6', 'C'},
  {'7', '8', '9', 'B'},
  {'*', '0', '#', 'A'},
  {'U', 'c', 'N', 'L'}
};

'A' -> F1 'B' -> F2 'C' -> F3 'D' -> F4 '*' -> ESC '#' -> ENT 'U' -> UP 'c' -> CALL 'N' -> ANNOUNCE 'L' -> ALERT

Hello John,

Thank you for your support. I will check this over the weekend and get back.

boolrules: Exactly as I suspect. Your ROWs are 1,2,3.4,10,11,12 and COLs are 2,5,6,7,8.9, 13. A 7x7 matrixSo you only need ROW: 1,2,3,4 and COL 6,7,8,9 (pins on you keypad). That's only a 4x4 matrix. Follow John's answer. You may be causing yourself a lot of grief later on by not starting with a 7x6 matrix from the start.Dollars to doughnuts the wire for COL 13 is not there because you might have a PWR connection to the LEDs somewhere else.

The 3 LED as I see now are controller from another unit.

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Ops image;
Keymap.jpg

Tom… :slight_smile:

Hi Tom,
My apologies. I will follow in future.

mr_confusion: Hi Tom, My apologies. I will follow in future.

No problem, just get you into the groove early to help with getting your project going. Tom.. :)

Sorry for a late reply. I was travelling. Good news is that with your help, I got the keypad working with single digit inputs. Next step - 1. enable alpha numeric mode 2. capture 1-6 char code that is entered and send over serial when F4 is pressed.

Will work on this and come back to the community is stuck.

Once again, thank you for all the help.