How to Use I2C LCD with ESP32 on Arduino IDE (ESP8266 compatible)

This tutorial shows how to use the I2C LCD (Liquid Crystal Display) with the ESP32 using Arduino IDE. We’ll show you how to wire the display, install the library and try sample code to write text on the LCD: static text, and scroll long messages. You can also use this guide with the ESP8266.

16×2 I2C Liquid Crystal Display

For this tutorial we’ll be using a 16×2 I2C LCD display, but LCDs with other sizes should also work.

The advantage of using an I2C LCD is that the wiring is really simple. You just need to wire the SDA and SCL pins.

Additionally, it comes with a built-in potentiometer you can use to adjust the contrast between the background and the characters on the LCD. On a “regular” LCD you need to add a potentiometer to the circuit to adjust the contrast.

Parts Required

To follow this tutorial you need these parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Wiring the LCD to the ESP32

This display uses I2C communication, which makes wiring really simple.

Wire your LCD to the ESP32 by following the next schematic diagram. We’re using the ESP32 default I2C pins (GPIO 21 and GPIO 22).

You can also use the following table as a reference.

I2C LCD ESP32
GND GND
VCC VIN
SDA GPIO 21
SCL GPIO 22

Wiring the LCD to the ESP8266

You can also wire your LCD to the ESP8266 by following the next schematic diagram. We’re using the ESP8266 default I2C pins (GPIO 4 and GPIO 5).

You can also use the following table as a reference.

I2C LCD ESP8266
GND GND
VCC VIN
SDA GPIO 4 (D2)
SCL GPIO 5 (D1)

Preparing the Arduino IDE

Before proceeding with the project, you need to install the ESP32 or ESP8266 add-on in the Arduino IDE.

Arduino IDE with ESP32

Follow one of the next guides to prepare your Arduino IDE to work with the ESP32:

Arduino IDE with ESP8266

To install the ESP8266 add-on in your Arduino IDE, read the following tutorial: How to Install the ESP8266 Board in Arduino IDE.

Installing the LiquidCrystal_I2C Library

There are several libraries that work with the I2C LCD. We’re using this library by Marco Schwartz. Follow the next steps to install the library:

  1. Click here to download the LiquidCrystal_I2C library. You should have a .zip folder in your Downloads
  2. Unzip the .zip folder and you should get LiquidCrystal_I2C-master folder
  3. Rename your folder from LiquidCrystal_I2C-master to LiquidCrystal_I2C
  4. Move the LiquidCrystal_I2C folder to your Arduino IDE installation libraries folder
  5. Finally, re-open your Arduino IDE

Getting the LCD Address

Before displaying text on the LCD, you need to find the LCD I2C address. With the LCD properly wired to the ESP32, upload the following I2C Scanner sketch.

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

View raw code

After uploading the code, open the Serial Monitor at a baud rate of 115200. Press the ESP32 EN button. The I2C address should be displayed in the Serial Monitor.

In this case the address is 0x27. If you’re using a similar 16×2 display, you’ll probably get the same address.

Display Static Text on the LCD

Displaying static text on the LCD is very simple. All you have to do is select where you want the characters to be displayed on the screen, and then send the message to the display.

Here’s a very simple sketch example that displays “Hello, World!“.

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

View raw code

It displays the message in the first row, and then in the second row.

In this simple sketch we show you the most useful and important functions from the LiquidCrystal_I2C library. So, let’s take a quick look at how the code works.

How the code works

First, you need to include theLiquidCrystal_I2C library.

#include <LiquidCrystal_I2C.h>

The next two lines set the number of columns and rows of your LCD display. If you’re using a display with another size, you should modify those variables.

int lcdColumns = 16;
int lcdRows = 2;

Then, you need to set the display address, the number of columns and number of rows. You should use the display address you’ve found in the previous step.

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

In the setup(), first initialize the display with the init() method.

lcd.init();

Then, turn on the LCD backlight, so that you’re able to read the characters on the display.

lcd.backlight();

To display a message on the screen, first you need to set the cursor to where you want your message to be written. The following line sets the cursor to the first column, first row.

lcd.setCursor(0, 0);

Note: 0 corresponds to the first column, 1 to the second column, and so on…

