LCD 16×2 (I²C)
A 16×2 LCD is the classic character display: two rows of sixteen glowing characters, the sort of thing on fridges and weather stations. The shop's part costs $9 and is an HD44780-compatible panel with a PCF8574 I²C backpack soldered on the back, which turns the parallel interface into four wires. It is the cheapest way to put real text — a temperature, a countdown, an IP address — on a project. For graphics instead, see the OLED; for digits, the TM1637.
Pins
| Pin | What it is | Type |
|---|---|---|
| GND | Ground | ground |
| VCC | Supply 5 V (works dimly at 3.3 V) | power |
| SDA | I²C data | io |
| SCL | I²C clock | io |
| Setting | Type | Range | Default |
|---|---|---|---|
expander | enum | PCF8574, PCF8574A | PCF8574 |
color | enum | green, blue | blue |
Four pins: GND, VCC, SDA, SCL. VCC wants 5 V — at 3.3 V most modules are too dim to read. SDA and SCL go to GPIO2 and GPIO3, and the backpack answers at 0x27 (or 0x3F for PCF8574A clones; the expander setting picks which the part emulates, and color picks the green or blue board).
Wiring it in circuit.py
from wiring import *
pi = Pi()
lcd = LCD1602()
pi.V5 >> lcd.vcc
lcd.gnd >> pi.GND
lcd.sda >> pi.SDA
lcd.scl >> pi.SCLOnly four header pins are used. The backpack's contrast pot is already on the module; nothing else needs wiring.
Driving it in main.py
The runtime ships the real RPLCD 1.4.0 wheel, so this example runs here and on a Pi after pip install RPLCD:
from RPLCD.i2c import CharLCD
from time import sleep
lcd = CharLCD('PCF8574', 0x27, cols=16, rows=2)
count = 0
while True:
lcd.cursor_pos = (0, 0)
lcd.write_string("Hello, PyRasp!".ljust(16))
lcd.cursor_pos = (1, 0)
lcd.write_string(f"count {count}".ljust(16))
count += 1
sleep(1)write_string writes at the cursor and wraps or scrolls; cursor_pos = (row, column) moves it. clear(), home() and the cr/lf/crlf helpers work too. The RPLCD library page covers custom characters and the backlight.
Electrical notes
- Supply 4.5–5.5 V. The backlight draws about 20 mA; the controller itself is negligible.
- The backpack drives the LCD in 4-bit mode: every character is two nibbles, each latched by a pulse on the enable line. It is not a register device like an ADC — you send HD44780 instructions, not pixel data.
- Timing per the model: instructions take 37 µs and a clear 1.52 ms. The simulator does not enforce either (writes never fail for being too fast), but a real clone appreciates the delays RPLCD already adds.
- The character ROM is the Japanese A00 table: a backslash prints as ¥, and code 0xDF is the degree sign, so
21.5\xdfCis the usual Celsius trick. - Eight custom glyphs (codes 0–7) fit in CGRAM via
create_char. - Address 0x27 (PCF8574) is the default; PCF8574A clones answer at 0x3F. Two powered devices on the same address produce a warning and the first one wins.
Simulator vs real hardware
- There is no special library support for the display: the part itself implements the PCF8574 expander and the HD44780 instruction set, decoding the real byte stream. RPLCD works, and so does any other HD44780-over-PCF8574 driver, or your own smbus2 bytes.
- The screen is modelled as text, not pixels: the canvas draws the 16×2 grid with the built-in font. Contrast, viewing angle and character-ROM variants are not modelled beyond the A00 quirks above.
- The backlight bit is honoured — clearing it blanks the screen in the board view, like switching off the backpack's transistor.
- There is no busy flag and no setup/hold limit: a tight
write_stringloop never skips characters, where a real module can miss writes unless the busy flag is polled or delays are added.
Going deeper
- Library: RPLCD — the API, custom characters and backlight control.
- Primer: I²C and the other buses.
- Other displays: OLED 128×64 for graphics, TM1637 for four digits.
- Recipe: the LCD weather station puts sensor readings on this screen.
- Nearby parts: BME280, DS18B20.
Further reading
- HD44780U datasheet (Hitachi) — instruction set, DDRAM/CGRAM and the character table.
- PCF8574 datasheet (NXP) — the I²C expander on the back of the module.
- RPLCD documentation — the library the runtime ships.