Raspberry Pi Pico - LCD 20x4
In this guide, we will teach you how to connect a 20x4 LCD display to a Raspberry Pi Pico board using an I2C interface. We will cover:
- How to connect a 20x4 LCD I2C to a Raspberry Pi Pico
- How to program a Raspberry Pi Pico to display text, integer, float number and custom characters on a 20x4 LCD I2C
Hardware Preparation
1 | × | Raspberry Pi Pico W | |
1 | × | Raspberry Pi Pico (Alternatively) | |
1 | × | Micro USB Cable | |
1 | × | LCD 20x4 | |
1 | × | Jumper Wires | |
1 | × | Breadboard | |
1 | × | (Optional) Screw Terminal Expansion Board for Raspberry Pi Pico |
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of LCD I2C 20x4
Pinout
The LCD 20x4 I2C connects using the I2C interface and has 4 pins.
- GND pin: Connect this to GND (0 volts).
- VCC pin: Connect this to VCC (5 volts) to power the LCD.
- SDA pin: Used for I2C data signal.
- SCL pin: Used for I2C clock signal.
LCD Coordinate
The LCD I2C 20x4 includes 20 columns and 4 rows. Both columns and rows begin at 0.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
LCD I2C | Raspberry Pi Pico |
---|---|
VCC | 5V |
GND | GND |
SDA | GP0 (SDA) |
SCL | GP1 (SCL) |
Raspberry Pi Pico Code
The below MicroPython code displays string, integer and float number on LCD 20x4 display.
Detailed Instructions
Please follow these instructions step by step:
- Ensure that Thonny IDE is installed on your computer.
- Ensure that MicroPython firmware is installed on your Raspberry Pi Pico.
- If this is your first time using a Raspberry Pico, refer to the Raspberry Pi Pico - Getting Started tutorial for detailed instructions.
- Connect the LCD 20x4 display to the Raspberry Pi Pico according to the provided diagram.
- Connect the Raspberry Pi Pico to your computer using a USB cable.
- Launch the Thonny IDE on your computer.
- On Thonny IDE, select MicroPython (Raspberry Pi Pico) Interpreter by navigating to Tools Options.
- In the Interpreter tab, select MicroPython (Raspberry Pi Pico) from the drop-down menu.
- Ensure the correct port is selected. Thonny IDE should automatically detect the port, but you may need to select it manually (e.g., COM3 on Windows or /dev/ttyACM0 on Linux).
- Navigate to the Tools Manage packages on the Thonny IDE.
- Search “DIYables-MicroPython-LCD-I2C”, then find the LCD I2C library created by DIYables.
- Click on DIYables-MicroPython-LCD-I2C, then click Install button to install LCD I2C library.
- Copy the above provided code and paste it to the Thonny IDE's editor.
- Save the script to your Raspberry Pi Pico by:
- Click the Save button, or use Ctrl+S keys.
- In the save dialog, you will see two sections: This computer and Raspberry Pi Pico. Select Raspberry Pi Pico
- Save the file as main.py
- Click the green Run button (or press F5) to run the script. The script will execute.
- Check out the result on the LCD 20x4 display.
If you name your script main.py and save it to the root directory of the Raspberry Pi Pico, it will automatically run each time the Pico is powered on or reset. This is useful for standalone applications that need to start running immediately upon power-up. If you name your script another name other than main.py, you will need to manually run it from Thonnys's Shell.
Video Tutorial
The below video shows the instruction for LCD I2C 16x2, but it is similar for LCD I2C 20x4
Raspberry Pi Pico - 20x4 LCD - Custom Character
It is similar to LCD 16x2, you can refer to the custom character section on Raspberry Pi Pico - LCD I2C tutorial, and then adapt it for LCD 20x4 display