Package: matrix_keypad
NOTICEI have added support for the BeagleBone Black and would like help testing. If you are able please provide feedback to me atchris@chriscrumpacker.comIntroductionPython Library for Matrix Keypads.
Written and tested on a Model B Raspberry Pi.
Supports both a 3x4 and 4x4 keypad includedCurrent Version:v1.2.2Project Page:Project_PagePyPI page:PyPI_PageAuthorAuthor:Chris CrumpackerEmail:chris@chriscrumpacker.comWeb:http://www.chriscrumpacker.comBlog:http://crumpspot.blogspot.comPrerequisitesIf you are using the Raspberry Pi you will need to install the Python Development Toolkit. First update your package list:sudo apt-get updateNow install the Dev Kit:sudo apt-get install python-devThen to install Rpi.GPIO itself:sudo apt-get install python-rpi.gpioInstalling Setuptools next so that you can use PIP is also helpful:https://pypi.python.org/pypi/setuptools/1.1If the I2C Port expander MCP23017 or MCP23008 is being used on a RPi, the Adafruit Python library for I2C and the MCP will need to be installed.You can clone the whole library like so:git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.gitor the two files needed can be pulled out,Adafruit_I2C.py&Adafruit_MCP230xx.py.If using a BeagleBone Black you must install the Adafruit_BBIO. This will give us access to the Adafruit_BBIO.GPIO library that will interface with the pins. Instructions on installing the BBIO library can be found here. The easiest way to install is:/usr/bin/ntpdate -b -s -u pool.ntp.org
opkg update && opkg install python-pip python-setuptools
pip install Adafruit_BBIOFor manual installation:git clone git://github.com/adafruit/adafruit-beaglebone-io-python.git
#set the date and time
/usr/bin/ntpdate -b -s -u pool.ntp.org
#install dependency
opkg update && opkg install python-distutils
cd adafruit-beaglebone-io-python
python setup.py installInstallYou can use the source from just downloading the files or Install it as a library via PIP:pip install matrix_keypadIf using the Adafruit I2C code on a Raspberry Pi, you will need to create links to the Adafruit I2C and MCP230xx code since they are not installed as packages.:sudo ln -s [path to Adafruit python code]/AdafruitMCP230xx/*.py /usr/local/lib/python2.7/dist-packages/matrix_keypadNote: you will have to change the part in the brackets and maybe the path to the where the matrix keypad package isFiles IncludedREADME.txt
LICENSE.txt
setup.py
matrix_keypad/
    __init__.py
    BBb_GPIO.py
    RPi_GPIO.py
    MCP230xx.py
    matrix_keypad_demo.py
    matrix_keypad_demo2.pyUsageSee the demo scripts included to see this all in action.To call the library select which one you intend to use and use the correct line:from matrix_keypad import MCP230xxor:from matrix_keypad import RPi_GPIOor:from matrix_keypad import BBb_GPIOThen initialize and give the library a short name so it is easier to reference later. For the MCP version:kp = MCP230xx.keypad(address = 0x21, num_gpios = 8, columnCount = 4)The variables in the keypad function call in this example are the I2C address, then if you are using the MCP23017 or MCP23008 you have to put the number of GPIO pin avaialable (default is 8), Then the “columnCount” is 3 for the 4x3 keypads and 4 for the 4x4 keypads.For the standard GPIO version you only have to reference the column count and only if you want to change it to the 4x4, it defaults at the 3x4:kp = RPi_GPIO.keypad(ColumnCount = 4)It is possible to just check to see if a digit is currently pressed.:checkKeypad = kp.getKey()Or a simple function to call the keypad library and
loop through it waiting for a digit pressdef digit():
    # Loop while waiting for a keypress
    digitPressed = None
    while digitPressed == None:
        digitPressed = kp.getKey()
    return digitPressedVersion Historyv0.1.0:Initial Scriptsv1.0.0:Initial package buildv1.0.1:Initial package build and push to PyPIv1.0.2:Updating the matrix_keypad_demo2.py to demo selecting the 4x4 keypadv1.0.3:Moved Version Log in READMEUpdated README Linksv1.0.4:Updated References to include the PiLarm code as the inspiration for the “…demo2.py” codev1.0.5:Updates to the code in both main libs to fix some indenting and other issues from coping the code from blogger to a text file.Updates to the keypad picking section for the constants to make it actually workv1.0.6:Fixes to more indenting issues. :(v1.1.0:Updated main libs and the demo code.Added install directions to handle the links to the adafruit codev1.1.1:Updated …demo.py and demo2.py to reflect new package name.Updated README as wellv1.1.2:Updating the README project linksUpdating the code’s commentsv1.1.3:Repackagev1.2b:Beta code added for BeagleBone Black supportUpdated the demo code to include examples intializing the BBb_GPIO codeUpdate all library and demo code with new Comment Headerv1.2.2:Updated the BBb library with feedback from testersCode ReferencesColumn and Row scanning adapted from Bandono’smatrixQPIwhich is wiringPi based.Support for the BeagleBone Black has been added with the help of Daniel Marcus, Details on his project can be found here;dmarcstudios.commatrix_keypad_demo2.py is based on some work that Jeff Highsmith had done in making hisPiLarmthat was featured on Make.