Interface 16x2 Alphanumeric LCD And4x4 Matrix Keypad With Raspberry Pi3

by iTechnoLabz in Circuits > Raspberry Pi

12288 Views, 24 Favorites, 0 Comments

Interface 16x2 Alphanumeric LCD And4x4 Matrix Keypad With Raspberry Pi3

41-anivAqRL._SY300c_.jpg

In this instructables, we explain how to interface 16x2 LED and 4x4 matrix keypad with Raspberry Pi3.

We use Python 3.4 for developing the software. You can choose Python 2.7 also, with little alterations

Materials Required

compo.jpg

    We require the following components

  • Raspberry Pi 3
  • 5V 2A Adaptor for Pi
  • 8GB micro SD
  • 16x2 Alphanumeric LCD
  • 4x4 matrix Keypad
  • Dot PCB (medium size) or Breadboard
  • Berg Strip
  • Jumper Wire
  • 10K pot
  • Ethernet Cable (for establishing VNC connection with Laptop)

Hardware Setup

IMG_20171224_165606_HDR.jpg
rp3.png
lcd_pinout.png
4x4KP.png
term.png

We did not Include the steps for hardware setup such as burning OS to the micro SD and VNC interface. You have to find other resources for these procedures.

Insert OS pre-loaded 8GB Micro SD card into Rapberry Pi 3. Connect Raspberry Pi to Laptop by Ethernet Cable. Make the hardware as described in the wiring diagram.

16x2 LCD

We use 4-bit mode lcd interface, so the required pins for Control singals are RS, EN, D4, D5, D6, D7 which is connected to GPIOs of Raspberry Pi.


4x4 Matrix Keypad

Install Python package for 4x4 and 4x3 matrix keypad so that interrupt based operations are performed. Thus no need to scan keypad’s rows and columns all the time. Here internal pull-up used thus no external pull-up resistor required.

Connect Raspberry Pi to web, then open terminal and type the following:

sudo python3.4 -m pip install pad4pi


Wiring Diagram

wiring.jpg

LCD Pins:

  • LCD_RS = 21
  • LCD_E = 20
  • LCD_D4 = 26
  • LCD_D5 = 19
  • LCD_D6 = 13
  • LCD_D7 = 6

KeyPad pins:

Column Pins = 17, 15, 14, 4
Row Pins = 24, 22, 27, 18

You can choose any GPIO pins for interfacing LCD and Keypad, just change pin number in the code. You can either use breadboard or PCB for interfacing LCD and Keypad.


Python Code

2017-12-24-113423_1280x720_scrot.png

You can download the code directly. Run code.py with python 3.4 in your Raspberry Pi 3. Or copy the text and paste it in new script file of python 3.4.

Run the progam:

LCD will display the text "Welcome" in the first line if the connections you made are correct. The Keypad data is displayed in the second line.

Downloads

Output Preview

IMG_20171224_170855.jpg
IMG_20171224_171024.jpg
IMG_20171224_171234c.jpg

I have added Keyboard interrupt, so that if you terminate program LCD will display Good bye