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
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.
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.
- ESP32 Development board
- 16*2 LCD display
- Connecting wires
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.
// go to row 0 column 5, note that this is indexed at 0
// go to row 1 column 0, note that this is indexed at 0
lcd.print (" TheEnggProjects");
- The first step is to include the required header files.
Fig. 2 Adding header files
- Define the data and control pins to be interfaced with ESP32.
Fig. 3 LCD data and control pins
- 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.
Fig. 4 steup() function
- 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.
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.
Only a single row with dark blocks is visible.
Sol. : Check the EN pin.
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.