74LS151 & Keypad

Hello,

I have a 3x4 matrix Keypad. Instead of using 7 pins on my Arduino Uno I thought I would multiplex it. I have some 74LS151's laying around but I'm not sure if that will gain me much. Seems that I am only freeing up 1 pin using that IC? I would appreciate any feedback on the following:

  1. Is this possible (using a 74LS151 to multiplex the 3x4 Keypad?
  2. Does the 74LS151 require 6 pins on the arduino (3 Selects, 1 Strobe, 2 outputs) or am I looking at it wrong?

A 3 by 4 keypad is multiplexed. You have to select a column and read a row, or vice versa.

You are right. Using the obsolete 74LS151 (it uses power just to keep warm!) would save only one pin. You would select one of three columns, and use the 151 to read the rows in turn. You would use two pins to select which row, and one to read the result. Total six pins.

You want a keyboard encoder - 74(H)C922. That gets you down to five pins. There are ways of using shift registers to reduce the number to less, and if you were already using other shift registers, it could be using pins already used for the others.

Thank you for your feedback!

Note: the 3x4 keypad is a 12 digit keypad with 7 pins (I know it is multiplexed already but I was looking to increase the number of free pins on the arduino)

What about using the 74HC595? Looks like that would get it down to 3 pins.

tcox8:
Note: the 3x4 keypad is a 12 digit keypad with 7 pins (I know it is multiplexed already but I was looking to increase the number of free pins on the arduino)

Yes, so four outputs and three inputs, or vice versa.

tcox8:
What about using the 74HC595? Looks like that would get it down to 3 pins.

What about it? How would you use a 74HC595 to multiplex inputs?

Citing an "instructable" - and that one is clearly no exception - is considered akin to swearing here.

Paul__B:
What about it? How would you use a 74HC595 to multiplex inputs?

Duh! Now I just feel stupid. :confused:

Paul__B:
Citing an "instructable" - and that one is clearly no exception - is considered akin to swearing here.

Sorry about that. But thanks for the help. I appreciate it!

How about a i2c i/o expander? Only 2 pins needed but they must be A4&5 on Uno. If you are already connecting other i2c devices then this solution uses no extra pins at all.

What else is connected to the Arduino? There may be other, easier ways to save pins.

Paul

That could work. I also have some CD4021BE Shift Registers that I am thinking of using.

The big picture of this project is an activity board for my son. The keypad is from an old touch-tone phone. I have it playing .wav files of the touch tones which I think is pretty slick. I also have it ringing with the push of a button. There are several switches and lights that I plan on having light up but haven't got to that part yet. I am also planning on using rgb leds that will be color controlled based on what switches are flipped (I have 3 switches with the three different led's built in). Lot's going on here but I am trying to compartmentalize it all.

Another approach would need only 4 pins and no extra chips, but one of the 4 would need to be an analog input. You would make a resistor ladder from 4 equal resistors, say 2K3, to feed the analog input. Then scan the 3 columns with the 3 other pins.

My first try was something similar except also having a resistors on the columns as well. Then to measure the voltage using one analog pin. It worked but wasn't very accurate because depending on how hard you pushed the key on the keypad you could get totally different values.

Ah, right, i know the sort you mean.

Well, that's the difference. The original Touch Tone™ keyboards used real push switches.

Something like this?


Might also have to connect Q6 to P6, Q7 to P7 & Q8 to P8.

You can charlieplex it:-
http://forum.arduino.cc/index.php?topic=141978.0;topicseen

Grumpy_Mike:
You can charlieplex it

Now that is clever!

@tcox8, you could add 4 of your other switches into the same matrix as your keypad, making it 4x4, and save even more pins.

Grumpy_Mike:
You can charlieplex it:-

@Grumpy_Mike - Brilliant! Thanks for this! I only wish I had waited to order my ICs. >:(

PaulRB:
@tcox8, you could add 4 of your other switches into the same matrix as your keypad, making it 4x4, and save even more pins.

@PaulRB - Yet another brilliant idea!

You guys rock! :slight_smile:

PaulRB:
Something like this?


Might also have to connect Q6 to P6, Q7 to P7 & Q8 to P8.

I decided to try the CD4021 chips opposed to the Charlieplexing (I already had the chips and don't have enough diodes).

@PaulRB - Can you explain this schematic for me (I'm having trouble understanding it). Questions I have:

  • What size resistors to use?
  • Why is D5 hooked to Q8?
  • Are the diodes necessary?
  • What if I wanted to hook some switches up to make it 4x4 matrix?

I truly appreciate everyone's help on this!

I don't know if this will work, its just an idea. Don't have one of those chips, so can suggest some code but can't help you test it.

  1. A few K, not critical. Try 10K
  2. To allow the data read by the chip to be shifted into the Arduino
  3. Yes, they prevent short-circuits between Q6, 7 & 8 when buttons are pressed.
  4. You can't, not with this chip alone, but you could make 5x3 matrix. Use P5 to make 5th row, like the others.

The process would be:
1.Arduino sets chip into serial mode and sends out 8 bits to the chip. The 5 least significant bits don't matter, but the 3 most significant bits govern which column of buttons will be read. One should be zero and the other two should be one, so that only one column is read at a time.
2. Arduino changes chip back to parallel mode. The 3 most significant bits appear on the Q6, 7 & 8 outputs. For the outputs set to one/high, no current flows because of the diodes. For the one set to zero/low, current can be sunk if one of the buttons in that column is pressed.
3. The P1 to 5 inputs are normally pulled high by the resistors. If a button is pressed in the currently selected column, the corresponding P input is pulled low (by one of the Q outputs, through the diode).
4. Arduino sets chip back to serial mode. The levels at P1 to 5 inputs are captured by the chip.
6. Arduino shifts 8 bits in through D5. The button states are read from the 5 least significant bits.
7. Arduino repeats the process for the other two columns of buttons.

Any experts reading this care to comment on likely succes? Exact timing issues could be the downfall of the idea. Hence my suggestion of also connecting P6 to 8 to Q6 to 8, so that the output levels on Q6 to 8 are not disturbed at the instant when the chip switches back to serial mode.

That's my idea. But the charlieplexing one is better because it uses same number of Arduino pins, no extra chips, and has been tested and shown to work.

Thanks for the fantastic explanation! I think you are right... I think I need to just stick with the Charlieplexing. I tested it out and it works great.

I truly thank you (and everyone else) for your help!