Driving an LCD using I2C

You can use your ESP8266 to communicate with I2C devices such as LCD displays, sensors, other microcontrollers, etc. This example writes to a 20x4 character LCD. You can use most types of Hitachi HD44780 compatible LCDs providing they also have an I2C backpack to change the interface from 4- or 8-bit parallel to I2C. If you're ordering an LCD, ensure that it has the backpack included; otherwise you can order them separately and solder them together yourself.

Exclamation mark

Not all I2C backpacks have the same bus address. They are usually either 0x27 or 0x3F so you could try both to see which is correct. Alternatively, you can use the I2C scanner here to scan the whole range of possible I2C pins and addresses.

The four connections required for I2C are +3.3V, GND, SCL and SDA. The pins to use for SCL and SDA are not fixed and are specified in the setup() function in your sketch and can be any pair from the range D0 to D7. There may be issues using D8, so avoid using that. Also, if you wish to use the onboard LED, that's on D2, so keep that free.

You can download the sketch here or just copy and paste from below.

* es-i2c-lcd             V1.0 02-Aug-2018 JST Lawrence.                        *
*                                                                              *
* Purpose: simple driver for LCD test using I2C.                               *
*                                                                              *
// SOURCE: https://www.instructables.com/id/Interface-LCD-Using-NodeMCU/

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

#define SCL 0
#define SDA 2

// Define lcd - address, number of columns, number of rows
LiquidCrystal_I2C lcd(0x3F,20,4);

void setup()
  Wire.begin(SDA,SCL);  // GPIO numbers for SDA and SCL respectively
                        // SDA - GPIO2 - pin D4
                        // SCL - GPIO0 - pin D3
  lcd.print("Hello World!");
void loop()