Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
Lesson 26: I2C LCD 1602
In this lesson, you’ll learn how to set up and display messages on a 16x2 Liquid Crystal Display (LCD) with an I2C interface using an ESP32 Development Board. We’ll cover initializing the LCD using the LiquidCrystal I2C library, then displaying “Hello world!” and “LCD Tutorial” on two separate lines of the screen. This tutorial is ideal for beginners, offering hands-on experience with LCD interfaces and improving your understanding of output operations in Arduino programming.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
|---|---|---|
Universal Maker Sensor Kit |
94 |
You can also buy them separately from the links below.
Component Introduction |
Purchase Link |
|---|---|
ESP32 & Development Board (ESP32 Board) |
|
Wiring
Code
Note
To install the library, use the Arduino Library Manager and search for “LiquidCrystal I2C” and install it.
Code Analysis
Library Inclusion and LCD Initialization: The LiquidCrystal I2C library is included to provide functions and methods for LCD interfacing. Following that, an LCD object is created using the LiquidCrystal_I2C class, specifying the I2C address, number of columns, and number of rows.
Note
To install the library, use the Arduino Library Manager and search for “LiquidCrystal I2C” and install it.
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2);
Setup Function: The
setup()function is executed once when the ESP32 Development Board starts. In this function, the LCD is initialized, cleared, and the backlight is turned on. Then, two messages are displayed on the LCD.void setup() { lcd.init(); // initialize the LCD lcd.clear(); // clear the LCD display lcd.backlight(); // Make sure backlight is on // Print a message on both lines of the LCD. lcd.setCursor(2, 0); //Set cursor to character 2 on line 0 lcd.print("Hello world!"); lcd.setCursor(2, 1); //Move cursor to character 2 on line 1 lcd.print("LCD Tutorial"); }