Questions And Answers

More Tutorials

Raspberry Display Hello world with LCD

After adding the library file, let's write a simple program to let the LCD display "Hello, world!".

Hardware Connection

In this project, the electronic hardware we need to use is as follows:

• Raspberry Pi Pico

• Grove Shield for Pi Pico

• Grove - 16 x 2 LCD

Plug the Pico and the Shield, use a Grove data cable to connect the LCD to I2C1.

Write a Program

First, define the function libraries that we need to use, including the third-party function library lcd1602 that has just been saved in the Pico.

1 from lcd160
2 import LCD1602 2 from machine import I2C, Pin 
3 from utime import sleep

The functions available in the lcd library are as follows:

• display() — Enable the display.

• no_display() — Disable the display.

• clear() — Clear the current display and return the cursor.

• setCursor(col, row) — Set the display position, “col" is the number of columns, “row" is the number of rows.

• print(text) — Display characters.

Next, define the pin. Unlike other pin definitions, pin I2C needs to define data lines SCL and SDA respectively.

1 i2c = 12C(1, scl=Pin(7), sda=Pin(6), freq=400000)

It is written as “machine.I2C(id,*,scl,sda,freq=400000)", where:

• “id" identifies a specific I2C peripheral, and its allowed value depends on the specific port/ board.

• “scl" uses the Pin function to specify the pin used for SCL.

• “sda" uses the Pin function to specify the pin used for SDA.

• “freq" is the integer of the maximum frequency of SCL, which is generally adjusted according to the different devices used. Here we set it to 40000.

Finally, use the functions in the library to display “Hello, World" on the LCD, and the program is completed. The complete program is as follows:

1 from lcd1602 import LCD1602 
2 from machine import I2C, Pin 
3 from utime import sleep 
4 i2c = I2C(1, scl=Pin(7), sda=Pin(6), freq=400000) 
5 d = LCD1602(i2c, 2, 16) #label data type, number of lines and characters per line
7 d.display ( ) #enable display 
8 sleep(1)
9 d.clear()#clear display 
10 d.print('Hello ') #display characters
12 sleep(1) 
13 d.setCursor(0, 1)#set display position, row and column start from o 
14 d.print('world ').

Use a USB cable to connect Pico to the computer, click the “run" button to save the program to any location, you can see the program in action.


In this page (written and validated by ) you learned about Raspberry Display Hello world with LCD . What's Next? If you are interested in completing Raspberry tutorial, your next topic will be learning about: Raspberry Display Rotary Angle Sensor Reading with LCD.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.