Reducing keypad pins

Hello everyone,

I'm going to finish my first Arduino project soon, but I have a question:

I currently have a 4x4 matrix keypad and a lcd connected to my Arduino Uno. The problem is that I almost don't have any digital pins anymore that I can use. Only pin 13, TX and RX is available, and all the analog pins. The lcd only uses 3 digital pins with a shift register, but the keypad uses 8 pins. Is there anyway to reduce the amount of pins needed for the keypad, or extend the digital pins?

I'm planning to make a barebone Arduino for this project, because I don't always want to put my Arduino Uno in it.

Regards, Tibo

Yes there is...

Use some i2c port expanders (like the PCF8574P) there are libs to use them with lcd's and keypad's also. I used them a lot works like a charm!

:)

Thanks, I will take a look at it.

The analog pins also work as digital pins as do the pwm pins.

You would need to find bi-directional shift registers for your keypad but twice good news; 1) They exist at least up to 8 bits wide. Look around. 2) Keypads don't need blazing interface speed, serial to parallel will do fine.

If you connect via SPI bus then you can add another or two for the lcd? Note to self: make sure to get serial lcd.

The analog pins also work as digital pins as do the pwm pins.

Very nice! I didn't knew that! Thanks!

You would need to find bi-directional shift registers for your keypad but twice good news; 1) They exist at least up to 8 bits wide. Look around. 2) Keypads don't need blazing interface speed, serial to parallel will do fine.

Okay, but should an I2C be easier?

If you connect via SPI bus then you can add another or two for the lcd?

What do you mean?

Note to self: make sure to get serial lcd.

I'll take a look at this, as it uses only 1 pin. Nice!

Thanks for helping guys!

Take a look at this application note from Microchip. Among several ways outlined in it to reduce number of microcontroller pins used, there is a keypad example

http://ww1.microchip.com/downloads/en/appnotes/00234a.pdf

Thanks man, I wil take a look at it. :wink:

TiboJ:

You would need to find bi-directional shift registers for your keypad but twice good news; 1) They exist at least up to 8 bits wide. Look around. 2) Keypads don't need blazing interface speed, serial to parallel will do fine.

Okay, but should an I2C be easier?

And slower and not sure you can daisy-chain I2C.

If you connect via SPI bus then you can add another or two for the lcd?

What do you mean?

SPI bus is possible to connect many serial devices. Each has a wire to make it active. If not active it is just there until activated. For the price of one extra pin you add a device like shift register or SD adapter or even something with multiple chips to run on one signal. As long as the signals are there, how is flexible which opens up possibilities in design.

Just make sure there's enough power for everything without overtaxing the Arduino. You can light up 8x8x8 RGB leds and make the colors dance with shift registers but it will need external power going to the shift registers.

You can control the keypad and lcd using the ATmega's hardware-supported SPI pins, leaving the regular serial pins that have INT0 and INT1 (the only edge-triggered interrupts) open. There is an SPI library for Arduino too. That should take some pain away!

Perhaps there is also for I2C. You can save more pins there but lose some speed sending ID messages for activation instead of using control wires. I2C uses the same ATmega hardware that SPI does.

Look up SPI bus on Wikipedia, nice article with better explanation.

I'm assuming you are "Tibo371" from Youtube, if not, just ignore my post.

I use this serial LCD from digikey, its only $21: http://search.digikey.com/scripts/DkSearch/dksus.dll?x=16&y=16&lang=en&site=us&KeyWords=NHD-0216K3Z-NSW-BBW-ND

If you just need the extra pins for the siren and some LEDs, you can use the analog pins for that. Just treat analog pin 0 as digital pin 14.

@GoForSmoke:

Thanks for explaining and the suggestion, I'll keep it in mind and take a look at Wikipedia!

wizdum: I'm assuming you are "Tibo371" from Youtube, if not, just ignore my post.

I use this serial LCD from digikey, its only $21: http://search.digikey.com/scripts/DkSearch/dksus.dll?x=16&y=16&lang=en&site=us&KeyWords=NHD-0216K3Z-NSW-BBW-ND

If you just need the extra pins for the siren and some LEDs, you can use the analog pins for that. Just treat analog pin 0 as digital pin 14.

Yes, I am Tibo371 :)

I'll keep using the shift register for the lcd for now, but a serial lcd might be good for future project when I need even more pins. I will use the analog pins now, because they're enough for this project. Thanks for telling me. ;)