Raspberry Display Hello world with LCD
After adding the library file, let's write a simple program to let the LCD display "Hello, world!".
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.
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.
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:
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.