Raspberry Pi Pico and 4x3 Keypad

by Ramatronics Laboratory in Circuits > Microcontrollers

1477 Views, 4 Favorites, 0 Comments

Raspberry Pi Pico and 4x3 Keypad

IMG_20220907_170708.jpg
IMG_20220907_170343.jpg
IMG_20220907_170304.jpg
Raspberry pi pico and 4X3 Keypad.jpg

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

https://quartzcomponents.com/products/colored-breadboard-mb-102-830-point?_pos=3&_sid=149f84734&_ss=r

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

https://www.amazon.in/REES52-Raspberry-microcontroller-Development-RP2040/dp/B08V4XBDDB/ref=sr_1_2?crid=WFSLL9UFKRU1&keywords=raspberry+pi+pico&qid=1664002735&sprefix=rasp%2Caps%2C315&sr=8-2

4x3 matrix keypad

https://www.amazon.in/Techtonics-Matrix-Switch-Keypad-Arduino/dp/B07QHF6MF3/ref=sr_1_1?crid=1PXP38VOGSZVP&keywords=4x3+matrix+keypad&qid=1664002810&sprefix=4x3+m%2Caps%2C690&sr=8-1

Bread board

https://www.amazon.in/Robotbanao-Solderless-MB102-Breadboard-Points/dp/B08GG6ZC41/ref=sr_1_22_sspa?crid=1UWA0GY5V8DT0&keywords=bread+board&qid=1664002855&sprefix=bread+board%2Caps%2C498&sr=8-22-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzUzZVWjY4QUlUNUQmZW5jcnlwdGVkSWQ9QTAzNDkxMTYxQ1YyMVU1TjVKREFLJmVuY3J5cHRlZEFkSWQ9QTAxNDY3MTIxS05ISDhZUDg4UEdDJndpZGdldE5hbWU9c3BfbXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==

Jumper wires (male to male)

https://www.amazon.in/Scriptronics%C2%AE-Breadboard-Jumper-Dupont-Wire/dp/B09M7KFQ6S/ref=sr_1_44?crid=12Y8IB45YCQUB&keywords=jumper+wires&qid=1664002939&sprefix=ju%2Caps%2C775&sr=8-44

Micro-B USB Cable

https://www.amazon.in/Mi-Original-Cable-120cm-Black/dp/B07H4X1SCK/ref=sr_1_13?crid=TM1LSX0TCYXQ&keywords=micro+usb+cable&qid=1664003027&sprefix=micro+usb+cable%2Caps%2C936&sr=8-13

Connect the Keypad to Raspberry Pi Pico

IMG_20220907_170425.jpg
IMG_20220907_170517.jpg
IMG_20220907_170551.jpg
IMG_20220907_170708.jpg

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.