Go Down

Topic: Matrix Keypad with fewer pins? (Read 3581 times) previous topic - next topic

SouthernAtHeart

I've been looking around, and have seen this question asked, seen dicussions about analog, but haven't really seen a definite answer:  Can I connect a 4x3 keypad with fewer than 7 pins?

CrossRoads

Yes. Folks have devised ways to make voltage dividers such that you can get 12 unique voltages for the 12 buttons (not sure what happened if multiple buttons were pressed).
There were some good solutions to this in the old forum, I'd guess in the Nov/Dec 2010 timeframe.
I myself used a 4x4 keypad and 8 pins, using the keypad library for debouncing and a DIODE AND function to allow a keypress to create an interrupt from powerdown sleep mode. I used it for a remote, so didn't to save pins for other things.

What do you have in mind?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267115381

Check #9, click the British flag to get the Spanish page link in English.
Not sure if can be done with a 4x3 matrix keypad, but is pretty clever.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

DigitalJohnson

see this: http://arduino.cc/playground/Main/I2CPortExpanderAndKeypads

Only 4 pins, and 2 of those are just supply pins. So really 2 pins!

DJ
DigitalJohnson

CrossRoads

And just 1 chip vs a bunch of resistors. Can it be procured in a DIP?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SouthernAtHeart

I'm wanting to use an LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid...
Most things I've come across that use another chip, I look for the chip and it cost $10!  considering my Arnuino was only $20, that's just kinda high.
this PCF8574 looks like it's only a few dollars,  I'll search around for how it works...

GordonEndersby


As you want an LCD as well, How about one of the Serial/I2C controllers with combined support for the keypad.
Then its just 2 pins plus supply and ground.
Includes all the backlighting and contrast adjustment.
http://cgi.ebay.co.uk/I2C-Keypad-controller-LCD-Character-Display-/310275043982?pt=UK_BOI_Electrical_Test_Measurement_Equipment_ET&hash=item483dd5728e

Libraries available as well.
Ive had a play and it works well.

Gordon

CrossRoads

"LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid"
So you're up 15 pins, out of 19 available (A0-A5 are accessible as D14-D19).
Leave D0/D1 out for serial Rx/Tx still leaves 2 free. Sounds like your're ok without having to add external chips.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SouthernAtHeart

"LCD which takes 6-7 pins, and a 4x3 keybaord, 7 more pins, and run a solenoid"
So you're up 15 pins, out of 19 available (A0-A5 are accessible as D14-D19).
Leave D0/D1 out for serial Rx/Tx still leaves 2 free. Sounds like your're ok without having to add external chips

...I wondered about that, so A0-A5 can be used...   I may be alright, then. 
I just looked at the Serial/I2C mentioned.  This looks pretty nice.  So it runs the LCD display, and the keypad? Here's what I've ordered, will it work with them?
A 1602 LCD w/backlight:
http://cgi.ebay.com/HD44780-1602-16x2-LCD-Display-Module-Blue-Blacklight-/190487384867?pt=LH_DefaultDomain_0&hash=item2c59eed323#ht_3016wt_1139

A keypad:
http://cgi.ebay.com/4x3-Key-Matrix-Keypad-Keyboard-General-/130395616352?pt=LH_DefaultDomain_0&hash=item1e5c2f3460#ht_1534wt_905

I'll have to find out more about Serial/I2C controllers

SouthernAtHeart

Whatever I2C is, (Does the Arnuino Uno have I2C?)  It looks like it'd take a long time to figure out.  So I'm hoping I have enough pins...

CrossRoads

Take a look here
http://symlink.dk/electro/hd44780/
The keypad does not appear to be I2C, the keypad library should be enough for that.
I2C is pretty straight forward, you use the Wired.h library to send out serial commands, similar to shiftout but there are dedicated hardware pins.

Here is some of the code I set up for a max6953, which has an I2C interface, for example:
Code: [Select]

