SlideShare a Scribd company logo
1
Input Interfacing - Lab II Prof. Anish Goel
STTP on " Embedded Systems using Raspberry Pi Single Board Computer"
Lab Exercise - II
Input Interfacing with R-Pi
Introduction
Keypads are a part of HMI or Human Machine Interface and play really important role in a small
embedded system where human interaction or human input is needed. Martix keypads are well known for
their simple architecture and ease of interfacing with any microcontroller. In this part of tutorial we will
learn how to interface a 4x4 matrix keypad with R-PI. Also we will see how to program it in Python.
Constructing a Matrix Keypad
Construction of a keypad is really simple. As per the outline shown in the figure below we have four rows
and four columns. In between each overlapping row and column line there is a key.
So keeping this outline we can construct a keypad using simple SPST Switches as shown below:
Now our keypad is ready, all we have to do is connect the rows and columns to a port of microcontroller
and program the controller to read the input.
Scanning a Matrix Keypad
There are many methods depending on how you connect your keypad with your controller, but the basic
logic is same. We make the columns as i/p and we drive the rows making them o/p, this whole procedure
of reading the keyboard is called scanning.
In order to detect which key is pressed from the matrix, we make row lines low one by one and read the
columns. Let's say we first make Row1 low, then read the columns. If any of the key in row1 is pressed
will make the corresponding column as low i.e if second key is pressed in Row1, then column2 will give
low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done.
So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of
the button is pressed in a row, it will take the corresponding column to a low state which tells us that a
key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then
column2 and so on.
2
Input Interfacing - Lab II Prof. Anish Goel
import RPi.GPIO as gp
import time
gp.setmode(gp.BOARD)
col=[12,10,8]
row=[15,13,11]
gp.setup(12,gp.OUT,initial=0)
gp.setup(10,gp.OUT,initial=0)
gp.setup(8,gp.OUT,initial=0)
gp.setup(15,gp.IN,pull_up_down=gp.PUD_DOWN)
gp.setup(13,gp.IN,pull_up_down=gp.PUD_DOWN)
gp.setup(11,gp.IN,pull_up_down=gp.PUD_DOWN)
keys=['1','4','7','2','5','8','3','6','9']
def getkeys():
a=[0]*9
gp.output(12,1)
for z in range(3):
a[z]=gp.input(row[z])
gp.output(12,0)
gp.output(10,1)
for z in range(3):
a[z+3]=gp.input(row[z])
gp.output(10,0)
gp.output(8,1)
for z in range(3):
a[z+6]=gp.input(row[z])
gp.output(8,0)
return a
a=[0]*9
a=getkeys()
entered=''
for z in range(9):
if a[z]==1:
entered+=keys[z]+' '
print 'The keys pressed are:'+entered
gp.cleanup()

More Related Content

Similar to Input interface with Raspberry pi (20)

PPTX
Lec10
siddu kadiwal
 
PPSX
Hex keypad
sudheerarao2
 
PPT
Keyboard interfacing for the 8051 MCA.ppt
22ecuos015
 
PPTX
Keyboard Interfacing .pptx
livaunnoor
 
DOCX
Basic standard calculator
UVSofts Technologies
 
PDF
Keypad interfacing
Akhash Kumar
 
PDF
Microcontroladores: El microcontrolador 8051 con LCD 16x2
SANTIAGO PABLO ALBERTO
 
PPTX
Analog to Digital .pptx
karanthakur846894
 
PPT
Presentation2 1-150523155048-lva1-app6892
Nirav rathod
 
DOCX
Keypad interfacing 8051 -NANOCDAC
nanocdac
 
PDF
06 Interfacing Keypad 4x4.2016
Mohamed Fawzy
 
DOCX
Password based door locksystem
UVSofts Technologies
 
PPTX
Microcontroller- An overview
PANIMALAR ENGINEERING COLLEGE
 
PDF
Capacitance Sensing - PC-Compatible USB
Ruth Moore
 
PDF
Capacitance Sensing - PC-Compatible USB CapSense Matrix Keyboard
Ruth Moore
 
PDF
Arduino based Applications-part 6
Jawaher Abdulwahab Fadhil
 
PPTX
Key board interfacing with 8051
DominicHendry
 
PDF
VlSI course project report : Keypad Scanner
Omkar Rane
 
PPT
Lcd & keypad
Izwanizam Yahaya
 
PPT
EMBEDDED PASSWORD BASED ACESS CONTROL SYSTEM USING I2C PROTOCOL
Gaurav Singh
 
Hex keypad
sudheerarao2
 
Keyboard interfacing for the 8051 MCA.ppt
22ecuos015
 
Keyboard Interfacing .pptx
livaunnoor
 
Basic standard calculator
UVSofts Technologies
 
Keypad interfacing
Akhash Kumar
 
Microcontroladores: El microcontrolador 8051 con LCD 16x2
SANTIAGO PABLO ALBERTO
 
Analog to Digital .pptx
karanthakur846894
 
Presentation2 1-150523155048-lva1-app6892
Nirav rathod
 
Keypad interfacing 8051 -NANOCDAC
nanocdac
 
06 Interfacing Keypad 4x4.2016
Mohamed Fawzy
 
Password based door locksystem
UVSofts Technologies
 
Microcontroller- An overview
PANIMALAR ENGINEERING COLLEGE
 
Capacitance Sensing - PC-Compatible USB
Ruth Moore
 
Capacitance Sensing - PC-Compatible USB CapSense Matrix Keyboard
Ruth Moore
 
Arduino based Applications-part 6
Jawaher Abdulwahab Fadhil
 
