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:

Raspberry Pi Pico and LCD I2C 20x4

Hardware Preparation

1×Raspberry Pi Pico W
1×Raspberry Pi Pico (Alternatively)
1×Micro USB Cable
1×LCD 20x4
1×Jumper Wires
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)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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 20x4 I2C Pinout

LCD Coordinate

The LCD I2C 20x4 includes 20 columns and 4 rows. Both columns and rows begin at 0.

Raspberry Pi Pico LCD I2C Coordinate

Wiring Diagram

The wiring diagram between Raspberry Pi and Pico LCD 20x4 I2C

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.

""" This Raspberry Pi Pico MicroPython code was developed by newbiely.com This Raspberry Pi Pico code is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-lcd-20x4 """ from machine import I2C, Pin from DIYables_MicroPython_LCD_I2C import LCD_I2C import utime # The I2C address of your LCD (Update if different) I2C_ADDR = 0x27 # Use the address found using the I2C scanner # Define the number of rows and columns on your LCD LCD_COLS = 20 LCD_ROWS = 4 # Initialize I2C i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) # Initialize LCD lcd = LCD_I2C(i2c, I2C_ADDR, LCD_ROWS, LCD_COLS) # Setup function lcd.backlight_on() lcd.clear() # Main loop function while True: lcd.clear() lcd.set_cursor(0, 0); # Move cursor at the first row, first column lcd.print("LCD 20x4"); # Display text at the first row lcd.set_cursor(0, 1); # Move cursor at the second row, first column lcd.print("I2C Address: 0x27"); # Display text at the second row lcd.set_cursor(0, 2); # Move cursor at the third row, first column lcd.print("DIYables"); # Display text at the third row lcd.set_cursor(0, 3); # Move cursor at the fourth row, first column lcd.print("www.diyables.io"); # Display text at the fourth row utime.sleep(2) lcd.clear() lcd.set_cursor(0, 0) # Move to the beginning of the first row lcd.print("Int: ") lcd.print(str(197)) # Print integer lcd.set_cursor(0, 1) # Move to the beginning of the second row lcd.print("Float: ") lcd.print(str(26.39)) # Print float utime.sleep(2)

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.
Raspberry Pi Pico 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.
Raspberry Pi Pico 20x4 LCD

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

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!