Connect I2C 1602 LCD to Raspberry Pi Pico (RP2040)

Javed Ameen Shaikh
3 min readMar 3, 2021

Ever since Raspberry foundation release their in-house microcontroller Pico (RP2040), I wanted to try it since it was so cheap and works with Micropython (the one I am familiar with :P). During the getting started tutorials, I got to know that the Pico comes up with an onboard temperature sensor. I got excited and made a program to read the surrounding temperature and notify users by lighting LEDs for their corresponding temperature range. This works but NOT ENOUGH!

Here comes a cheap LCD panel for the rescue 😃. I bought a cheap I2C 1602 LCD to show the temperature. The problem was that the instructions provided were not in Micropython, so I started Googling and found this Github repository. I extracted the files needed to operate the LCD that I am using and simplified the setup process.

Enough of the story, Lets actually setup the LCD 📺

Items used-

  • Raspberry Pi Pico RP2040
  • I2C 1602 LCD display
  • Breadboard and jumper wires

Step 1 – Circuit diagram

Once the connections are made you will notice that the LCD lights up. You might need to rotate the potentiometer at the back of LCD to adjust the contrast to see the characters.

Also check your LCD voltage preferences, the one I am using needs 5V Pico pin to be connected to VCC. That’s why I have connected VCC to VBUS (as it provides 5V). You can use any other GPIO pins for SDA & SCL pins but make sure you change the corresponding pin number in the Micropython script too.

Step 2 – LCD libraries

These are the bare minimum library to operate the LCD.

https://github.com/javed0863/RP2040/blob/main/i2c/lcd_api.py
https://github.com/javed0863/RP2040/blob/main/i2c/machine_i2c_lcd.py

Also, note the default address of your I2C from the device documentation or you can also try the bus scan using Micropython. The code is as below:

import machine
sda=machine.Pin(0)
scl=machine.Pin(1)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
print(i2c.scan())

It will tell you the address in DECIMAL (in my case ‘39’), you need to convert it to hex (in my case the hex converted value for 39 is ‘0x27’). Once you have the right value, update it in the “DEFAULT_I2C_ADDR” field in your source code.

Step 3 – Reading temperature

You can follow this script to get the temperature reading from your Raspberry Pi Pico

https://github.com/javed0863/RP2040/blob/main/temperature.py

Step 4 – Operate LCD

Use this script to test your LCD setup and perform different types of operations.

https://github.com/javed0863/RP2040/blob/main/i2c/i2c-test-1.py

Step 5— Integration

Create app.py and use source code from steps 3 & 4 to read the temperature and write it to the LCD panel. You can refer my final source code below.

https://github.com/javed0863/RP2040/blob/main/i2c/main.py

Success

Now, to run this script automatically when connected to a power source, save it as main.py in your Pico and we are DONE 🥳.

--

--