In this quick tutorial, learn how to connect 16X2 LCD display module without I2C adapter with Raspberry Pi Pico board which requires lots of wire connections and also learn connecting Raspberry Pi Pico board with 16X2 LCD display module using I2C adapter which uses only 2 wires for data transfer and 2 wires to power up.
Many latest Microcontroller boards are coming along with WiFi and Bluetooth which can create webservers to display the data on PC or mobile displays but the new Raspberry Pi Pico neither has WiFi nor Bluetooth, To play with projects and to display the output it has only 2 options to display the data either on Serial monitor or by connecting a LCD display or OLED display. We can add WiFi to Raspberry Pi Pico to create a webserver but it moves towards very complex side. So, lets know the process and coding to connect Pico board with 16×2 LCD display and same for 20X4 LCD display and display some simple text on it.
16X2 LCD display module:
As the name indicates 16X2, means it can display characters in 16 columns and 2 rows and LCD is the Liquid crystal Display. It can display total of 16X2=32 characters. Each character is made with 5width x 8height pixel dots =total 40 pixel dots for one character. To make a character, pixel dots should be lit black according to the character shape and other pixels should be in off state. So for every character all the 40 pixel dots are to be instructed weither to be lit on or off.
As our 16X2 LCD display has 32 Characters, there should be 32X40=1280 instructions to be sent to display 32 characters on the display, which is a very complex task for microcontrollers. So, to overcome this issue, an IC HD44780 which can process the data and commands from the microcontrollers and convert them into LCD meaningful instructions to display the data on it. It has a separate library with instructions and commands, if you want to twerk with it to build anything advanced refer its datasheet here.
As you can see from the above LCD display module pinout diagram the display is powered with VCC:5v and GND. It has 8 data pins for 8 bit data but we can also use 4 bit data mode which we are using in this example. has pins for LCD backlight and contrast adjustments using potentiometer.
Method1: Interfacing 16X2 LCD display module with Raspberry Pi Pico with out I2C adapter
Required components (Bill of Materials):
|16X2 LCD module without I2C||1||https://amzn.to/3I3Uaax||https://amzn.to/363ki7F|
|Raspberry Pi Pico Board(seedstudio)||1||https://amzn.to/36gKUlu||https://amzn.to/3sTnD1Z|
|Few Connecting Wires||https://amzn.to/3H2BV4e||https://amzn.to/3J0WVu2|
|5V power supply (Micro USB or External).||1||https://amzn.to/3s1a8g3||https://amzn.to/364yInH|
Connect all the required components listed above as shown in the schematic diagram below. for details on pins look at the Raspberry Pi Pico Pinout diagram.
As you can see from the above connection diagram you can see VSS,A pins from LCD display are connected to 5v supply from pin 40 Vbus of Raspberry Pi Pico. VSS, RW and K are connected to GND of Raspberry Pi Pico, RS and E pins of LCD display are connected to 21,22(GP16,GP17) of Pico board. The data pins D4,D5,D6 and D7 of LCD display are connected to 24,25,26 and 27 pins(GP18,GP19,GP20,GP21) of Raspberry pi Pico respectively.
Potentiometer first pin is connected to 5v, second pin to VO of LCD, third pin to GND.
Source code for LCD with no I2C:
After connecting all the required components as shown in the above circuit diagram, next step is to upload the code, Raspberry Pi Pico supports Micro python code which can be installed using PC as explained in our previous projects. After installing Micro Python we need Thonny IDE to compile and upload the code to Raspberry Pi Pico. So, copy the below code and paste it in Thonny IDE workspace.
Note: We need to add few libraries to make the LCD fully functional with multiple commands. Download below files and copy them on the Raspberry Pi Pico root folder.
After opening the library files now click on file-> new and copy the below code and paste in the new workspace and save with name: mainlcd.py
from machine import Pin
from gpio_lcd import GpioLcd
# Create the LCD object
lcd = GpioLcd(rs_pin=Pin(21),
# #The following line of codes should be tested one by one according to your needs
# #1. To print a string to the LCD, you can use
# #2. Now, to clear the display.
# #3. and to exactly position the cursor location
# # If you do not set the cursor position,
# # the character will be displayed in the
# # default cursor position starting from
# # 0, x and 0, y location which is the top left-hand side.
# # There are other useful functions we can use in using the LCD.
# #4. Show the cursor
# #5. Hide the cursor
# #6. Turn ON blinking cursor
# #7. Turn OFF blinking cursor
# #8. Disable display
# this will only hide the characters
# #9. Enable display
# #10. Turn backlight OFF
# #11. Turn backlight ON
# # 12. Print a single character
# but this will only print 1 character
# #13. Display a custom characters using hex codes, you can create the character from <a href="https://maxpromer.github.io/LCD-Character-Creator/">here.</a>
# happy_face = bytearray([0x00,0x0A,0x00,0x04,0x00,0x11,0x0E,0x00])
# lcd.custom_char(0, happy_face)
After uploading the code you can see the text circuitschools. displayed on the first line and LCD16x2display on the second line of LCD module as shown in the below image output image.
Method2: Interfacing 16X2 LCD display module with Raspberry Pi Pico with I2C adapter
This method is simple and easier than the previous method as it uses I2C interface protocol to transfer the data using only 2 pins SDA and SCL. In this method we are using 16X2 LCD display module which has I2C adapter connected to 16 pins of normal LCD display and outputs only 4 pins.
The I2c adapter has PCF8574 8-Bit I/O Expander IC which converts the I2C data from the microcontrollers to parallel data required to the LCD display module. This adapter has a jumper to turn ON/OFF the backlight which can save the power consumption, and also has an inbuilt potentiometer to adjust the contrast of the LCD display module.
- Raspberry Pi Pico microcontroller board
- 16X2 LCD module with i2c adapter
- Few connecting wires.
Connect all the required components listed above as shown in the below schematic diagram
As you can see there are only 4 connecting wires, the LCD module VCC and GND are powered from VBUS(pin40) and GND(pin38) pins of Raspberry pi Pico board respectively. The data pins of LCD module SDA and SCL are connected to GP8(pin11) and GP9(pin12) of Pico board which acts as SDA and SCL as you can see from the Raspberry Pi Pico pinout diagram.
If you previously connected a non I2C LCD display module with Pico board and now with this method you feel like “Wow! this is so easy and clean…”.
Related article: Interfacing 16X2 LCD Module with ESP32 with and without I2C
After connecting according to the connection diagram, next step is to upload the code, as Raspberry Pi Pico support MicroPython, Install micropython on it and Upload the code using Thonny IDE.
Note: LCD display I2C requires few pre coded libraries, download them from below links.
After downloading the above files copy them into the Raspberry Pi Pico MicroPython directory. Now open Thonny IDE and click new and copy the below code and paste in the workspace.
from machine import I2C, Pin
from pico_i2c_lcd import I2cLcd
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=100000)
I2C_ADDR = i2c.scan()
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
With the above code we are able to get the I2C address of the LCD display and print it on the Shell and LCD display module in line 1 and print simple text in second line of LCD. This code can be also used as an I2C address scanner code as it scans and collect the addresses of I2C devices connected with the below code.
I2C_ADDR = i2c.scan()
# is for the first device address connected, as we have only one i2c device connected we are using 0
Mainly the LCD displays with PCF8574 I2C adapter has I2C addresses 0x27 or 0x3F. So after uploading the code you can see the output on the LCD display as shown in the below image.
If you found this project helpful please share our site with your friends and help them learn. If you have any doubts or errors regarding this project please through comments on us from the below comments section. Thanks with love 🙂