> ## Documentation Index
> Fetch the complete documentation index at: https://learn.pcbcupid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# I2C LCD Display

> Connect a 16x2 LCD with I2C backpack to a Glyph ESP32 board over two wires and print messages using the LiquidCrystal_I2C Arduino library.

[YouTube video player](https://www.youtube.com/embed/gjp0ktQbu1Y?si=-nliDv-VtYwXXCCk)

# LCD I2C

![LCD](https://files.pcbcupid.com/Documentation/Boards/Examples/LCD_I2C/PCBCUPID_I2C_LCD.avif)

## Introduction

The 16×2 LCD (Liquid Crystal Display) is a widely used alphanumeric display module capable of showing 16 characters per line on 2 lines. It is based on the Hitachi HD44780 controller, which provides a simple command-based interface for displaying characters, symbols, and custom graphics.

To reduce the number of GPIO pins required for communication, the LCD is often connected through an I²C I/O expander, typically the PCF8574 chip. This configuration allows the LCD to communicate with the microcontroller using only two wires — SDA (Serial Data) and SCL (Serial Clock) — instead of the usual 6 to 8 parallel data and control lines.

The PCF8574 acts as a bridge between the microcontroller’s I²C bus and the LCD’s parallel interface, providing:

* Pin saving
* Simpler wiring
* Easy software control
* Without it, you would need many more GPIO pins and complex wiring to operate the LCD.

## Pin Configuration

| LCD Pin | Glyph-C3 |
| - | - |
| VCC | Power Supply |
| GND | GND |
| SDA | GPIO 21 |
| SCL | GPIO 22 |

## Features

* Uses I²C communication — only two wires (SDA and SCL) are required.
* Saves microcontroller pins — reduces pin usage from 8 (parallel) to 2.
* Compatible with the HD44780 LCD controller.
* Based on PCF8574 I/O expander for serial-to-parallel data conversion.
* Built-in LED backlight for better visibility.
* Adjustable contrast using the onboard potentiometer.
* Operates on 3.3V or 5V, suitable for most microcontrollers (Arduino, ESP32, ESP8266, Raspberry Pi).
* Displays 16 characters × 2 lines (total 32 characters).

## Typical Applications

* Embedded system displays — show system status or information.
* Sensor data monitoring — display temperature, humidity, voltage, etc.
* Industrial control panels — parameter and status display.
* IoT devices — display device data or connection status.
* Educational and training projects — for learning I²C and LCD interfacing.
* Digital meters — voltage, current, and frequency measurement displays.
* Home automation systems — display time, mode, or device state.

## Step 1: Hardware Required

1. GLYPH
2. LCD Display
3. PCF-8574

## Step 2: Circuit Diagram

![](https://files.pcbcupid.com/Documentation/Boards/Examples/LCD_I2C/LCD_12C%20CIRCUIT%20DAIGRAM/circuit_diagram_i2c.jpg)

## Step 3: Code Setup

1. Open Arduino IDE.
2. Make sure to install the  library
3. Copy and paste the following code into the Arduino IDE

> [tab] Arduino Code
>
> ```cpp theme={null}
> #include <Wire.h>
> #include <LiquidCrystal_I2C.h> // https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c
>
> // Initialize LCD: I2C address 0x27, 16 columns, 2 rows
> LiquidCrystal_I2C lcd(0x27, 16, 2);
>
> void setup() {
>   lcd.init();          // Initialize the LCD
>   lcd.backlight();     // Turn ON backlight
>
>   // Print text
>   lcd.setCursor(0, 0);  
>   lcd.print("Hello");
>   lcd.setCursor(0, 1);
>   lcd.print("PCBCUPID");
> }
>
> void loop() {
>   // Static display - nothing needed
> }
>
> ```

> [tab] CircuitPython Code
>
> Copy adafruit\_pcf8574.mpy, adafruit\_bus\_device/, and adafruit\_character\_lcd/ into lib/. This uses the common PCF8574 backpack mapping (RS=P0, EN=P2, backlight=P3, D4–D7=P4–P7) at 0x27. Check the address with the I2C scanner and use a 3.3 V backpack or level shifter if its pull-ups go to 5 V.
>
> Follow the [CircuitPython setup guide](https://learn.pcbcupid.com/documentation/welcome/prerequisites/circuitpython-setup-guide.md) and save this example as `code.py` on the board.
>
> ```python theme={null}
> import board
> import adafruit_pcf8574
> from adafruit_character_lcd import character_lcd
>
> expander = adafruit_pcf8574.PCF8574(board.I2C(), address=0x27)
> backlight = expander.get_pin(3)
> backlight.switch_to_output(value=True)
> lcd = character_lcd.Character_LCD_Mono(
>     expander.get_pin(0), expander.get_pin(2),
>     expander.get_pin(4), expander.get_pin(5),
>     expander.get_pin(6), expander.get_pin(7), 16, 2
> )
> lcd.message = "Hello\nPCBCUPID"
> while True:
>     pass
> ```

## Step 4: Upload the Code

1. **Connect the Board**

* Connect your GLYPH board to your computer

2. **Select the Board and Port**

Do the following settings in your Arduino IDE,

* `Tools > Board > esp32 > Pcbcupid Glyph S3`

> [!WARNING]
>
> For the `Pcbcupid Glyph S3 ` to appear under `Tools > Board > esp32`, the esp32 board version installed in the Arduino IDE should be greater or equal to 3.1.0.

* `Tools > Port` and select the port connected to your GLYPH.
* `Tools > USB CDC on Boot >` ***Enabled***

> [!WARNING]
>
> If `USB CDC on BOOT` not enabled, you won't be seeing any serial data on Arduino IDE.

3. **Upload the Code**

   * Click the upload button (➡️ icon) or use the shortcut `CRTL + U` in Arduino IDE to upload the code to the board.

## Step 5: Observe Output on Serial Monitor

![LCD](https://files.pcbcupid.com/Documentation/Boards/Examples/LCD_I2C/PCBCUPID_I2C_LCD_OUTPUT.avif)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.