LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Hello readers, we hope you all are doing great. In this tutorial, we will learn how to interface an LCD display (16*2) with the ESP32 module.

In our previous tutorials, we have already discussed various methods of displaying data using the internet over Google Sheets, IFTTT, ThingSpeak etc., for example. But, in some applications where we do not want to include the internet or it is required to display the data on directly connected displays. In such applications, we prefer using matrix display and Liquid Crystal Display (LCD).

16*2 LCD display
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig.1: 16*2 LCD display

LCD displays are a type of electronic display module that is used in a wide variety of applications and devices such as calculators, computers, mobile phones, TV, etc.

These displays are primarily used with multi-segment light-emitting diodes and seven segments. The major features of using this module are:

  • Easy to program.
  • It has no limitations for displaying custom characters special and even animations etc.

As the name suggests, the 16*2 display, consists of 2 rows and 8 columns and is can display a maximum of up to 32 characters.

Pin configuration

LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Table 1

Where To Buy?
No.ComponentsDistributorLink To Buy
1ESP32AmazonBuy Now

Interfacing LCD display with ESP32

There are basically two methods of interfacing ESP32 with a 16*2 LCD display.

  • Interfacing with I2C adapter
  • Interfacing directly without using an I2C adapter.

Interfacing the LCD display without an I2C adapter is cost effective but implementation is complex as this method requires more connecting wires. On the other hand, using I2C adapter reduces the complexity but increases the cost. In this tutorial, we are interfacing ESP32 directly without using the I2C adapter.

Components Required:

  1. ESP32 Development board
  2. 16*2 LCD display
  3. Potentiometer
  4. Connecting wires
  5. Breadboard

Connections:

LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Table 2

Arduino IDE Programming

We are using Arduino IDE to compile and upload code into ESP32 module. To know more about Arduino IDE and how to use it, follow our previous tutorial i.e., on the ESP32 programming series.

Code

#include <LiquidCrystal.h>

LiquidCrystal lcd(22,23,5,18,19,21);

void setup()

{

lcd.begin(16, 2);

lcd.clear();

// go to row 0 column 5, note that this is indexed at 0

lcd.setCursor(5,0);

lcd.print("ESP32");

// go to row 1 column 0, note that this is indexed at 0

lcd.setCursor(0,1);

lcd.print (" TheEnggProjects");

}

void loop()

{

}

 

Code Description

  • The first step is to include the required header files.
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 2 Adding header files

  • Define the data and control pins to be interfaced with ESP32.
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 3 LCD data and control pins

Setup() function

  • Initialize the 16*2 LCD using begin() function.
  • Clear the previous data from the LCD before printing or displaying the new one using print() function.
  • Set the cursor position at row 1 and column 0 using setCursor() function.
  • print() function is used to print data on LCD display.
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 4 steup() function

Testing

  • Select the right development board from Tools >> Boards >> DOIT ESP32 DevKit V1 in Arduino IDE.
  • Compile and upload the code into ESP32 using Arduino IDE.
  • Make the connections as per the instructions given in Table 2.
  • Again power up the ESP32 development board.
  • Press the EN button from the ESP32 development board.
  • You should see the text printed or displayed on the 16*2 LCD display. We are attaching a screenshot below for your reference.
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 5

Common Errors faced while working on 16*2 LCD:

  • Texts are not visible: Backlight is ON but the texts are not visible (after uploading the code) as shown in the image below. To resolve this issue:
    • Check the potentiometer, whether it is connected properly or not.
    • Adjust the value of potentiometer to control brightness of the display.
LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 6

Only a single row with dark blocks is visible.

Sol. : Check the EN pin.

LCD esp32, esp32 lcd, lcd interfacing with esp32, interface lcd with esp32, 16x2 lcd esp32, esp32 lcd 16x2, ESp32 LCD interfacing

Fig. 7

This concludes the tutorial. We hope you found this of some help and also hope to see you soon with a new tutorial on ESP32.