Raspberry Pi Pico and 4x3 Keypad
by Ramatronics Laboratory in Circuits > Microcontrollers
1994 Views, 4 Favorites, 0 Comments
Raspberry Pi Pico and 4x3 Keypad
In this instructables, I am going to teach you how we can interface a 4x3 matrix keypad with Raspberry pi Pico. We shall create a python program to print the pressed key in the shell are of IDE. Let's get started.
Supplies
Hardware List:
https://quartzcomponents.com?sca_ref=3671286.DzEptz4I3w
Raspberry Pi Pico
https://quartzcomponents.com/products/raspberry-pi-pico?_pos=1&_sid=0bd862ba1&_ss=r
4x3 matrix keypad
not available on Quartz components.
Bread Board
Jumper Wires (male to male)
https://quartzcomponents.com/products/65pcs-breadboard-jumper-cable?_pos=7&_sid=bbd2c7176&_ss=r
Micro-B USB Cable
https://quartzcomponents.com/products/raspberry-pi-cable-for-charging?_pos=9&_sid=8364cf4c7&_ss=r
http://www.amazon.in
Raspberry Pi Pico
4x3 matrix keypad
Bread board
Jumper wires (male to male)
Micro-B USB Cable
Connect the Keypad to Raspberry Pi Pico
In step first, we create a simple prototype circuit on a bread and connect the Keypad to the GPIO pins of the raspberry pi Pico. The list of the wiring scheme is given below.
R1 ---------> GPIO2
R2 ---------> GPIO3
R3 ----------> GPIO4
R4 ----------> GPIO5
C1 ----------> GPIO6
C2 ----------> GPIO7
C3 ----------> GPIO8
For making proper connections you can take the help of the provided schematic diagram.
Programming
Python Code:
from machine import Pin
import utime
row_list = [2, 3, 4, 5]
col_list = [6, 7, 8]
for x in range(0, 4):
row_list[x] = Pin(row_list[x], Pin.OUT)
row_list[x].value(1)
for x in range(0 ,3):
col_list[x] = Pin(col_list[x], Pin.IN, Pin.PULL_UP)
key_list = [["1", "2", "3"],\
["4", "5", "6"],\
["7", "8", "9"],\
["*", "0", "#"]]
def keypad(col, row):
for r in row:
r.value(0)
result = [col[0].value(), col[1].value(), col[2].value()]
if min(result) == 0:
key = key_list[int(row.index(r))][int(result.index(0))]
r.value(1)
return (key)
r.value(1)
while True:
key = keypad(col_list, row_list)
if key != None:
print("key: "+key)
utime.sleep(0.3)
Upload the above python program on the Raspberry Pi Pico by Thonny IDE. After uploading is completed press any one key of the keypad, you will see the pressed key on the shell area of Thonny IDE.