Pages: [1]   Go Down
Author Topic: About pins on a membrane matrix keypad  (Read 2182 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a 4*4 membrane matrix keypad from iteadstudio:



The connector is on the bottom of the keypad. The left 4 are rows and the right 4 are columns. The columns are 0-3 from left to right so are the rows.

I wrote some code to sense this pad. But I'm interested in making the code work on as many keypads as possible. On the other hand I don't have other keypads like these:



and



How are the columns and rows laid out on these above pads? Thanks.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26524
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

I think in all cases you get a pin per row, and a pin per column. If not documented, you do some buzzing with a meter and see what's what.

The bottom one looks like a velleman 4x4 keypad, I might have documentation for that, and possibly even a new one in the package. Will take me a while to dig thru several boxes to find ... - hang, on its documented in my RF remte schematic.


Then use the keypad.h library and set up the code like this to interface with them:
Code:
// set up the Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns

// 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.
byte rowPins[ROWS] = { 6, 5, 4, 3  };  // Keypad uses internal pullups? No externals supplied

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

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
Code:
    // I read the keypad in void loop and put it in an array that virtual wire sends out for me
  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
  {
    msg[0]=key;                               // load the array with the key character
   }
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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks CrossRoads. I was estimating the keypads all have the same layout until I saw this on sparkfun:



Strange way to arrange keys. I guess there is no way I can make the key map work on all keypads. The users will have to decide how to map themselves.

BTW, what is the purpose of putting diodes on the row pins? Digital OR operation?
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26524
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

"Digital OR operation?" AND actually - any 1 going low makes the interrupt line go lo.
Before going to sleep, I bring the columns low, then a Row connecting it will bring the diode low to make an interrupt for waking up, and on wakeup I write the columns back high, then let the keypad library take over to read the key that was pressed.

So it looks like 2,4,6,7 are the rows, and 1,3,5 are the columns on that one.
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.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26524
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

Could you do this: have them press each key, enter what comes out, then work backwards to find the mapping, and correct the row, column mapping in the code.
Maybe keep that in EEPROM so you could change it?
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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you do this: have them press each key, enter what comes out, then work backwards to find the mapping, and correct the row, column mapping in the code.
Maybe keep that in EEPROM so you could change it?


That is a smart way! I will display a prompt: "Press col:0row:0" and wait for input. I'm gonna do that for sure. It's fool-proof and interactive. Thanks!
Logged


Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4259
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Strange way to arrange keys.
It's an even stranger way to describe the connections.  Even with an ASCII diagram I can do better than that.

pin 2 ------ 1----2----3
pin 7 ------ 4----5----6
pin 6 ------ 7----8----9
pin 4 ------ *----0----#
             |    |    |
pin 3 -------|    |    |
pin 1 ------------|    |
pin 5 -----------------|


Don
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Don. I later figured it out by staring at it for quite some time. Yes, your arrangement makes better sense than mine, which insists the order of pin numbers, which messes up the key arrangement as a result. I'll program this in my panel as a pre-set option. Wonder what the 4*4 keypads (black hard plastic) do with their connections. Maybe time to make a purchase and find out.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26524
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

The schematic I posted above shows the pinout for the Velleman 4x4 black plastic keypad.
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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The schematic I posted above shows the pinout for the Velleman 4x4 black plastic keypad.

So this one?

http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001__2131055_-1

Then the left 4 pins are columns and right 4 are rows? That's all I needed to know.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26524
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

Yes.

Some set up code for it:
Code:

// added Keypad example from playground
// modified to send character in a buffer to the receiver from 4x4 matrix

// Velleman 4 x 4 matrix keypad
// keypad 1 (Col1) to D10
// keypad 2 (Col2) to D9
// keypad 3 (Col3) to D8
// keypad 4 (Col4) to D7
// keypad 5 (Row1) to D6
// keypad 6 (Row2) to D5
// keypad 7 (Row3) to D4
// keypad 8 (Row4) to D3

// Rows have Internal Pullups

// set up the Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns

// 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.
byte rowPins[ROWS] = { 6, 5, 4, 3  };  // Keypad uses internal pullups? No externals supplied

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

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
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.

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7172
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Great! Thanks!
Logged


Pages: [1]   Go Up
Jump to: