20×4 LCD over I²C
Drive a 20×4 character LCD with only two wires through its I²C backpack.
Displays · Beginner
In a real product: 3D printer control panel (Consumer electronics): A 20x4 LCD on two wires shows temperatures and progress.
The parallel LCD needs six signal wires. An I²C "backpack" (a PCF8574 port expander soldered to the back of the LCD) cuts that to two, shared with any other I²C devices. This one is the bigger 20×4 display.
What you'll learn
- How an I²C port expander drives the LCD's pins for you
- I²C addresses (this backpack is at 0x27)
- Using the LiquidCrystal I2C library
How it works
SDA and SCL go to A4 and A5, the Uno's I²C pins. The backpack's PCF8574 has 8 outputs wired to the LCD's RS, E, backlight and D4–D7. The library sends it bytes over I²C that set those pins, and so speaks the same 4-bit protocol as the parallel version.
lcd.init() sets up the display, lcd.backlight() turns on the light, and the rest is the same as LiquidCrystal: setCursor(column, row) and print().
Try this
- Fill all four lines: a title, the date, a sensor reading and the uptime.
- Change the part's i2cAddress and the address in the code together.
- Add a DS1307 on the same two wires and show the time.
sketch.ino
// A 20x4 LCD with an I2C backpack at 0x27 (SDA = A4, SCL = A5).
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Try Embedded");
lcd.setCursor(0, 1);
lcd.print("20x4 LCD over I2C");
lcd.setCursor(0, 2);
lcd.print("Only 2 signal wires");
}
void loop() {
lcd.setCursor(0, 3);
lcd.print("Uptime: ");
lcd.print(millis() / 1000);
lcd.print(" s ");
delay(250);
}