< All Topics
Print

Interfacing a 2004LCD Screen using a RP2040 and MicroPython

Introduction

This project aims to interface a 2004 LCD screen with an RP2040 (Rapsberry Pi Pico variant model), using MicroPython.

For this project, Thonny will be development environment that MicroPython will be written in. the By the end of this tutorial, you will have a basic understanding of MicroPython and how it can be used to program microcontrollers. This project is great for those looking to start learning MicroPython to program microcontrollers or embedded devices.

Materials:

  • RP2040 core board (Raspberry Pi Pico)
  • PC with Thonny installed
  • Breadboard
  • Jumper Cables
  • USB-A to USB-C cable to power the Raspberry Pi Pico (with data transfer capability)
  • 2004 LCD display module

Below is a pin out diagram for the RP2040 board that is being used for this project.

About the 2004 LCD display

The 2004 LCD s a dot matrix module that is designed to display alphanumeric characters and symbols. It has a capacity to display 4 lines of 20 characters. The 2004 LCD display model being used can use the I2C communication protocol, increasing the pin efficiency of the module. 

 
Power Connections:

Wire the LCD’s VCC pin to the Raspberry Pi Pico Vout pin. Connect the GND pin to an available GND pin on the Raspberry Pi Pico.

Communication:

Wire the SCL pin of the LCD to pin 5 (GP5) in the Raspberry Pi Pico. Wire the SDA pin of the LCD to the Raspberry Pi Pico’s pin 4 (GP4).

The image below shows the wiring diagram for the Raspberry Pi Pico and the 2004 LCD screen.

Click to expand

Setup and required libraries:

For this tutorial, the SDA and SCL pins of the LCD can be wired to GPIO pins of your preference, as the pins used can be specified in the MicroPython code. After wiring up the board and LCD and connecting it to the PC, open Thonny. After opening Thonny, change the interpreter on the bottom right hand side to be the Raspberry Pi Pico, using MicroPython.

On your browser, open the following link: https://pypi.org/project/micropython-i2c-lcd/#upload-files-to-board

Download the file, it is a .tar.gz file. Open the lcd_i2c file inside, and open all the .py files using Thonny. Using Thonny, create a new directory in the ‘lib’ file of the Raspberry Pi Pico and name it ‘lcd_i2c’, and save all the .py files of the lcd_i2c file on your PC there. You have essentially added the MicroPython I2C LCD library to the Pico board you are using. If you open the file called ‘lcd_i2c.py’ from the ‘lcd_i2c’ file in the Raspberry Pi Pico, you can view the class called LCD, its properties and functions, all of which you can use once importing the LCD class.

Python Code:

After successfully adding the library into the Raspberry Pi Pico, open a new file using Thonny.

Type out the following code onto the new script:

Save this code onto the Raspberry Pi board and run it. The LCD will display some text upon initialisation. You can change the text displayed according to your preference.

The image below shows the 2004 LCD lit up, displaying the text as programmed in the MicroPython code.

End Result

Running the code with the setup for this project should result in the following output on the LCD screen below.

Click to expand

Downloadable Content

Please find the code for this tutorial on our GitHub page.

Credits:

  • Maker Community
  • The Raspberry Pi Community
  • The STEM Community
Table of Contents