4x4 keypad wont work

this is the code i’m using

//http://www.arduino.cc/playground/Code/Keypad
#include <Keypad.h> // Download Keypad.zip

//define the cymbols on the buttons of the keypads
char hexaKeys[4][5] = {
“ABCD”,
“EFGH”,
“IJKL”,
“MNOP”
};
byte rows = 4; //four rows
byte cols = 4; //four columns
byte rowPins = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins = {6,7,8,9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(hexaKeys,rowPins,colPins,rows,cols);

void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key != NO_KEY) {
key -= ‘A’-1;
Serial.println(key,DEC);
}
}

this is the error message i’m getting :
No matching found for call to ‘Keypad::Keypad(char [4][5], byte [4], byte [4], byte&, byte&)’
sketch_may25a:15: error: no matching function for call to ‘Keypad::Keypad(char [4][5], byte [4], byte [4], byte&, byte&)’
C:\Users\DarkGiZmo\Documents\Arduino\libraries\Keypad/Keypad.h:63: note: candidates are: Keypad::Keypad(char*, byte*, byte*, byte, byte)
C:\Users\DarkGiZmo\Documents\Arduino\libraries\Keypad/Keypad.h:57: note: Keypad::Keypad(const Keypad&)

i have no idea what i’m supposed to do now :confused:

Try this:

Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, rows, cols);

Wooho :D i love u man :) ,, but now my keypad returns alot of gibberish numbers tho, it might just be my pinning that's wrong. and my "6" key doesent work . any initial thoughts ?

Wooho smiley-grin i love u man smiley ,, but now my keypad returns alot of gibberish numbers tho

Keep that to yourself, OK? :)

What, exactly, are you trying to print when a key is pressed?

The whole purpose of defining hexaKeys the way it is, and using makeKeymap(), is so that the getKey() function returns a value that matches what's printed on the key. In other words, if you press the key labeled 6, the getKey() function should return '6'.

The most likely issue is the values in the rows and/or cols array, when some keys work and some don't.

You decrement key with:

key -= 'A'-1;

But you probably want to INCREMENT instead since prior to this key is assaigned to as:

char key = keypad.getKey();

I am not familiar with what values getKey() returns but i'm guessing it will be an integer 0 to 7, hence decrementing this number will make it go negative and cause problems with odd chars. Incrementing will shift your 'key' variable up to the correct range in the ASCII table from A onwards i.e. Decimal 65. Note, adding 'A' is akin to adding 65.

If this helps but doesn't completely solve it, changes are it should just be key += 'A' rather than 'A' -1.

I am not familiar with what values getKey() returns but i'm guessing it will be an integer 0 to 7

Nope. See Reply #3.

i'm aiming to make it serial print 1 if i press 1 and 2 if i press 2 and so on, so i can write the values into a variable to be displayed on an LCD screen for a temperature controller. i've changed the wiring around a little and now 1 is 2 and 2 is 3 and so on.

So getKey() returns ints from 1 to 8 then? Why not simply print the key returned from that function?

i just tried that, then i get numbers like 71 , 68 etc. etc. and then it’s 2 other keys that doesent work.

illillillill:
//define the cymbols on the buttons of the keypads
char hexaKeys[4][5] = {
“ABCD”,
“EFGH”,
“IJKL”,
“MNOP”
};

4 x 5 is 20 keys not 16, for a start.

And you should have 16 values there, not 4. eg.

char hexaKeys[4][4] = {
 'A', 'B', 'C', 'D',
 'E', 'F', 'G', 'H',
 'I', 'J', 'K', 'L',
 'M', 'N', 'O', 'P'
};

illillillill: i just tried that, then i get numbers like 71 , 68 etc. etc. and then it's 2 other keys that doesent work.

Depends how you print them. 68 in decimal is 0x44 in hex, which is 'D' in ASCII. And 'D' is in your list.

So getKey() returns ints from 1 to 8 then?

No. The getKey() function returns the values defines in hexaKeys ('A', ..., 'P').

A = 65
B = 66
C = 67
D = 68
E = 69
F = 70
G = 71
H = 72
I = 73
J = 74
K = 75
L = 76
M = 77
N = 78
O = 79
P = 80

just tried using u'r :

char hexaKeys[4][4] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' };

now all keys exept the 4 to the right works .. my keypad looks like this

1 2 3 A 4 5 6 B 7 8 9 C * 0 # D

the numbers are still wrong but now at least they print. but the letters are not printing

May have to do with your DEC argument to the Serial.println command. You asked for it to print numbers. See Nick’s lookup table…

Yes, the keypad setup code needs to look like this:

// Define the Keymap
char keys[ROWS][COLS] = 
{
  {    '1','2','3','A'      }  ,  // row 1
  {    '4','5','6','B'      }  ,  // row 2
  {    '7','8','9','C'      }  ,  // row 3
  {    '*','0','#','D'      }  ,  // row 4
};

// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins  << insert your pins
byte rowPins[ROWS] = { 6, 5, 4, 3  };  // Keypad uses internal pullups - No externals supplied

// Connect keypad COL1, COL2, COL3, COL4 to these Arduino pins.  << insert your pins
byte colPins[COLS] = { 10, 9, 8, 7 }; 

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

then your void loop code can be like this

void loop()
{   // go read the keypad
  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {
 switch(key){
case 'A':
Serialprint ("A");
break;

case '1':
Serialprint ("1");  // or serial.Print, whatever the correct format is
break;

case '#':
Serialprint ("#");
break; 
} // end switch
} // end if (key)
}  // end of void loop

illillillill: my keypad looks like this

1 2 3 A 4 5 6 B 7 8 9 C * 0 # D

So shouldn't you use this:

char hexaKeys[] = {
 "123A"
 "456B"
 "789C"
 "*0#D"};

Then you can print the result directly instead of re-mapping from other characters.

Maybe - the keypad library works as described tho.

johnwasser: So shouldn't you use this:

char hexaKeys[] = {
 "123A"
 "456B"
 "789C"
 "*0#D"};

Then you can print the result directly instead of re-mapping from other characters.

Maybe that works, but from what I see you are actually describing 5 values per row, not 4:

'1', '2', '3', 'A', 0x00, 
.. and so on

So telling the library you have 4 columns and then supplying 5 values would account for some "dead keys".