This comprehensive tutorial shows how to interface a 16x2 character LCD display with a Raspberry Pi Pico microcontroller using the Wokwi online simulator. Learn to display custom text messages, create scrolling effects, and build the foundation for embedded display projects.
What You'll Learn
- LCD parallel interface communication
- Raspberry Pi Pico GPIO programming
- MicroPython LCD library usage
- Wokwi simulator for Pico projects
- Character LCD display control
Components Required in Wokwi
Hardware (Virtual):
- 1x Raspberry Pi Pico board
- 1x LCD 16x2 display (HD44780 compatible)
- 1x 10kΩ potentiometer (for contrast adjustment)
- Multiple jumper wires (automatic in Wokwi)
Software/Libraries:
- MicroPython firmware
- LCD library (machine_i2c_lcd or gpio_lcd)
Understanding the 16x2 LCD Display
LCD Pin Configuration
The 16x2 LCD has 16 pins:
| Pin No. | Symbol | Function | Description |
|---|---|---|---|
| 1 | VSS | Ground | Power ground (0V) |
| 2 | VDD | Power | +5V or +3.3V power supply |
| 3 | V0/VEE | Contrast | Contrast adjustment (via potentiometer) |
| 4 | RS | Register Select | Data/Command selection (0=Command, 1=Data) |
| 5 | RW | Read/Write | Read or Write (0=Write, 1=Read) - usually grounded |
| 6 | E | Enable | Enable signal (triggers data read/write) |
| 7-14 | D0-D7 | Data Pins | 8-bit data bus (we use 4-bit mode: D4-D7) |
| 15 | A/LED+ | Backlight Anode | Backlight positive (+5V) |
| 16 | K/LED- | Backlight Cathode | Backlight negative (GND) |
Operating Modes
- 8-bit mode: Uses all 8 data pins (D0-D7)
- 4-bit mode: Uses only 4 data pins (D4-D7) - saves GPIO pins ✅
This tutorial uses 4-bit mode to conserve Raspberry Pi Pico GPIO pins.
Step-by-Step Wokwi Setup Instructions
Step 1: Create New Raspberry Pi Pico Project
- Go to https://wokwi.com
- Click "New Project"
- Select "Raspberry Pi Pico"
- The Pico board appears on your canvas
Step 2: Add LCD Display Component
Step 3: Add Potentiometer for Contrast Control
- Click the "+" button again
- Search for "Potentiometer"
- Select "Potentiometer" (10kΩ)
- Place it near the LCD
Step 4: Understanding the Wiring Connections
Diagram.json:
{
"version": 1,
"author": "Uri Shaked",
"editor": "wokwi",
"parts": [
{
"type": "wokwi-pi-pico",
"id": "pico",
"top": 123.67,
"left": 135.97,
"rotate": 90,
"hide": false,
"attrs": { "env": "arduino-community" }
},
{
"type": "wokwi-lcd1602",
"id": "lcd",
"top": -17.85,
"left": 22.03,
"rotate": 0,
"hide": false,
"attrs": {}
},
{
"type": "wokwi-resistor",
"id": "r1",
"top": 114.8,
"left": 226.31,
"rotate": 0,
"hide": false,
"attrs": { "value": "220" }
}
],
"connections": [
[ "pico:GND.1", "lcd:VSS", "black", [ "v-51", "*", "h0", "v18" ] ],
[ "pico:GND.1", "lcd:K", "black", [ "v-51", "*", "h0", "v18" ] ],
[ "pico:GND.1", "lcd:RW", "black", [ "v-51", "*", "h0", "v18" ] ],
[ "pico:VSYS", "lcd:VDD", "red", [ "v16", "h-16" ] ],
[ "pico:VSYS", "r1:2", "red", [ "v16", "h0" ] ],
[ "r1:1", "lcd:A", "pink", [] ],
[ "pico:GP12", "lcd:RS", "blue", [ "v-16", "*", "h0", "v20" ] ],
[ "pico:GP11", "lcd:E", "purple", [ "v-20", "*", "h0", "v20" ] ],
[ "pico:GP10", "lcd:D4", "green", [ "v-24", "*", "h0", "v20" ] ],
[ "pico:GP9", "lcd:D5", "brown", [ "v-28", "*", "h0", "v20" ] ],
[ "pico:GP8", "lcd:D6", "gold", [ "v-32", "*", "h0", "v20" ] ],
[ "pico:GP7", "lcd:D7", "gray", [ "v-36", "*", "h0", "v20" ] ]
]
}
Connection Table:
| LCD Pin | Pin Name | Raspberry Pi Pico Pin | Notes |
|---|---|---|---|
| 1 | VSS | GND | Ground |
| 2 | VDD | 3V3 (OUT) or VBUS | Power supply (3.3V or 5V) |
| 3 | V0 | Potentiometer middle pin | Contrast adjustment |
| 4 | RS | GPIO 0 | Register Select |
| 5 | RW | GND | Read/Write (ground for write mode) |
| 6 | E | GPIO 1 | Enable signal |
| 7-10 | D0-D3 | Not connected | Not used in 4-bit mode |
| 11 | D4 | GPIO 2 | Data bit 4 |
| 12 | D5 | GPIO 3 | Data bit 5 |
| 13 | D6 | GPIO 4 | Data bit 6 |
| 14 | D7 | GPIO 5 | Data bit 7 |
| 15 | A (LED+) | 3V3 (OUT) or VBUS | Backlight power |
| 16 | K (LED-) | GND | Backlight ground |
Potentiometer Connections:
- Left pin → 3V3 (OUT)
- Middle pin → LCD Pin 3 (V0)
- Right pin → GND
Step 5: Wire the Circuit in Wokwi
CODE:
// LCD1602 and Pi Pico!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
lcd.begin(16, 2);
lcd.print("Hello World!");
lcd.setCursor(2, 1);
lcd.print("> Pi Pico <");
}
void loop() {
delay(1); // Adding a delay() here speeds up the simulation
}
Power Connections:
- LCD Pin 1 (VSS) → Pico GND
- LCD Pin 2 (VDD) → Pico 3V3 (OUT) or VBUS (5V)
- LCD Pin 15 (A) → Pico 3V3 (OUT) or VBUS
- LCD Pin 16 (K) → Pico GND
Contrast Control:
- Potentiometer left pin → Pico 3V3 (OUT)
- Potentiometer middle pin → LCD Pin 3 (V0)
- Potentiometer right pin → Pico GND
Control Pins:
- LCD Pin 4 (RS) → Pico GPIO 0
- LCD Pin 5 (RW) → Pico GND (always write mode)
- LCD Pin 6 (E) → Pico GPIO 1
Data Pins (4-bit mode):
- LCD Pin 11 (D4) → Pico GPIO 2
- LCD Pin 12 (D5) → Pico GPIO 3
- LCD Pin 13 (D6) → Pico GPIO 4
- LCD Pin 14 (D7) → Pico GPIO 5
Wokwi Tip: Click each LCD pin and drag to the corresponding Pico pin. Wokwi automatically creates colored wires.
Step 10: Verify and Adjust
Contrast Adjustment:
- Click and drag the potentiometer knob in Wokwi
- Rotate clockwise/counterclockwise to adjust LCD contrast
- Find the sweet spot where text is clearly visible
Serial Monitor:
- Check bottom panel for "LCD initialized and displaying message"
- Look for any error messages
Comments
Post a Comment