Home » Blog » Projects » Electronics Projects » NodeMCU I2C LCD Display Saves Pins

NodeMCU I2C LCD Display Saves Pins

nodemcu i2c lcd

My NodeMCU I2C LCD Display finally arrived. It works great and saves pins on the ESP-12E board.

Compared to the Arduino, NodeMCU V1.0 board has limited input/output pins. One of the ways to make the best of this board is to use the I2C bus for communicating with peripherals. An LCD display board with a piggyback I2C module is available. This display only needs two control lines or GPIO pins on the NodeMCU. These lines are for data and clock signals, respectively. The piggyback module converts serial data on the I2C bus to control eight digital pins on the LCD module. The whole arrangement is available on E-Bay for just over $2.

There are four things needed to get up and running.

  • Download and install the LiquidCrystal_I2C library from Marco Schwartz.
  • Figure out the I2C address for your LCD. It is usually either 0x27 or 0x3F. Here is a good reference site for these devices.
  • Hook up the LCD SCL line to NodeMCU pin D1 and the SDA line to pin D2. Also provide the LCD with five volts.
  • Write some Arduino code.
#include <LiquidCrystal_I2C.h>
 * Test program NodeMCU and YwRobot LCD 1602
 * Default I2C Pin SCL=D1 SDA=D2
 * Library modified with overloaded init() to
 * enable alternative I2C pin use

#define LCD_ADDRESS 0x3F
#define NEW_SDA D3
#define NEW_SCL D4
#define USE_NEW_I2C

LiquidCrystal_I2C lcd(LCD_ADDRESS,16,2);

void setup() {
#ifdef USE_NEW_I2C
 lcd.init(NEW_SDA, NEW_SCL);
 lcd.print("Making It Up");

NodeMCU I2C LCD Display Library Modifications

By default, the NodeMCU uses pins D1 and D2 for I2C serial communications. You might want to switch this to another set of pins. You can run the I2C bus on any two of D1 through D8, but not D0. Unfortunately, the LiquidCrystal_I2C library is hard wired to the defaults.

But changing this is easy. First you create a second (overloaded) initialization function for the library. Second, you change one line of code, as follows.

/* Modifications to LiquidCrystal_I2C.h */
  void init();
  void init(uint8_t sda, uint8_t scl);//added

/* Modifications to LiquidCrystal_I2C.cpp */
void LiquidCrystal_I2C::init(){
	Wire.begin(); //moved from init_priv

void LiquidCrystal_I2C::init(uint8_t sda, uint8_t scl){
	Wire.begin(sda, scl); //moved from init_priv

With these changes, you can run your NodeMCU I2C LCD display off any of the GPIO pins except D0. Or just use the original init() function for the default pins.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.