Reference
LCD16x2
16x2 character LCD display (I2C backpack).
- Connects over
- I²C
- Address
- 0x27 (or 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x3F, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E)
- Made by
- Generic (HD44780 + PCF8574 backpack)
- Datasheet
- sparkfun.com
Use it
hardware {
device lcd16x2: LCD16x2
}
every 1s {
lcd16x2.clear()
}
On its own, the declaration puts the LCD16x2 on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x27. To choose the pins or the address, declare the bus and attach the device: device lcd16x2: LCD16x2 on i2c0 at 0x20 with i2c i2c0(sda: 21, scl: 22).
Methods
-
lcd16x2.clear()
Clear the display
-
lcd16x2.print(text: string)
Print text at cursor
-
lcd16x2.set_cursor(col: int, row: int)
Move cursor (col 0-15, row 0-1)
-
lcd16x2.backlight(on: int)
Toggle backlight on/off
-
lcd16x2.create_char(slot: int, r0: int, r1: int, r2: int, r3: int, r4: int, r5: int, r6: int, r7: int)
Define custom character 0-7 from 8 rows of 5-bit pixels (top to bottom)
-
lcd16x2.write_char(code: int)
Write a raw character code at the cursor (0-7 = custom chars)
-
lcd16x2.reinit()
Re-initialise the display (recovers garbled characters after noise or a supply dip); redraw afterwards
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V or 5V |
GND | Ground |
SDA | Pull-up to VCC (often on breakout board) |
SCL | Pull-up to VCC |
Backlight jumper | Pull to disable backlight |
Specifications
- Voltage
- 5V (logic and backlight)
- Current
- 1.5 mA + ~20 mA backlight
- Characters
- 16 columns × 2 rows
- Interface speed
- I²C up to 100 kHz (backpack)
Tips
- Address is usually 0x27 or 0x3F depending on backpack vendor — scan the bus if unsure.
- Adjust the contrast pot on the backpack until characters are clearly visible.
- Backlight current is significant (~20 mA) — disable when you don't need it for battery projects.
Alternatives worth knowing:
- LCD20x4: Same chip, more characters.
- SSD1306: 128×64 OLED if you need graphics or sharper text.