Then, you can finally print your message on the display using the print() method.

lcd.print("Hello, World!");

Wait one second, and then clean the display with the clear() method.

lcd.clear();

After that, set the cursor to a new position: first column, second row.

lcd.setCursor(0,1);

Then, the process is repeated.

So, here’s a summary of the functions to manipulate and write on the display:

  • lcd.init(): initializes the display
  • lcd.backlight(): turns the LCD backlight on
  • lcd.setCursor(int column, int row): sets the cursor to the specified column and row
  • lcd.print(String message): displays the message on the display
  • lcd.clear(): clears the display

This example works well to display static text no longer than 16 characters.

Display Scrolling Text on the LCD

Scrolling text on the LCD is specially useful when you want to display messages longer than 16 characters. The library comes with built-in functions that allows you to scroll text. However, many people experience problems with those functions because:

  • The function scrolls text on both rows. So, you can’t have a fixed row and a scrolling row;
  • It doesn’t work properly if you try to display messages longer than 16 characters.

So, we’ve created a sample sketch with a function you can use in your projects to scroll longer messages.

The following sketch displays a static message in the first row and a scrolling message longer than 16 characters in the second row.

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

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

View raw code

After reading the previous section, you should be familiar on how this sketch works, so we’ll just take a look at the newly created function: scrollText()

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

To use this function you should pass four arguments:

  • row: row number where the text will be display
  • message: message to scroll
  • delayTime: delay between each character shifting. Higher delay times will result in slower text shifting, and lower delay times will result in faster text shifting.
  • lcdColumns: number of columns of your LCD

In our code, here’s how we use the scrollText() function:

scrollText(1, messageToScroll, 250, lcdColumns);

The messageToScroll variable is displayed in the second row (1 corresponds to the second row), with a delay time of 250 ms (the GIF image is speed up 1.5x).

Display Custom Characters

In a 16×2 LCD there are 32 blocks where you can display characters. Each block is made out of 5×8 tiny pixels. You can display custom characters by defining the state of each tiny pixel. For that, you can create a byte variable to hold  the state of each pixel.

To create your custom character, you can go here to generate the byte variable for your character. For example, a heart:

Copy the byte variable to your code (before the setup()). You can call it heart:

byte heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

Then, in the setup(), create a custom character using the createChar() function. This function accepts as arguments a location to allocate the char and the char variable as follows:

lcd.createChar(0, heart);

Then, in the loop(), set the cursor to where you want the character to be displayed:

lcd.setCursor(0, 0);

Use the write() method to display the character. Pass the location where the character is allocated, as follows:

lcd.write(0);

Wrapping Up

In summary, in this tutorial we’ve shown you how to use an I2C LCD display with the ESP32/ESP8266 with Arduino IDE: how to display static text, scrolling text and custom characters. This tutorial also works with the Arduino board, you just need to change the pin assignment to use the Arduino I2C pins.

We have other tutorials with ESP32 that you may find useful:

We hope you’ve found this tutorial useful. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.

Thanks for reading.

February 1, 2019



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

