RPi Pico B.Tech/Diploma Beginner

Interfacing 16×2 LCD Display with Raspberry Pi Pico

Interfacing 16x2 LCD Display with Raspberry Pi Pico & MicroPython Code. HD44780 Based 16X2 I2C & Non-I2C LCD Display with Raspberry Pi Pico

  • Suitable forB.Tech/Diploma RPi Pico students
  • Build time1-2 weeks
  • LevelBeginner
  • Available atAjvika Labs, Kakinada

About this project

Overview
In this tutorial, we will learn Interfacing of 16×2 LCD Display with Raspberry Pi Pico. An LCD is an electronic display module that uses liquid crystal technology to produce a visible image. The 16×2 LCD display is a very basic module commonly used in electronic circuit applications. The 16×2 translates 16 characters per line in 2 such lines. In this LCD each character is displayed in a 5×8 pixel matrix.
Raspberry Pi Pico which was released a few months ago requires some LCD Display in engineering applications. Here we will go through the LCD Display details and features. The LCD Display is based on HD44780 Driver. There are I2C versions and non-I2C versions of LCD Display. We will take both of these LCDs as an example and interface with Raspberry Pi Pico. We will write MicroPython Code for Interfacing 16×2 LCD Display with Raspberry Pi Pico.
Bill of Materials
You need to purchase following components for building this project.
S.N.
Components
Quantity
Purchase Links

Raspberry Pi Pico

Amazon
AliExpress

16x2 LCD Display

Amazon
AliExpress

10K Potentiometer

Amazon
AliExpress

16x2 I2C LCD Display

Amazon
AliExpress

Jumper Wires

Amazon
AliExpress

BreadBoard

Amazon
AliExpress
Brief Description of 16X2 LCD Display
16×2 LCD is named so because it has 16 Columns and 2 Rows. So, it will have (16×2=32) 32 characters in total and each character will be made of 5×8 Pixel Dots. A Single character with all its Pixels is shown in the below picture.
Each character has (5×8=40) 40 Pixels and for 32 Characters we will have (32×40) 1280 Pixels. Further, the LCD should also be instructed about the Position of the Pixels. Hence it will be a complicated task to handle everything with the help of a microcontroller. Hence the LCD uses an interface IC like HD44780. This IC is mounted on the backside of the LCD Module. You can check the
HD44780 Datasheet
for more information.
The function of this IC is to get the Commands and Data from the MCU and process them to display meaningful information on LCD Screen. The LCD operating Voltage is 4.7V to 5.3V & the Current consumption is 1mA without a backlight. It can work on both 8-bit and 4-bit mode
It can also display any custom-generated characters. These LCDs are available in Green and Blue Backlight.
There are two section pins on the whole 16×2 LCD module. Some of them are data pins and some are command pins. Somehow, every pin has a role in controlling a single pixel on the display.
16X2 I2C LCD Display
This display incorporates an I2C interface that requires only 2 pins on a microcontroller to the interface. The I2C interface is a daughter board attached to the back of the LCD module. The I2C address for these displays is either 0x3F or 0x27.
The adapter has an 8-Bit I/O Expander chip
PCF8574
. This chip converts the I2C data from a microcontroller into the parallel data required by the LCD display. There is a small trimpot to make fine adjustments to the contrast of the display. In addition, there is a jumper on the board that supplies power to the backlight.
Interfacing 16×2 LCD Display with Raspberry Pi Pico
Now, let us interface the 16×2 LCD Display with Raspberry Pi Pico. You can use Fritzing Software to draw the Schematic. You can assemble the circuit on breadboard as shown in the image below.
Connect the pin 1, 5 & 16 of LCD to GND of Raspberry Pi Pico. Similarly, connect the Pin 2 & 15 of LCD to 5V Pin, i.e Vbus of Raspberry Pi Pico. Connect the Pin 4, 6, 11, 12, 13, 14 of LCD Display to Raspberry Pi Pico GP16, GP17, GP18, GP19, GP20, GP21 Pin.
To adjust the LCD Contrast, connect a 10K Potentiometer at Pin 3 of LCD Display.
Source Code/Program
Raspberry Pi Pico supports MicroPython Program for interfacing 16×2 LCD Display. You can either use
Thonny IDE
or
uPyCraft IDE
for running the MicroPython Code.
Here is a complete code for interfacing the 16X2 HD44780 LCD with Raspberry Pi Pico. Copy the code to the IDE and save it with the name main.py.

