BytesOfProgress

Wiki


ESP32 I2C LCD Display (16x2 / 20x4)

Generally, the coordinate you want to print your string to, in its code form, is always n-1. That means if you want to display something on the 3rd cell of the second row, you declare cell 2 of row 1 in the code.

This example uses a 20x4 display with the I2C address "0x27". The I2C address might vary depending on the display your are using. The most common ones are "0x27" and 0x3F".

When using a 16x2 LCD, you have to change "LiquidCrystal_I2C lcd(0x27,20,4)" to "LiquidCrystal_I2C lcd(0x27,16,2)". This is also where you correct the I2C address if needed.


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

  // Display data
  LiquidCrystal_I2C lcd(0x27,20,4);

  void setup() {
    lcd.init();
    lcd.backlight();
    lcd.clear();
  }

  void loop() {
    lcd.setCursor(4, 1);
    lcd.print("Hello World!");
  }




back