Pages: [1]   Go Down
Author Topic: Troubleshooting a 4x4 16 keys keypad [solved]  (Read 1912 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello community, I come here because I'm not quite sure if I'm doing something wrong or if there is something wrong with my hardware. Here's the deal:

1. I have connected as directed per tutorial a 4x4 keypad to an arduino leonardo using the following code:
Code:
#include <Keypad.h>

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

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

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

void loop()
{
  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    Serial.println(key);
    }
}

It works quite ok, but some keys are not read by the Arduino when the're hit.
  • Keys that don't work: 2, 3, A & 4, 7, *.
  • All rest work and show accordingly
  • All col OR row have at least 1 key working OK

What am i missing here?
« Last Edit: February 01, 2013, 06:33:18 am by tavovalencia » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like a bdy [edit: bad] keypad.
If you use a jumper wire and connect the two pins that make up any keypress, can you see all the characters?

For example, put a jumper wire on 6, and touch it to 2,5,4,3, then 7 and 2,5,4,3, then 8 and 2,5,4,3, then 9 and 2,5,4,3.
« Last Edit: February 01, 2013, 11:08:48 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 1
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey CrossRoads,

what's a bdy ? a typo or abbreviation for...

If I jump pin 6 with the other pins, I get all the keys that are missing on ROW0 (2,3,A) without pressing the keypad.
Also if I jump 2 with the rest, I get all the missing keys in COL0 (4,7,*) without pressing the keypad.

What should I do?
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After all it wasn't a hardware problem, I believe that with my keypad there's a need to include some pull-up resistors. I actually figure this out after changing my scope. As I wouldn't be able to use as many I/O pins anyways, I connected the keypad via I2C with a PCF8574AN (As instructed) with the http://playground.arduino.cc/Main/I2CPortExpanderAndKeypads library and the modifications suggested by PaulS here: http://arduino.cc/forum/index.php/topic,102018.0.html (5th post).
Logged

Pages: [1]   Go Up
Jump to: