Numeric keypad that doesn't use most of my pins

I'm a novice, and want to make a little thing that requires a user to enter numeric data, and things will display on the 2x16 LCD screen. I've managed to get text displaying on the screen, but now want to do the user entry.

However, the cheap numeric keypads seem to have 8 wires, which end up using a lot of my pins. So I'm out of space. Is there any numeric keyboards that use maybe 2 data plus +/Gnd?

Remember, I'm a novice. It looks like there might be clever coding ways this can be achieved, but - a simple solution would be better for now.

I can't help, but have been wondering the same thing. So I'm joining the thread to see the answers.

There "must" be some kind of I2C or SPI bus thingy, surely?

You can use an IR remote as a data entry device.
Example:

Have a look at Adafruit Trellis Monochrome Driver PCB for 4x4 Keypad & 3mm LEDs

I saw something called a I2C GPIO PCF8574/PCF8574A Module
I read a post, but got a bit sick half way through as it looked a bit like rocket science.

I got frightened when I saw it start about "Visuino" and ... I started hoping there was a way NOT to do it this way. But for the experts, that does seem to be an option.

Cralis:
https://www.instructables.com/id/Arduino-Nano-I2C-Matrix-Keypad-With-PCF8574PCF8574/

for the experts

Not sure those two words go well together :wink:

Cralis:
I saw something called a I2C GPIO PCF8574/PCF8574A Module

Easy enough to use, but - in case you didn’t get the message above, “instructables” does not have a great deal of credibility here.

The thing is, if you use a display with an I2C “backpack” (which incidentally uses a PCF8574), you access it using only two pins (A4 and A5). If you use another PCF8574 to read the keyboard, you can (and in fact must) use the same two pins, so the whole of the project you have described so far uses only two pins on the Arduino.

On the other hand, you can use the four data pins which access the LCD to also access the keyboard (along with four other pins and some diodes).

neiklot:
There “must” be some kind of I2C or SPI bus thingy, surely?

Yes - port extenders.
The PCF8574 will do fine. If you’re using a 1602 with I2C backpack it almost certainly has one of those on the backpack. So beware of I2C addresses. Be aware that the PCF8574’s outputs can really only sink current, they have a VERY weak source.

An alternative is the MCP23008.

Shift registers won’t work, they’re input or output only depending on the type.

That PCF module in the instructable looks very handy; my local walk-in supplier has only the loose PCF8574 chip.

There's a PCF8574 library and example here

neiklot:
That PCF module in the instructable looks very handy; my local walk-in supplier has only the loose PCF8574 chip.

No problem, especially if it's a DIP package. They fit nicely on a breadboard. Just remember to add a 100nF decoupling cap at the Vcc pin, and a pull-up resistor on the RESET. Set A0-A2 so you have a different address from your LCD.

Your I2C bus may also need pull-ups, but those are likely present in your LCD backpack.

Just as an aid I found: GitHub - joeyoung/arduino_keypads: arduino libraries for keypad interface on I2C bus

No idea how good it is... But yeah, the hardware side of connecting a key matrix to an I2C expander is pretty straight forward.

This has all gone over my head. :slight_smile: It looks like there’s a way. But it’s pretty involved for a guy who’s started with Arduino only this week. This “backpack” thing sounds like a winner - but pull down resistor.... capacitors... and I started crying. :slight_smile:

Looks like the IR option is the most viable. I’ll search YouTube - maybe the backpack isn’t too bad.

The "backpack" is no trouble whatsoever - you solder it to your display (if you didn't get a display with it already soldered) and connect it with four wires to your Arduino. No other components required and you use Bill's HD44780 library installed in the library manager in the IDE to control your display.

If you use a "port expander" module for the keypad you require no other components either.

On the other hand, the display with backpack requires only 2 pins so you could just connect the keypad with eight. However you do it you will have to code for the keyboard.

And as I said before, it is quite possible to just connect the keypad and display directly by sharing the four data pins on the display.

Either way, if you connect the keypad directly, you need four resistors to protect against simultaneously pressing multiple keys. The PCF8574 is inherently protected against this.

Cralis:
This has all gone over my head. :slight_smile: It looks like there’s a way. But it’s pretty involved for a guy who’s started with Arduino only this week. This “backpack” thing sounds like a winner - but pull down resistor.... capacitors... and I started crying. :slight_smile:

Looks like the IR option is the most viable. I’ll search YouTube - maybe the backpack isn’t too bad.

Ralph Bacon has a video and I usually find his explanations fairly easy to follow.

As a beginner it might help to say, run a "scanner" sketch to check for the I2C address.

If you use the hd44780 library for your LCD (my recommendation), you may need to specify the LCD's I2C address in the LCD constructor. If there are more than one I2C expanders on the I2C bus, the hd44780 library automatic address finder may pick the wrong one for the LCD. If that happens, just put the LCD address in the constructor:

hd44780_I2Cexp lcd(0x27);

@Paul__B & @groundFungus, where did that LCD suddenly came from? I know an LCD to a "backpack" is common but we where talking keypads... Which sounds very doable except it's not very common (aka, no idea about ready made libraries).

You don't need Visuino, The Joe Young library posted by @septillion seems to work well and is simple to set up.

Tutorial:
I2C Version of Using the 4x4 Universal 16 Key Keypad for Arduino

I'm just surprised this isn't more popular it seems like it would be a natural.

septillion:
@Paul__B & @groundFungus, where did that LCD suddenly came from? I know an LCD to a “backpack” is common but we where talking keypads… Which sounds very doable except it’s not very common (aka, no idea about ready made libraries).

Oh really!

The port expander is addressed through the I2C library. You just write and read the pins on it which as they are already arrange in a byte, is even easier than accessing the Arduino pins using digitalRead and digitalWrite. It really should not be difficult to write code to scan it.

And as I said, the PCF8574 does not even need the protective resistors!

Credit to Hutkikz too - there is a library!

Any pointers on how to install this.

Went to the linked page but no green button to download.

So went back one page to download, tried to add the zip file to the libraries but it came up with an error

Arduino: 1.8.8 (Windows 7), Board: “Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)”

Specified folder/zip file does not contain a valid library

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.