Key board interfacing with 8051
DominicHendry
 
VlSI course project report : Keypad Scanner
Omkar Rane
 
Lcd & keypad
Izwanizam Yahaya
 
EMBEDDED PASSWORD BASED ACESS CONTROL SYSTEM USING I2C PROTOCOL
Gaurav Singh
 

More from anishgoel (20)

PDF
Computer Organization
anishgoel
 
PDF
Learning vhdl by examples
anishgoel
 
PDF
Dot matrix module interface wit Raspberry Pi
anishgoel
 
PDF
Learning Python for Raspberry Pi
anishgoel
 
PDF
Raspberry Pi
anishgoel
 
PDF
learning vhdl by examples
anishgoel
 
PDF
Digital System Design Basics
anishgoel
 
PPTX
digital design of communication systems
anishgoel
 
PPTX
Rtos concepts
anishgoel
 
PDF
8051 Microcontroller Timer
anishgoel
 
PDF
8051 Microcontroller I/O ports
anishgoel
 
PDF
Serial Communication Interfaces
anishgoel
 
PDF
Embedded systems ppt iv part d
anishgoel
 
PDF
Embedded systems ppt iv part c
anishgoel
 
PDF
Embedded systems ppt iv part b
anishgoel
 
PDF
Embedded systems ppt ii
anishgoel
 
PDF
Embedded systems ppt iii
anishgoel
 
PDF
Embedded systems ppt iv part a
anishgoel
 
PDF
Embedded systems ppt i
anishgoel
 
PDF
Cpld fpga
anishgoel
 
Computer Organization
anishgoel
 
Learning vhdl by examples
anishgoel
 
Dot matrix module interface wit Raspberry Pi
anishgoel
 
Learning Python for Raspberry Pi
anishgoel
 
Raspberry Pi
anishgoel
 
learning vhdl by examples
anishgoel
 
Digital System Design Basics
anishgoel
 
digital design of communication systems
anishgoel
 
Rtos concepts
anishgoel
 
8051 Microcontroller Timer
anishgoel
 
8051 Microcontroller I/O ports
anishgoel
 
Serial Communication Interfaces
anishgoel
 
Embedded systems ppt iv part d
anishgoel
 
Embedded systems ppt iv part c
anishgoel
 
Embedded systems ppt iv part b
anishgoel
 
Embedded systems ppt ii
anishgoel
 
Embedded systems ppt iii
anishgoel
 
Embedded systems ppt iv part a
anishgoel
 
Embedded systems ppt i
anishgoel
 
Cpld fpga
anishgoel
 
Ad

Recently uploaded (20)

PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Depth First Search Algorithm in 🧠 DFS in Artificial Intelligence (AI)
rafeeqshaik212002
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Evaluation and thermal analysis of shell and tube heat exchanger as per requi...
shahveer210504
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Day2 B2 Best.pptx
helenjenefa1
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Design Thinking basics for Engineers.pdf
CMR University
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
Ad

Input interface with Raspberry pi

  • 1. 1 Input Interfacing - Lab II Prof. Anish Goel STTP on " Embedded Systems using Raspberry Pi Single Board Computer" Lab Exercise - II Input Interfacing with R-Pi Introduction Keypads are a part of HMI or Human Machine Interface and play really important role in a small embedded system where human interaction or human input is needed. Martix keypads are well known for their simple architecture and ease of interfacing with any microcontroller. In this part of tutorial we will learn how to interface a 4x4 matrix keypad with R-PI. Also we will see how to program it in Python. Constructing a Matrix Keypad Construction of a keypad is really simple. As per the outline shown in the figure below we have four rows and four columns. In between each overlapping row and column line there is a key. So keeping this outline we can construct a keypad using simple SPST Switches as shown below: Now our keypad is ready, all we have to do is connect the rows and columns to a port of microcontroller and program the controller to read the input. Scanning a Matrix Keypad There are many methods depending on how you connect your keypad with your controller, but the basic logic is same. We make the columns as i/p and we drive the rows making them o/p, this whole procedure of reading the keyboard is called scanning. In order to detect which key is pressed from the matrix, we make row lines low one by one and read the columns. Let's say we first make Row1 low, then read the columns. If any of the key in row1 is pressed will make the corresponding column as low i.e if second key is pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done. So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of the button is pressed in a row, it will take the corresponding column to a low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then column2 and so on.
  • 2. 2 Input Interfacing - Lab II Prof. Anish Goel import RPi.GPIO as gp import time gp.setmode(gp.BOARD) col=[12,10,8] row=[15,13,11] gp.setup(12,gp.OUT,initial=0) gp.setup(10,gp.OUT,initial=0) gp.setup(8,gp.OUT,initial=0) gp.setup(15,gp.IN,pull_up_down=gp.PUD_DOWN) gp.setup(13,gp.IN,pull_up_down=gp.PUD_DOWN) gp.setup(11,gp.IN,pull_up_down=gp.PUD_DOWN) keys=['1','4','7','2','5','8','3','6','9'] def getkeys(): a=[0]*9 gp.output(12,1) for z in range(3): a[z]=gp.input(row[z]) gp.output(12,0) gp.output(10,1) for z in range(3): a[z+3]=gp.input(row[z]) gp.output(10,0) gp.output(8,1) for z in range(3): a[z+6]=gp.input(row[z]) gp.output(8,0) return a a=[0]*9 a=getkeys() entered='' for z in range(9): if a[z]==1: entered+=keys[z]+' ' print 'The keys pressed are:'+entered gp.cleanup()