import
machine
import
utime
rs
=
machine
Pin
(

machine
Pin
OUT
)
e
=
machine
Pin
(

machine
Pin
OUT
)
d4
=
machine
Pin
(

machine
Pin
OUT
)
d5
=
machine
Pin
(

machine
Pin
OUT
)
d6
=
machine
Pin
(

machine
Pin
OUT
)
d7
=
machine
Pin
(

machine
Pin
OUT
)
def
pulseE
(
)
:
e
value
(

)
utime
sleep_us
(

)
e
value
(

)
utime
sleep_us
(

)
def
send2LCD4
(
BinNum
)
:
d4
value
(
(
BinNum
&
0b00000001
)
>>

)
d5
value
(
(
BinNum
&
0b00000010
)
>>

)
d6
value
(
(
BinNum
&
0b00000100
)
>>

)
d7
value
(
(
BinNum
&
0b00001000
)
>>

)
pulseE
(
)
def
send2LCD8
(
BinNum
)
:
d4
value
(
(
BinNum
&
0b00010000
)
>>

)
d5
value
(
(
BinNum
&
0b00100000
)
>>

)
d6
value
(
(
BinNum
&
0b01000000
)
>>

)
d7
value
(
(
BinNum
&
0b10000000
)
>>

)
pulseE
(
)
d4
value
(
(
BinNum
&
0b00000001
)
>>

)
d5
value
(
(
BinNum
&
0b00000010
)
>>

)
d6
value
(
(
BinNum
&
0b00000100
)
>>

)
d7
value
(
(
BinNum
&
0b00001000
)
>>

)
pulseE
(
)
def
setUpLCD
(
)
:
rs
value
(

)
send2LCD4
(
0b0011
)
#8 bit
send2LCD4
(
0b0011
)
#8 bit
send2LCD4
(
0b0011
)
#8 bit
send2LCD4
(
0b0010
)
#4 bit
send2LCD8
(
0b00101000
)
#4 bit,2 lines?,5*8 bots
send2LCD8
(
0b00001100
)
#lcd on, blink off, cursor off.
send2LCD8
(
0b00000110
)
#increment cursor, no display shift
send2LCD8
(
0b00000001
)
#clear screen
utime
sleep_ms
(

)
#clear screen needs a long delay
setUpLCD
(
)
rs
value
(

)
for
in
'Hello World!'
:
send2LCD8
(
ord
(
)
)
Hence, once you run the code, the LCD Display will start showing the Hello World! message in LCD Display.
Interfacing 16×2 I2C LCD Display with Raspberry Pi Pico
The above code is valid for 16×2 LCD Display without any I2C Module. The PCF8574 I2C or SMBus module simplifies the above connection. Instead of using so many wiring, you can use this IC Module and convert the data output lines just to 2 pins.
Hence the LCD Display becomes an I2C Display with an I2C address of 0x27. The connection between the Raspberry Pi Pico and I2C LCD is very simples as shown below in the schematic.
Connect the LCD VCC & GND Pin to Raspberry Pi Pico 5V & GND Pin respectively. Connect the SDA & SCL pin of LCD to Raspberry Pi Pico GP8 & GP9 respectively.
Source Code/Program
The program for this section is divided into 3 parts. We need to write some driver code as well as I2C protocol code for this part.
Copy all this code and then save all of the 3 codes to Raspberry Pi Pico Board.
lcd_api.py

import
time
class
LcdApi
:
LCD_CLR
=
0x01
# DB0: clear display
LCD_HOME
=
0x02
# DB1: return to home position
LCD_ENTRY_MODE
=
0x04
# DB2: set entry mode
LCD_ENTRY_INC
=
0x02
# --DB1: increment
LCD_ENTRY_SHIFT
=
0x01
# --DB0: shift
LCD_ON_CTRL
=
0x08
# DB3: turn lcd/cursor on
LCD_ON_DISPLAY
=
0x04
# --DB2: turn display on
LCD_ON_CURSOR
=
0x02
# --DB1: turn cursor on
LCD_ON_BLINK
=
0x01
# --DB0: blinking cursor
LCD_MOVE
=
0x10
# DB4: move cursor/display
LCD_MOVE_DISP
=
0x08
# --DB3: move display (0-> move cursor)
LCD_MOVE_RIGHT
=
0x04
# --DB2: move right (0-> left)
LCD_FUNCTION
=
0x20
# DB5: function set
LCD_FUNCTION_8BIT
=
0x10
# --DB4: set 8B

Technologies used

Raspberry PiBLELCDPythonI2CMicroPython

Hardware components

  • Raspberry Pi

Software & tools

  • Thonny
  • MicroPython
  • Fritzing

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.