Hardware Reference
In-Depth Information
the breadboard. Remember, you want to have the GPIO-connected jumper wires lined
up with the corresponding horizontal row that contains the keypad pin.
How to Use Fewer Pins
This configuration is the easiest to wire, but it does have the disadvantage of using
up a lot of the GPIO pins on your Raspberry Pi. If you are feeling braver, you could
cut back on the number of GPIO pins used by wiring a demultiplexer (demux) to
the row pins, cutting them from four down to two.
You could also binary encode the column outputs with pull-down resistors on the
GPIO input pins and diodes to generate and mix the binary signal, resulting in two
column pins instead of three. If you do this, you'd need to write new code to handle
the more complicated inputs, which is left as an exercise to the power hacker.
(Credit goes to aTao on the Raspberry Pi forums for pointing this out.)
Installing the Software
To keep things simple here, we'll take advantage of the Python Raspberry Pi GPIO
library. Pidora and Raspbian install this software by default, but if you do not have it
already available in your Linux distribution, you can download the source code . A copy
of this code is also included in the GitHub repository for this topic .
Chris Crumpacker wrote a Python library called matrix_keypad to interface the Rasp-
berry Pi directly with the Adafruit Matrix numeric keypad, but unfortunately, it has
some bugs which prevent it from working as is. We've taken revision 1.0.4 of his li-
brary and cleaned up the bugs that were preventing it from working properly.
To install this library, first check out the fixed source code:
$ git clone https://github.com/spotrh/rpihacks
$ cd rpihacks/matrix_keypad-1.0.4-fixed
Next, build and install the fixed library:
$ python setup.py build
$ su -c 'python setup.py install --prefix=/usr'
Running the Program
Now you have a working copy of the matrix_keypad library installed on your Raspberry
Pi. We have also included a demonstration script (derived from Chris's examples) so
that you can test your setup. There is a file in the matrix_keypad-1.0.4-fixed/ directory
called book-demo.py . Make sure your numeric keypad is wired in correctly, then run:
$ chmod +x book-demo.py
$ su -c './book-demo.py'
 
Search WWH ::




Custom Search