Skip to content
All notebook entries
Hardware · · Entry #08

Why my LCD only needs two wires (and how I2C works)

A 16x2 display normally takes 8 data wires. With a tiny I2C adapter on the back, it's down to 2. Same screen, same letters, six pins back.

Why my LCD only needs two wires (and how I2C works)

The dumb way (V2)

In V2 my 16x2 LCD was wired the classic way: 8 separate data lines back to the ESP32, plus power, ground, and a contrast pot. The breadboard looked like a plate of spaghetti, almost every pin on the ESP32 was used up, and adding even one more sensor was basically impossible. Fourteen wires for just the screen, and I had run out of usable pins.

The smart way (V3 onward)

Then I learned about I2C. It’s a “bus,” kind of like a hallway. The ESP32 yells one address down the hallway, and only the chip with that address answers. Every other chip on the bus stays quiet.

That means two wires is all you need:

  • SDA: Serial Data Line (the chip’s voice)
  • SCL: Serial Clock Line (the master’s heartbeat that keeps everyone in sync)

Both lines are shared. The LCD’s I2C adapter (address 0x27) sits on those two wires, and any future I2C device (a real-time clock, a better humidity sensor, an OLED) could share the same pair without me adding any new pins.

// In Arduino, this is the entire bus setup:
#include <Wire.h>
Wire.begin();   // ESP32 default SDA=21, SCL=22

// Then talking to the LCD is just:
Wire.beginTransmission(0x27);  // LCD I2C adapter
Wire.write(...);
Wire.endTransmission();

Why pull-up resistors matter

I2C lines float. They need to be pulled HIGH by default, and individual chips pull them LOW when they’re talking. The little adapter board soldered to the back of my LCD has built-in 4.7 kΩ pull-up resistors so I don’t have to add them myself. I didn’t know this in V2 and spent two evenings wondering why everything I sent the LCD came out as random noise.

What V5 looks like now

V5 has the ESP32-S, the MQ4 gas sensor (analog, its own pin), the DHT11 (single-wire protocol, its own pin), the capacitive moisture sensor (analog, its own pin), and the 16x2 LCD on I2C. Right now the LCD is the only thing on the bus, but the whole point is that it doesn’t have to stay that way. If I ever add a real-time clock or a more precise humidity chip, they plug straight into the same SDA and SCL pair.

  • Sri

- Sri

Related entries