Introduction: Interface 16x2 Alphanumeric LCD And4x4 Matrix Keypad With Raspberry Pi3

About: We are a bunch of passionate, enthusiastic and talented engineers with a craze on robotics and embedded systems. We aim to develop novel and high end robots and embedded technologies for a wide range of applic…

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

Step 1: Materials Required

    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)

Step 2: Hardware Setup

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

Step 3: Wiring Diagram

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.

Step 4: Python Code

You can download the code directly. Run 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.


Step 5: Output Preview

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

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017