Keypad + LCD (or 7SEGs)

Hi everybody,
I'm getting started with Arduino Uno, so forgive me if I'm asking something trivial.

I succeed in reading numbers from a 12keys keypad (with 7 pins) using the keypad library, and now I'd like to output them on six 7segments leds (and later also on the LCD).
However, 7 pins for the keypad + 3 * 6 pins for the 7segments makes 25 pins which is too much for Arduino Uno's pins.

I've read about some ICs to add extra pins, or that there is a way using I2C to do it with just 2 pins, but it sounds complicated and I'm not sure about what should I buy and how should I use it.

What is the most straightforward, cheap, and reusable way to do it? (I mean, if later I want to replace the segs with the LCD, I'd like to reuse the same components and just change the code).

Thank you very much in advance.

Regards

I think that the IC you are referring to is a shift register. With these components you only use three Arduino pins to control eight pins on another component. Have a look through these search results and see how you go.

https://www.google.com.au/search?q=arduino+%2B+7+seg+%2B+keypad+%2B+shift+register&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&gfe_rd=cr&ei=gs7JUozlDcmN8Qfdu4DgBQ

Good luck Pedro.

Ah, but "multiplexing" works just as well for reading keypads and driving displays. The trick is to do both together.

You have six, seven segment LEDs to drive, so that is 14 pins (the LEDs have decimal points). You multiplex these by driving the common of each digit in turn. As you do so, you also multiplex four of the keypad lines, so you only need another three lines to read the multiplexed keyboard. Total 17 pins and by my count, the UNO has sufficient I/O to do this without compromising the serial interface and still leaving one analog input available.

And here are the "tricks":

Analog pins are also digital.

You need a buffer to drive the LED commons.

You need a diode for each of the LED commons to multiplex the keyboard in case two keys are pressed simultaneously.

Since you need an extra chip or six transistors at least to drive the LEDs, it is actually much more sensible to use a MAX7219 to do so, costing only three pins.

Thank you both! You opened my mind :smiley: I googled for more info about the 74HC595 and the CD4021BE and they are exactly what I needed (they are both cheap too).

Thanks guys :smiley:

This is nice suggestion.

from,
Shravan Gupta

A quick final question: suppose I'm using the LCD and the keypad; normally, I #include the appropriate library for both and I initialize them passing the pins config to the classes constructor.
When I use shift registers, either in input or in output, how should I use the libraries? Of course I cannot pass the pins config to the constructor since there are no straightforward I/O pins, I must first decode/encode the registers, so what is the right procedure to do that?

Thanks!