Strange results with a telephone keypad

Hi everyone. I'm having a weird issue with a keypad. I took one out of an actual desk phone, figured out the pinouts, plugged it in, and now I get odd results.

First off, the code. It's pretty much the default stuff from the library:

/*  Keypadtest.pde
 *
 *  Demonstrate the simplest use of the  keypad library.
 *
 *  The first step is to connect your keypad to the
 *  Arduino  using the pin numbers listed below in
 *  rowPins[] and colPins[]. If you want to use different
 *  pins then  you  can  change  the  numbers below to
 *  match your setup.
 *
 */
#include <Keypad.h>

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8 }; 

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

#define ledpin 13

void setup()
{
  digitalWrite(ledpin, HIGH);
  Serial.begin(9600);
}

void loop()
{
  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '*':
        digitalWrite(ledpin, LOW);
        break;
      case '#':
        digitalWrite(ledpin, HIGH);
        break;
      default:
        Serial.println(key);
    }
  }
}

Now, the oddness as seen off the USB:

  • Most of the buttons don't work.
  • When I press 4, I get ~
  • When I press 7, I get '
  • When I press 8, I get f
  • When I press 9, I get x

I know the keypad works because I tested continuity on all pins. The odd results are what's puzzling. Where is it getting that information? Did I use the wrong library? Any help would be appreciated. :slight_smile:

Was the keyboard you used wired like the one for the library? It looks like it was not.

It was not wired exactly the same. The example had 14 pins, mine had 8. I also moved the pins down because laziness. :slight_smile:

It's just bizarre that it comes up with F, X, and those special characters and that's about it. :frowning:

It was not wired exactly the same. The example had 14 pins, mine had 8.

In electronic terms that means it is totally different.

It's just bizarre that it comes up with F, X, and those special characters

No it's not, is the way the library works, it is probably accessing an array outside the limits of it and that is producing random characters, because the input is not what it was written for.

I suggest you grab a multimeter and get the pin out of the keypad.Then modify the

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8 };

acording what you get.
To get the pin out of the rows and columns just press the botton and then check on which wires the resistence gets lower. Draw a table and you will get the values for all pins of the keypad
Then wire it correctly.

FTPMonster:
Now, the oddness as seen off the USB:

  • Most of the buttons don't work.
  • When I press 4, I get ~
  • When I press 7, I get '
  • When I press 8, I get f
  • When I press 9, I get x

I know the keypad works because I tested continuity on all pins. The odd results are what's puzzling. Where is it getting that information? Did I use the wrong library? Any help would be appreciated. :slight_smile:

This is not a normal failure mode for the keypad library. Even if you wired it up completely wrong you would not get those strange characters. Unless of course if you are plugged into the serial pins 0 or 1. Also, are you running version 1.0.3 of the Arduino software? If so, could you download 1.0.4 and give it a try. http://arduino.cc/en/Main/Software

OK, I have confirmed the pins. I did reverse a few, but I now have it:

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 7, 6, 5, 4 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 8, 9, 10 };

However, I still have the same problem. Now, I'm reading about some keypads needing pull up resistors, and I'm going to try that and report back.

FTPMonster:
However, I still have the same problem. Now, I'm reading about some keypads needing pull up resistors, and I'm going to try that and report back.

No need. The library automatically uses the internal pull-up resistors on the uController. What I'm really concerned about is why are you getting the strange characters. I've seen that problem when someone uses the wrong baud rate in their serial terminal. Can you make sure you have your code and serial monitor set to the same value?

Also, did you check to see which Arduino version you are using?

mstanley:
No need. The library automatically uses the internal pull-up resistors on the uController. What I'm really concerned about is why are you getting the strange characters. I've seen that problem when someone uses the wrong baud rate in their serial terminal. Can you make sure you have your code and serial monitor set to the same value?

Also, did you check to see which Arduino version you are using?

Arduino 1.0.4, but it was the serial speed. I mis-typed it in PuTTY. :frowning:

I'm so glad I'm done for the week. :slight_smile:

FTPMonster:
I'm so glad I'm done for the week. :slight_smile:

I'm really glad to hear it. :slight_smile: Let me know if you have any more trouble. It's been kind of interesting. :wink: