Interfacing a keypad with the RPZ
Now that we've looked at the Raspberry Pi Zero's pull-up and pull-down resistor options, we can apply our knowledge to operating a 12- or 16-digit keypad. Let's take a look!
Getting ready
All you'll need for this recipe is a 16-key numeric keypad. One is included in the Elegoo kit, and they are available from most online retailers. A typical keyboard input looks something like this:
How to do it...
There are eight pins on a 16-key numeric keypad. Here is how you wire them to your Raspberry Pi:
Understanding the internals of the keypad makes it easy to understand how to control it. Effectively, each number is a switch tied to a column and a row, as shown here:
Suppose we set our rows as inputs with the pull-down circuit enabled and configure the columns as outputs. Now, when a button is pressed, if we can detect which output and input were connected, we can determine which key was pressed. Look at
keypad.py
in thech8
directory...