How to Display Text on 16x2 LCD with Raspberry Pi Pico in Wokwi - Complete Step-by-Step Guide

 


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.SymbolFunctionDescription
1VSSGroundPower ground (0V)
2VDDPower+5V or +3.3V power supply
3V0/VEEContrastContrast adjustment (via potentiometer)
4RSRegister SelectData/Command selection (0=Command, 1=Data)
5RWRead/WriteRead or Write (0=Write, 1=Read) - usually grounded
6EEnableEnable signal (triggers data read/write)
7-14D0-D7Data Pins8-bit data bus (we use 4-bit mode: D4-D7)
15A/LED+Backlight AnodeBacklight positive (+5V)
16K/LED-Backlight CathodeBacklight 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

  1. Go to https://wokwi.com
  2. Click "New Project"
  3. Select "Raspberry Pi Pico"
  4. The Pico board appears on your canvas

Step 2: Add LCD Display Component

  1. Click the blue "+" (Add Part) button
  2. Search for "LCD 16x2" or "LCD1602"
  3. Select "LCD 16x2" display
  4. Click to place it above the Pico board


Step 3: Add Potentiometer for Contrast Control

  1. Click the "+" button again
  2. Search for "Potentiometer"
  3. Select "Potentiometer" (10kΩ)
  4. 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 PinPin NameRaspberry Pi Pico PinNotes
1VSSGNDGround
2VDD3V3 (OUT) or VBUSPower supply (3.3V or 5V)
3V0Potentiometer middle pinContrast adjustment
4RSGPIO 0Register Select
5RWGNDRead/Write (ground for write mode)
6EGPIO 1Enable signal
7-10D0-D3Not connectedNot used in 4-bit mode
11D4GPIO 2Data bit 4
12D5GPIO 3Data bit 5
13D6GPIO 4Data bit 6
14D7GPIO 5Data bit 7
15A (LED+)3V3 (OUT) or VBUSBacklight power
16K (LED-)GNDBacklight 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:

  1. LCD Pin 1 (VSS) → Pico GND
  2. LCD Pin 2 (VDD) → Pico 3V3 (OUT) or VBUS (5V)
  3. LCD Pin 15 (A) → Pico 3V3 (OUT) or VBUS
  4. LCD Pin 16 (K) → Pico GND

Contrast Control:

  1. Potentiometer left pin → Pico 3V3 (OUT)
  2. Potentiometer middle pin → LCD Pin 3 (V0)
  3. Potentiometer right pin → Pico GND

Control Pins:

  1. LCD Pin 4 (RS) → Pico GPIO 0
  2. LCD Pin 5 (RW) → Pico GND (always write mode)
  3. LCD Pin 6 (E) → Pico GPIO 1

Data Pins (4-bit mode):

  1. LCD Pin 11 (D4) → Pico GPIO 2
  2. LCD Pin 12 (D5) → Pico GPIO 3
  3. LCD Pin 13 (D6) → Pico GPIO 4
  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