Home » ESP32 and I2C LCD example

ESP32 and I2C LCD example

by shedboy71

In this example we will interface to an I2C LCD using our ESP32. Now these I2C LCD's consist of 2 parts usually an HD44780 16×2 LCD and an I2C backpack which connects to the LCD exposing the standard power and I2C pins.

This is a typical module you can buy, you can see the backpack which is obviously on the back of the LCD

i2c lcd

i2c lcd

We will now look at the connections and a simple layout

Layout

Connect the pins as follows:

Wemos LOLIN32 LCD1602
GND GND
3v3 VCC
SDA/21 SDA
SCL/22 SCL

 

Remember the backpack and lcd connections are already made for you

 

Code

You will need an updated I2C LCD library, the original one I couldn't get to work but this one does seem to work – LiquidCrystal_I2C-master

You will need to import this into the IDE as usual

Now my example below required the I2C address to be changed to 0x3F, a lot of the example I have looked at are 0x27

[cpp]

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display

void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(“Hello world”);
lcd.setCursor(1,0);
lcd.print(“ESP32 I2C LCD”);

}

void loop()
{
}

[/cpp]

All going well you should see the messages in the code on your LCD display

Link

You can pick up one these modules for under $3

1pcs Blue Display IIC/I2C/TWI/SPI Serial Interface 1602 16X2 LCD Module

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.