Using IIC (I2C) for interfacing to MAX6953
*  Arduino analog 5 - I2C SCL, pin 24
*  Arduino analog 4 - I2C SDA, pin 23

*/
#include <Wire.h>  // bring in Wire Library

//  I2C device address is 1 0 1   A3 A2 A1 A0  with AD1, AD0 both low
#define COMMAND_ADDRESS 0x50 // (B1010000)
#define CONFIG_ADDRESS 0x04
#define INTENSITY10_ADDRESS 0x01
#define INTENSITY32_ADDRESS 0x02
#define SCANLIMIT_ADDRESS 0x03
#define DIGIT0_ADDRESS 0x20 // write both Plane 0
#define DIGIT1_ADDRESS 0x21 // write both Plane 0
#define DIGIT2_ADDRESS 0x22 // write both Plane 0
#define DIGIT3_ADDRESS 0x23 // write both Plane 0
:
:
// start up I2C, uses Analog 5 for Clock, Analog 4 for data
  Wire.begin(); // nothing in () because we are the master

  //  write config register
  Wire.beginTransmission(COMMAND_ADDRESS);
  Wire.send(CONFIG_ADDRESS);
  Wire.send(0x05); 
  // 0000 0001 => 0 shutdown, 1 = normal mode, no fooling with blink modes & stuff
  // 0000 0010 = not used
  // 0000 0100 => 0  slow blink, 1 = fast blink
  // 0000 1000 => 0 = global blink disabled (Plane 1 data ignored), 1  global blink enabled Plane 1 data used)
  // 0001 0000 => 0 = blink unaffected during I2C acknowledge
  // 0010 0000 => 0 = data unaffected during I2C ack, 1 = data cleared
  // 0100 0000 => not used
  // 1000 0000 => blank phase - blink status is read back
  // for this use: 0000 0101 => normal operation, fast blink

  Wire.endTransmission();

  //  write intensity10 register
  Wire.beginTransmission(COMMAND_ADDRESS);
  Wire.send(INTENSITY10_ADDRESS);
  Wire.send(0xEE);  //  E = 15/16 (max)
  Wire.endTransmission();

  // write intensity32 register
  Wire.beginTransmission(COMMAND_ADDRESS);
  Wire.send(INTENSITY32_ADDRESS);
  Wire.send(0xEE);  //  E = 15/16 (max)
  Wire.endTransmission();
:

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

GordonEndersby



I havnt used that keypad but if its got the usual pinouts it should be fine with that I2C controller.
The lcd is fine as well, or you could use a similar 4x20.

There are loads of examples for using the keypad and lcd through I2C.

Gordon

SouthernAtHeart

Crossroads,
I'm a bit confused, that link doesn't seem to say anything about I2C, (or a keypad you mentioned)...

Folderol

I get 8x6 key matrix plus 8bit parallel alph-numeric LCD using a bit of lateral thinking :)

Use the 8 data pins for the LCD as the diode isolated 'drive' pins for the keypad matrix. Scan these in a tight loop between screen updates.

When not actually writing to the screen, the EN line will be low so no risk of sending obscure characters to the screen, and when you're not actually scanning the key matrix it doesn't matter how much the lines wiggle about. Also with a couple of simple arrays you can get the state of every single key simultaneously (sort of).

Program up a chip, and dedicate it to this on a breadboard with just a cheap 16MHz resonator and a few resistors and caps. I pass data in and out via direct serial connections between a couple of these and a mega.

To keep comms to the minimum everything is in single byte commands. I don't need to display top-bit characters so 128+n is top row cursor position, 160+b 2nd row cursor etc. (4x20 display). 12 is clear screen (like the old terminals). 20 is flash cursor, 21 is steady cursor and 22 is cursor off. Chars 32 to 126 are normal printables.

For the keypad side, 128+n gives row/column key-down and  192+n gives corresponding key-up. Chars 32 to 126 are kept clear so the keypad/display module can send a wake-up message.

Go Up