One of the most commonly used devices on Arduino to display information is the 16×2 LCD screen. Liquid Crystal Displays (LCD) have the advantage of creating flat displays with low power consumption.
They work by polarizing light through polarizing filters. Liquid crystals do not produce light but modify their transparency depending on the orientation of the filters. This is why an external light source is necessary for them to be visible.
Let’s look at the different pins of the LCD screen:
Vss: Connect to ground
Vdd: Connect to +5V
VEE or VO: Connect to a potentiometer to adjust contrast
Rs: Control the memory register
R/W: Select read or write mode
E: When low, triggers the execution of instructions by the LCD module
D0-D7: Read and write data
A and K: Control the backlight
To use the LCD screen, you need a library: LiquidCrystal.zip. It contains a set of functions that will simplify your code and the use of the 16×2 screen.
To install it, open the Arduino IDE and click on Sketch, then Include Library, and finally Add .ZIP Library as shown below:
Here is the program to use with the Arduino IDE for your Raspberry Pi Pico:
// LCD1602 and Pi Pico!
#include <LiquidCrystal.h>
// Initialize the LCD with the pins connected to the Pi Pico
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16, 2); // Set up the LCD with 16 columns and 2 rows
lcd.print("Arduino Factory!"); // Print "Arduino Factory!" on the first line
lcd.setCursor(2, 1); // Move cursor to the 3rd column of the 2nd row
lcd.print("> Pi Pico <"); // Print "> Pi Pico <" on the second line
}
void loop() {
delay(1); // Adding a delay() here speeds up the simulation (optional)
}