4×4 Membrane keypad RPI

Device:

Source code:
source

import RPi.GPIO as GPIO
 
GPIO.setmode(GPIO.BCM)
 
MATRIX = [ [1,2,3,'A'],
           [4,5,6,'B'],
           [7,8,9,'C'],
           ['*',0,'#','D'] ]
 
ROW = [5,6,13,19]
COL = [26,16,20,21]
 
for j in range(4) :
        GPIO.setup(COL[j], GPIO.OUT)
        GPIO.output(COL[j], 1)
 
for i in range(4) :
        GPIO.setup(ROW[i], GPIO.IN, pull_up_down = GPIO.PUD_UP)
 
try:
        while(True) :
                for j in range(4) :
                        GPIO.output(COL[j],0)
 
                        for i in range(4) :
                                if GPIO.input(ROW[i]) == 0:
 
                                        print MATRIX[i][j]
                                        while(GPIO.input(ROW[i]) == 0) :
                                                pass
                        GPIO.output(COL[j],1)
except KeyboardInterrupt :
        GPIO.cleanup()

 

Pastebin: http://pastebin.com/gV9e466L

Fritzing PDF:
Keypad-4x4_RPi_wiring_bb

Get it to work:
1) Get access to RPI
2) Write: sudo nano
3) 
Paste the code from above into the text editor
4) Press CTRL+X
5) Press Y
6) Give the file a name Name.py
7) Press Enter
8) Write: python Name.py
9) Press Enter
10) Program is running.

Post by: Nicki, Rasmus & Thor

One Reply to “4×4 Membrane keypad RPI”

  1. If anybody used a breakout board and need inspiration on how to set up the connections, here are some pictures of a working setup with it.
    http://imgur.com/a/3FAw3

    Side info if needed.

    Rows and columns used:
    ROW = [7,11,13,15]
    COL = [12,16,18,22]

Comments are closed.