top of page
Writer's picturePoornima Mani

Interfacing 16*2 LCD with Raspberry Pi using an I2C backpack.

Updated: Sep 29, 2024

This article will teach you How to interface a 16*2 LCD with #RaspberryPi using an #I2C module. The process is very simple and can be used for various projects on which you will be working in the future. The article provides you with a step by step guide on "What all components will be required?", "how to connect the LCD with #RaspberryPi?" and working explanation.


List:

The list provides all the hardware and software components that will be required for the interfacing.



Hardware -


1. #RaspberryPi: #RaspberryPi is a single-board microcomputer which utilizes the SoC, DDR RAM memory, ethernet port, USB host, and micro HDMI on it. It provides the opportunity to interact with the outside world and using its processing power in a compact board at a low cost. In this application, we have used the Python IDE to simplify it.


Raspberry Pi

2. LCD Display- 16*2: This is a versatile electronic module that can display 16 characters per line (this module has 2 such lines). It is cheap and easy to use. Keep reading to know about the implementation.

LCD Display

3. #I2CBackpack/Module: This is a general-purpose bi-directional I/O port expander which is used to convert 8-bit data from I2C serial to 8-bit parallel. A major advantage of this module is that it requires only 2 GPIO lines and hence saves a lot of hardware resources.

I2CBackpack/Module


4. USB Cable for power supply: This cord is used to temporarily connect the #RaspberryPi to the power supply.

USB Cable for power supply

5. Male - Female Jumper wires: As simple as it looks, these are used to connect ends without soldering. While male wired have protruding pins to plug into things, female jumpers are the ends that are used to plug into.

Male - Female Jumper wires

Software-


1. SSH Terminal: SH Terminal is used in this project to connect the #RaspberryPi to the terminal of another computer.

SSH Terminal


2. Python IDE: How does this #RaspberryPi actually work? Programming is done in an IDE (Integrated Development Environment) is a platform where we can write code, run and test the working.


Python IDE

Circuit:


The current address of the I2C module is 0x27. The black wire shown in the circuit is the connection of the ground terminal and the red being Vcc (5V). Though there are multiple pins for ground, the idea is to make the circuit tidy and use the closest supply pin. The SDA and SCL at pin3 and pin5 respectively are responsible for data communication.

What goes where?

  1. RPi Pin 2 - 5V Power

  2. RPi Pin 3 - SDA

  3. RPi Pin 5 - SCL

  4. RPi Pin 14 - Ground



Code:


Initially, all the necessary time modules are imported and 'mylcd' is used as a reference.

Inside the while loop, enter the text messages to be displayed. The function used is lcd_display_string where the parameters are the string to be displayed, line number, and row number respectively.

The sleep function is used to provide a delay in the display and the clear function is used to empty the LCD screen.



Note: Convert the file in python-format(.py) to run the above Main code successfully.


Working:


Ensure that the wiring is proper and adjust the lighting using the trimmer on the I2C module. Once the circuit is implemented, enable the I2C interface so that the code can be run. As we power on, the LCD starts flashing with the message that has been programmed into the #RaspberryPi.

Smart Lighting System with Raspberry Pi


Check the output from the images displayed below.