Playing ESP32 is Easy and Fun![LCD Display]

Figo Agil Alunjati
5 min readFeb 13, 2020

Hello Guys !

Welcome back ! On this occasion I still play with ESP32. At this time I will try LCD Display. in this experiment, We will show static & scrolling text on the LCD. Later, the text will be shown freely according to our desires.

For this experiment We need several components, such as
- PC / Laptop
- USB type A to microUSB cable
- ESP32 board
- LCD Display
- Female to female cable

After We collect these components, let’s just practice !!

a. Assembling Components
We must arrange the components like the picture below and connect the ESP32 board to PC / laptop. Before we have to install the LCD screen with the converter by soldering. In soldering make sure each pin is not connected to the lead.

https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2018/07/esp32_LCD_bb.png?resize=768%2C382&ssl=1

b. Add LiquidCrystal_I2C Library
Before starting the Arduino IDE, We must add the library first. The steps are
- Download the LiquidCrystal_I2C Library in https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip
- After that, move the zip file to your Arduino IDE libraries folder.
- Extract the zip file and rename the folder to LiquidCrystal_I2C

c. Get the LCD address
We have to get the LCD address so We can include it in our code file later. The Steps to get the address are
- Open the Arduino IDE
- Copy this code, verify, and upload (when uploading, don’t forget to press the boot on the ESP32 board to succeed)

/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/

#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);
}

-Open the serial monitor and We know the LCD Address. For my experiments, the LCD address that appears is 0x27.

d. Show the static text on LCD
The next step is we just show the words we want on the LCD, the steps are
- Copy the following code, We can replace “Hello, World!” with words as We like, but don’t forget the words We write don’t have too many characters to avoid being cut off when displayed on the LCD screen.
- after that verify, and upload (when uploading, don’t forget to press the boot on the ESP32 board to succeed)

/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/

#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();
}

e. Show the scrolling text on LCD
The show the scrolling text on the LCD, the steps are
- Copy the following code, We can replace the sample texts with words as We like.
- after that verify, and upload (when uploading, don’t forget to press the boot on the ESP32 board to succeed)

/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/

#include <LiquidCrystal_I2C.h>

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

// 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);

String messageStatic = "Static message";
String messageToScroll = "This is a scrolling message with more than 16 characters";

// Function to scroll text
// The function acepts the following arguments:
// row: row number where the text will be displayed
// message: message to scroll
// delayTime: delay between each character shifting
// lcdColumns: number of columns of your LCD
void scrollText(int row, String message, int delayTime, int lcdColumns) {
for (int i=0; i < lcdColumns; i++) {
message = " " + message;
}
message = message + " ";
for (int pos = 0; pos < message.length(); pos++) {
lcd.setCursor(0, row);
lcd.print(message.substring(pos, pos + lcdColumns));
delay(delayTime);
}
}

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 static message
lcd.print(messageStatic);
// print scrolling message
scrollText(1, messageToScroll, 250, lcdColumns);
}

In the experiment I encountered a problem that is text that does not appear on the LCD screen. If you experience the same thing then do not panic, here are some solutions that I did to overcome this
a) Tighten the screws on the LCD display, in this way We can adjust the contrast so that the text on the LCD display becomes visible.
b) change lcdRows from 2 to 1 or 0, this is to change the row on the LCD screen, sometimes what appears on the LCD screen is not as complete as the row 2, but the text that appears becomes clearer.

In addition, I also encountered another problem where the screen did not change after uploading, this can be fixed by resetting the ESP32 board after uploading by pressing the EN button on the ESP32 board.

Okay guys, that was my experience when playing with ESP32 and LCD display. Thank you for your attention and look forward to my other stories.
See you !!

--

--

Figo Agil Alunjati

Traveler who likes photography and technological development