Reference
LCD20x4
20x4 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 lcd20x4: LCD20x4
}
every 1s {
lcd20x4.clear()
}
On its own, the declaration puts the LCD20x4 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 lcd20x4: LCD20x4 on i2c0 at 0x20 with i2c i2c0(sda: 21, scl: 22).
Methods
-
lcd20x4.clear()
Clear the display
-
lcd20x4.print(text: string)
Print text at cursor
-
lcd20x4.set_cursor(col: int, row: int)
Move cursor (col 0-19, row 0-3)
-
lcd20x4.backlight(on: int)
Toggle backlight on/off
-
lcd20x4.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)
-
lcd20x4.write_char(code: int)
Write a raw character code at the cursor (0-7 = custom chars)
-
lcd20x4.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
- Current
- 1.5 mA + ~30 mA backlight
- Characters
- 20 columns × 4 rows
- Interface speed
- I²C up to 100 kHz
Tips
- Line addressing isn't sequential — line 3 starts at column 0x00+0x14, line 4 at 0x40+0x14. Most drivers hide this.
- Drawing 80 chars over I²C at 100 kHz takes ~50 ms — avoid refreshing the whole screen every frame.
Alternatives worth knowing:
- SSD1306: OLED — smaller package but you get graphics.
- ST7789: Color TFT — more pixels, more flexibility, more code.