130 thoughts on “How to Use I2C LCD with ESP32 on Arduino IDE (ESP8266 compatible)”

  1. Thanks for this excellent tutorial! I was just trying to get I2C working for a project and this was very helpful. My display was VERY VERY faint, even with the potentiometer turned all the way up. Do you think powering it via 5V versus 3 might help with that problem?

    Reply
      • Hi Sara,
        On my version of the ESP8266 v3, the Vin does not output any voltage. I thought my LCD module was DoA but when I connected its Vcc to 3v3, it worked. After all, it was dead. I then connected LCD’s Vcc to ESP8266 VU and presto it worked!
        Hope other’s benefit from this.
        Best
        Rajnish

        Reply
  2. I tried this project but got an error during compilation. At the line

    LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

    this error came out during compilation:

    sketch_jan14c:14: error: invalid conversion from ‘int’ to ‘t_backlighPol’ [-fpermissive]

    LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);

    ^

    In file included from C:\Users\KKC231~1.LIM\AppData\Local\Temp\arduino_modified_sketch_441632\sketch_jan14c.ino:6:0:

    C:\Users\K. K. Lim\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:53:4: error: initializing argument 3 of ‘LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)’ [-fpermissive]

    LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

    ^

    C:\Users\K. K. Lim\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h: In function ‘void setup()’:

    C:\Users\K. K. Lim\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:154:9: error: ‘int LiquidCrystal_I2C::init()’ is private

    int init();

    ^

    sketch_jan14c:18: error: within this context

    lcd.init();

    ^

    Multiple libraries were found for “Wire.h”
    Used: C:\Users\K. K. Lim\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\Wire
    Not used: C:\Users\K. K. Lim\Documents\Arduino\libraries\Wire
    exit status 1
    invalid conversion from ‘int’ to ‘t_backlighPol’ [-fpermissive]

    I have no idea what it means. Can you point out what is preventing the compilation.

    Reply
    • Hi.
      There are several libraries for the Liquid Crystal I2C. Please make sure that you’re using the same library we use in this example.
      The library is available in this link: https://github.com/johnrickman/LiquidCrystal_I2C
      After downloading and installing the library as described in the instructions, try our example or one of their examples and see if it works.
      Regards,
      Sara

      Reply
      • His Sara, Thanks for your reply. Actually I was wondering if I had used the wrong library as I found I got the same error with some other sketches. I will follow up on your suggestion. Thanks very much for taking the time to reply.

        Reply
          • Your tutorials are great. I learned a lot from them. Adding some research on the Internet in Github and Instructables, I have just finished a Weather Monitor using the DS18B20 probe for temperature measurement and the BME280 for Humidity and Atmospheric pressure measurement. The project uses the NodeMCU/WeMos D1 and the results are displayed on a LCD2004 and also on Thingspeak. The display can also be on my local WLAN using NGROK which I learned from your book on Home Automation using the ESP 8266. Not very sophistacated software structure but it works!

          • Hi!
            That’s great! I’m really glad you’ve built that project on your own with the help of our tutorials.
            Thank you for you interest in our content and for supporting our work.
            Best regards,
            Sara 🙂

  3. my 1602 shows up in an i2scan program correctly at 21 SDA and 22 SCL with id 0x27. I have 4 of the boards. they light up, but it doesn’t display text. I have found ALL of your projects to be fully tested and clearly documented. How do I decide if Amazon sent me bad boards. While its almost always user error (me) I need to determine if the boards are bad. Thank you, Bradshaw, Buzzards Bay, MA, on the Cape Cod Canal

    Reply
    • Hi.
      Sorry for taking so long to get back to you.
      Do you get text on any of the boards? Do you get any error on the serial monitor?
      Please make sure that you have the display wired properly and you are using the right library.
      Regards,
      Sara

      Reply
      • I had the same error using
        banggood.com/Geekcreit-Doit-NodeMcu-Lua-ESP8266-ESP-12F-WIFI-Development-Board-p-985891.html?rmmds=myorder&cur_warehouse=CN

        Used this library successfully
        arduinolibraries.info/libraries/liquid-crystal_pcf8574

        Reply
        • Hi Ben.

          Thanks for letting me know.
          So, the project didn’t work with the library we recommend, but it did work with that library that you’re pointing out?

          I’ll have to test this project again and see if it is working. It may be due to library updates or something. I’ll check that out.
          Thank you.

          Reply
    • Hi.
      I don’t know the reason for that.
      But if you’re using a similar display, this address should probably work: 0x27
      Regards,
      Sara

      Reply
  4. Hi,
    Using 3.3v with the lcd is too dim, Connecting the lcd to 5v, could it be risky damaging the esp? Do you need a level translator?
    Thanks,
    Ken

    Reply
    • Ken, the ESP8266 & ESP32 are 5V-tolerant on the GPIO pins (so says the Espressif CEO), but it’s flash chip is NOT. You can’t run the ESP from 5V as it’ll blow the flash, but the following pins are OK with 5V input levels: D0-D8 (GPIO0-5, GPIO12-16, but not GPIO6-11 as they’re also on the flash). I’d double-check the datasheets for various USB converter chips to be really sure it’s safe on GPIO1 and GPIO3 (TxD & RxD) for boards that have a USB port. Those parts are powered by USB 5V so it *should* be safe, but I’d still check myself before going to production.

      Older (30 years ago) HD44780 chips wouldn’t run reliably with 3.3V, but it didn’t harm them. Newer chips generally don’t have issues with 3.3V, but the backlight may not be bright enough as you noted. In that case, use the VIN pin on your module to power the LCD.

      Here’s where the CEO said it’s OK to use 5V on the GPIO only:
      https://www.facebook.com/groups/1499045113679103/permalink/1731855033731442/

      Reply
      • Why you don’t convert 5V LCD to 3.3V LCD(you are need solder ICL7660(U3) and 2 capacitors 1uF..4.7uF(C1 and C2),unsolder J1 and solder J3), or buy 3.3V version LCD with already soldered ICL7660? It more right by HW design…

        Reply
  5. Hi,
    There is an issue with using LCDs that have more than 2 rows.
    I tried with a 16 x 4 LCD with lcdRows set to 4.

    Writing to top 2 rows work as described.
    But writing to the 3rd row [ lcd.setCursor(0,2);] writes to the 3rd row, but shifted left 4 characters.

    Seems this library is optimised for 20 x 4 characters, and will need some work to modify it for other column values.

    This is because by its internal setup the 1st row carries over to the 3rd, and 2nd row to the 4th.

    The library has assumed 20 columns by default, after which it resets the column value to 0.

    Reply
  6. Hi, In your connections diagram you have mentioned to connect
    I2C LCD ESP32
    SDA to GPIO21,
    SCL to GPIO22

    I have a Starglow 1602A LCD 16X2. Is it possible to connect LCD to ESP32 “without” the I2C module in between ?

    Reply
  7. I have a problem. When I upload the code it shows me this error message: A fatal error occurred: Timed out waiting for packet content

    Reply
  8. Hi.

    I have found this tutorial very useful. I´d liketo share my experience: when tried to get the I2C address using the sketch, but my Esp 32 couldn`t find it. After several hours searching the Internet for the cause of the problem, i finally found the crasy cause: The SDA/ SCL pins of the I2C were touching some points of the LCD PCB circuit. Once inserting a smallpiece of paper card for electric insulation, the LCD is working very well. Thank you for your magnificent site.

    Reply
    • Cuauhtemoc Sarabia, I’m very grateful to you. After a week of trying different libraries etc to make my new display work I came across your solution here – my problem exactly!!

      Reply
  9. Hi!

    Great tutorial. At the beginning I pulled up SDA/SCL signals with resistors to 5V, as I always do with regular Arduino boards. This caused multiple I2C address situation when i2c scanner was run. Then I “followed your tutorial” by connecting SDA/SCL directly to the ESP32 board and everything work ok, even with a 20×4 LCD.

    I guess that SDA/SCL signals are pulled up internally in the ESP32 board???

    Thanks for the tutorial!!!

    Reply
    • Hi Marcos.
      Usually you don’t need to use those pull up resistor because these displays already include them. The same happens for other breakout boards with sensors.
      Regards,
      Sara

      Reply
  10. It woesn’t work with 3.3v, you need have 5 volts for display. I spent 3 days until I found that, so could you mention that in your guide, thanks

    Reply
  11. upload returns an error :
    Wire\utility\twi.c:25:20: fatal error: avr/io.h: No such file or directory

    I think this is because ‘twi’ library is written for avr while we are using esp8266.
    how can I fix it?

    Reply
    • Hi.
      I don’t know.
      This library works fine for me. Even tough it’s written for avr, it works fine with ESP32 and ESP8266.
      I’m sorry, but I don’t know how to fix your issue.
      Regards,
      Sara

      Reply
      • Hey Sara!
        I just found that that error occurs because there was another folder named ‘Wire’ in the libraries location and it confused the compiler. Removing that folder ended those errors up.

        wish you the best

        Reply
  12. Hi, thanks for your brilliant work, I already connect the OLED with the ESP32 and it works perfectly. However, I have no idea how to print the information received from the other ESP32 (by CAN transceiver) on OLED? Like how to output the value from register to OLED. The OLED is already connected, and I’ve already known the address of the register but have no idea how to write the code.

    Reply
  13. Greetings, thanks for the tutorial.
    Is there a way to tell the lcd.init () function that the display is connected to the alternate I2C GPIO 18 and 19? Because I am using a TTGO T-CALL ESP32 SIM800L module and the default I2C port (GPIO 21 and 22) is compromised

    Reply
  14. Hi.
    Thankyou for your brilliant work. But I am getting some problem that my LCD showing black square boxes in the first row and nothing is displaying in second row and my i2c address is 0x27. Please anybody help me.

    Reply
    • Hi.
      Double-check the power connections and you may also need to adjust the brightness of the display by rotating the potentiometer at the back.
      I hope this helps.
      Regards,
      Sara

      Reply
      • Hi Sara.
        Thankyou for your reply, but I have check every connections and I have also adjusted the brightness of display. but nothing changed in the output.

        Reply
  15. Dear randomnerdtutorials.
    I would like to share that I’m having the same problem as Khan.
    I can put my I2C LCD to work in an arduino uno.
    But cannot have it running in my esp32 devkit v1 (following your instructions).
    When running your “Getting the LCD Address” code in arduino uno, the program says that the lcd is in address 0x3C, but I have it running in address 0x27.
    In the esp32…
    The LCD receives the proper 5V.
    Connections are double checked.
    Installed the library as (you) suggested.
    My interpretation is that the lcd.init() fails, as there’s only one row where I can see the character pixel blocks (while in arduino there are two).
    Khan – I’m with you.
    Regards to all.

    Reply
  16. Hi Sara! I’m having the same problema that Khan had. When i run the first code you put here i got this response: No I2C devices found. My i2c board isn’t weld to the lcd board. Do you think it might be the problem? I’m using esp8266.

    Reply
    • Hi.
      Make sure that you have the LCD connected to the right I2C pins.
      On the ESP8266, the I2C pins are
      SCL: GPIO 5 (D1)
      SDA: GPIO 4 (D2)
      Regards,
      Sara

      Reply
      • It worked, Sara. I bought the LCD and I2C separated. Today i asked for a technician to weld both boards and everything worked fine! Thanks for helping too 😊

        Reply
  17. Dear madam , my name is Shirazi from South Africa, I am a student of your courses, I was just wondering if you have an example of a I2C LCD MENU interface program , thank you in advance , Shirazi

    Reply
    • Hi.
      We don’t have any tutorial about that.
      If you are one of our students, you can use the RNTLAB forum to get more immediate responses.
      Regards,
      Sara

      Reply
  18. Just wanted to quickly say: thank you! Your tutorial was clear and helpful and left no questions unanswered, bonus points for the link to the special character creator 🙂

    Reply
  19. Nice article, clear and easy to follow.

    I have Funduino LCM1602 board soldered on to 16*2 LCD module. Didn’t work with 3.3v from NodeMCU module, but fine with 5v.

    I already had a library LiquidCrystal_I2C and I wanted to keep it for use with Arduino Nano etc. So I renamed the library referred to above to LiquidCrystal_I2CE. Then in the LiquidCrystal_I2CE folder the same change to the .h and .c filenames. Then in those two files changed _I2C to _I2CE everywhere.

    The Arduino IDE knows which examples are not valid for the current hardware (e.g. Arduino or ESP) so maybe there’s a way to get it to select between two libraries with the same name.

    Reply
  20. Hello! I’m using a white background LCD. The text appears in white colour, an is unreadable. How can I write in black pixels? Thanks!

    Matias

    Reply
      • Hello Marcos! I’ts one those bugs which nobody in the world knows how to deal with. I changed the 8266 to ESP32 and works fine. I have in my hands another 8266 and the same problem. Still researching.

        Thanks again!

        Matías

        Reply
        • Hi Matias, I’m using NodeMCU Ver 0.9 ESP-12. Esp module is ESP8266MOD. It works normally, dark pixels on green backlight.

          I had a look in LiquidCrystal_I2CE.h and .cpp. Can’t see much useful to try there. At the end of the .cpp there is a set_contrast function, you could try that. Maybe a timing issue, try extending the times.

          Reply
          • Hello Richard! I found the problem: not enough supply voltage. I wire a 7805 directly to the pin 2 of the AMS1117 on the 8266 board, and work normally.

            Thanks for your help!

            Just in case mi cell phone number is 54 9 11 6110 7126

            Matías

  21. Hello, I’ve learned a lot from random nerd tutorials
    you guys are amazing!

    I deployed 16 unit ESP32 for early warning system with 3 phase voltage reading, relay, i2c LCD

    since this is i2c LCD topic, I would like to ask some question

    some of my i2c LCD is getting random character, is it reliable to use i2c LCD? how much the electromagnetic interference can cause error to LCD? is there any way to minimize it? especially when the relay triggered, almost half of them show random character

    Reply
  22. Just tried this on a Nodemcu 8266 generic. Using the LiquidCrystal_I2C.h does not work. However, it does with with Arduino UNO.

    Reply
  23. After a few attempts and failures, after adjusting “Serial.begin(115200);” to “Serial.begin(9600);” in “Getting the LCD Address” I obtained intelligible information on the serial monitor and from there things started to work. Thank you very much!

    Reply
  24. On the wiring diagram for the ESP32. Strongly suggest that a level shifter be added between the SDA and SCL lines and the display. It is essential, if not just good practice, when mixing 5 and 3.3 V devices that the power lines be isolated to the proper supply voltage for each device.

    Or at least include a note that is should be confirmed absolutely that any 5V device will operate fully at 3.3V.

    Reply
  25. Hi Sara,
    On scroll text, how to modify your code so at the first time, 16 chars are show up, then with some delay (assuming the text has been read) the rest of the text are scrolling to the left until all part of the text show up and repeat.
    Thanks for your help and your tutorial.

    Reply
  26. Hi Sara,
    Thank for scrolling text tutorial.
    I use also a LCD1602. In my case, I’ve 40 (or more depend on input) chars.
    1. At the first time 16 chars (including space) will show up normally as a static,
    2. After some delays, the text will scroll to the left for showing up remaining text (chars).
    3. Scrolling will stop when the last char already show up on 16th col.
    4. After some delays, it will back to #1.
    5. When chars only 16 or less, of course scrolling will ‘false’.
    Please guide me how to do that. Thanks and appreciate for your help.

    Reply
  27. Hello Sara,
    Yet again a question about LCD. I was using ATMEL chips to control DOGM204 via I2C succesfully. I used an ESP8266 succesfully. Now I want to connect an ESP32 to it, but this version doesn’t have pins 21 and 22. Only up to 19 (ESP32-C3-devkitc-02 with a wroom chip on it)
    I tried different examples from your site but couldn’t get something on the display. Preferably I would like to use some free pins but cannot find the way to get it declared.
    Can you give me a push in the right direction?
    Kind regards,
    Arthur

    Reply
  28. hi sarah i use the esp8266 and lcd i2c on arduino ide. i first wrote this code
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x27, 16, 2);

    void setup() {
    Serial.begin(115200);

    Wire.begin(2, 1);
    lcd.begin(16, 2);
    lcd.home();
    lcd.print(“3040”);
    delay(3000);
    }

    void loop() {

    delay(500);
    lcd.setCursor(0,0);
    lcd.print("POAH!");
    lcd.setCursor(0,1);
    lcd.print("sjiek");
    delay(2000);
    lcd.setCursor(0,0);
    lcd.print("Das mien merk");
    delay(2000);

    }

    i connected scl to d2 and sda to d1 and vice versa ground and power is connected correctly. my lcd turns on but no text appears when i used your code same problem accurs i have bougt to lcd i2c screens but with both of them the same problem occurs. and i cant figure out what the problem is. if i just write a code for LEDs with a switch or without one i have no problems.

    do you have any idea what the problem might be.

    many thanks in advance

    Reply
    • Hi.
      First, double-check the wiring.
      Then, run the I2C scanner sketch to check the I2C address of your display.
      Regards,
      Sara

      Reply
  29. Hi. Trying this on a DOIT ESP DEVKIT V1.

    With everything wired up correctly (Vin to Vcc) the detection code works fine (and gives me an address of 0x3C) but running the Hello World doesn’t work – I tried it with a different LCD panel (different make, different supplier, both brand new) and that didn’t work either. I tried switching from Vin to 3.3v and that didn’t work either.

    Do you have any suggestions please? I’m guessing that just to report its address correctly you would need all four pins to be working properly on both the ESP32 and the LCD.

    Reply
    • To update; I tried it on yet a different LCD – this time I can can get the backlight to come on, but still can’t send text. The row/columns are correct, and I’ve made sure to download the LCD library from your link.

      Again if I run the scanner sketch I get a reply of 0x27, and that is what is set in my output sketch.

      I’ve also tried this with a brand new ESP32, in case I’d fried the I2C bit of the other one with an ill-judged project – still no joy.

      Reply
      • Hi.
        It’s difficult to tell what might be wrong.
        If your LCD has a potentiometer at the ack, try rotating it to adjust the contrast and see if anything changes.
        Regards,
        Sara

        Reply
  30. Compilation error: invalid conversion from ‘int’ to ‘t_backlighPol’ [-fpermissive]
    Even after use right adress with scanner

    Reply
  31. Hi Sara,
    You’re absolutely beautiful,
    We are using esp32 (YD-ESP32-232022-V1.3)board. We’re are trying to connect lcd using I2C .
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x27, 16, 2);

    void setup()
    {
    Wire.begin(4,5);
    lcd.init();
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.print(” I2C LCD with “);
    lcd.setCursor(0,1);
    lcd.print(” ESP32 DevKit “);
    //delay(2000);
    }

    void loop()
    {

    }
    im running ablve code but we’re not able to see anything on lcd display
    and i used beloq code and it shows i2c device found
    #include “Wire.h”

    void setup() {
    Serial.begin(115200);
    Wire.begin(4,5);
    }

    void loop() {
    byte error, address;
    int nDevices = 0;

    delay(5000);

    Serial.println(“Scanning for I2C devices …”);
    for(address = 0x01; address < 0x7f; address++){
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0){
    Serial.printf(“I2C device found at address 0x%02X\n”, address);
    nDevices++;
    } else if(error != 2){
    Serial.printf(“Error %d at address 0x%02X\n”, error, address);
    }
    }
    if (nDevices == 0){
    Serial.println(“No I2C devices found”);
    }
    }
    there is no problem with i2c but we’re not able to see anything on display all connections are correct.I would be really grateful if you help me on this, kindly reply if you have any idea about this.
    Thank you,
    Manoj S

    Reply
    • Hi.
      Check the display power supply.
      Some Displays have a potentiometer to adjust the backlight. That might be your case.
      The LCD light might also be broken.
      Regards,
      Sara

      Reply
  32. Hi i am using esp32 and my board is esp32 wroom – i forgot the extension but its not reading or getting the I2C address, it always says “No device connected”.

    Reply
    • Hi.
      Make sure the LCD is wired correctly. Make sure you’re not switching SCL and SDA.
      Make sure GND is connected and that you’re powering 5V to VCC.
      Regards,
      Sara

      Reply
  33. Hi I have a strange problem well I have connected everything correctly and found the right address (0x27) but no characters show on the screen at all. Strangest of all, the code responsible for the backlight works, for example for such a loop function:
    void loop(){
    lcd.backlight();
    delay(3000);
    lcd.noBacklight();
    delay(3000);
    }
    the backlight is indeed on for 3 seconds, off for 3 seconds and so on. But no functions like print or createChar work

    Reply
  34. hi, i have a question on “custom characters”.
    all is working OK and i made different custom characters but seem like the limit is 8.
    is that correct?
    i tried create more than 8 but it does not work.

    is there a way to include more characters in the same SW?

    Reply
  35. Your tutorials are great, but I hit a snag with this one, Liquid Crystal I2C. I followed the instructions and got the following error and I get no output on the LCD.

    WARNING: library LiquidCrystal_I2C claims to run on avr architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s)..

    Reply
      • Sara, thank you for your response. To close the loop on this this was user error. The one part of the tutorial I didn’t follow was the part about adjusting the backlighting. On my LCD, nothing is visible until the adjustment is at the absolute extreme. So you program was working fine, I just couldn’t see it.

        Thanks again
        Greg

        Reply
  36. Thank You for the tutorial.
    While I am using the library for I2C which was build by Frank de Brabander or by johnrickman for NodeMCU there no display on screen of LCD.
    I get a warning that library used and nodeMCU are incompatable.
    Why?

    But I dint face any issue using the library mentioned in your website.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.