Project 5: ESP32 Output Display

Alvito Rizqi
3 min readMar 9, 2022

In this article, you will know how to use l2c LCD with ESP32 using your Arduino. I will be using 16×2 I2C LCD display because the wiring will be easier and simple. Additionally, it comes with a built-in potentiometer you can use to adjust the contrast between the background and the characters on the LCD.

Hardware and Software Requirements

  1. ESP32 Devkit V1
  2. Female-to-female jumper wires
  3. 16×2 I2C LCD

Steps

First, wire your lcd with ESP32 by following this schematic diagram.

source: https://randomnerdtutorials.com/esp32-esp8266-i2c-lcd-arduino-ide/

After the wiring is already done, you need to install the LiquidCrystal_I2C Library. I’m using the library by Marco Schwartz. Follow this steps to install the library.

  1. Click this link https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip and you will have a zip folder in your computer.
  2. Unzip the folder and you should see the LiquidCrystal_I2C-master folder. Rename that to LiquidCrystal_I2C.
  3. Move LiquidCrystal_I2C folder to your Arduino libraries folder.
  4. Then, open your Arduino.

If you have installed the library, you need to find the LCD address. Upload the following I2C Scanner sketch to find the address.

#include <Wire.h>

void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}

void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
delay(5000);
}

Upload the code and open serial monitor. Set the baud rate to 115200 and press the EN button in your ESP32. This should be displayed in your serial monitor.

Finally, we can displaying text in the LCD. I use the following code to displays “Hello, World!” in the LCD. It will displays the text in first row, then second row.

#include <LiquidCrystal_I2C.h>

// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

void setup(){
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}

void loop(){
// set cursor to first column, first row
lcd.setCursor(0, 0);
// print message
lcd.print("Hello, World!");
delay(1000);
// clears the display to print new message
lcd.clear();
// set cursor to first column, second row
lcd.setCursor(0,1);
lcd.print("Hello, World!");
delay(1000);
lcd.clear();
}

Here is my video showing the text. Thank you for reading and see you next time.

--

--