Sub topic 1
Character LCD or OLED: which one fits your project
Prerequisites
This chapter assumes you can upload a sketch with the Arduino IDE, write a basic sketch with setup() and loop(), wire a breadboard with power, ground, and signal jumper wires, and install a library with the Library Manager.
Choosing between a character LCD and an OLED
A character LCD shows fixed-size text, usually 16 columns by 2 rows. An OLED (organic light-emitting diode) screen controls each pixel, so it can draw text and shapes. Use a character LCD for simple text. Use an OLED when you need graphics or a smaller module.
| Feature | 16x2 HD44780 LCD | SSD1306 OLED (128x64) |
|---|---|---|
| Output | Text and 5x8 custom characters | Pixels: text, lines, shapes |
| Pins with parallel wiring | 6 or more | 2 with I2C |
| Power draw | Higher, because of the backlight | Lower |
Powering and wiring a display safely
Check the supply voltage printed on your module before you connect power. Many HD44780 modules run at 5 V, while many OLEDs accept 3.3 V. Connect GND on the display to GND on the Arduino. Disconnect power before you change wires.
Printing text on a 16x2 LCD with LiquidCrystal
LiquidCrystal is the built-in library for HD44780 displays. In 4-bit mode, the sketch below uses RS on pin 12, E on pin 11, and data pins D4 to D7 on pins 5, 4, 3, and 2. Tie RW to GND and set contrast with a potentiometer on V0.
#include <LiquidCrystal.h>
// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
lcd.print("Hello, world!");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}How I2C works: two wires and an address
I2C (Inter-Integrated Circuit) is a bus that uses two signal wires: SDA carries data and SCL carries the clock. Each device on the bus has a 7-bit address. On an Uno, SDA is A4 and SCL is A5. Most I2C modules include pull-up resistors, so you usually add no extra parts.
Call Wire.begin() to start the bus. An LCD backpack often uses address 0x27 or 0x3F, and an SSD1306 often uses 0x3C. Use an I2C scanner sketch to confirm the address before you write your main code.
Exercise
The LCD shows nothing after wiring. Name two things to check first.
Show answer
Adjust the contrast potentiometer on V0, then confirm that VCC and GND are connected to the correct voltage and ground pins.