• Ankita Sharma

Interfacing 20 X 4 LCD Display with NodeMCu


The Internet of Things ( IoT) aims towards making life simpler by automating every small task around us. Alerts play an important role in IoT developments to notify the user about something important. It can be either in the form of LCD Display messages, Gmail notifications, LED indication / SMS alerts, or any other form.


In this article, we will learn the interfacing of 20 X 4 LCD Display with NodeMCU using the I2C communication module to display messages regarding the task performed by our IoT projects.


Hardware Components :


The hardware components required for the interfacing are as follows -


Breadboard :

Breadboard

They are basically a construction base used for prototyping electronic circuits. #Breadboards allow us to make quick connections between hardware components, without soldering.


Buy Breadboard from here.


NodeMCU :


Let us understand what is NodeMCU?

NodeMCU Esp8266

NodeMCU ( Node MicrocontrollerUnit ) is an open-source development board for creating IoT project prototypes. It is having integrated support for WiFi connection. Also, it is very cost-efficient as well as consumes less power. It allows us to use it as a micro-controller and manipulate input and output.


Buy Esp8266 from here.


I2C Module :


Let us understand What is the I2C Module?

I2C Module

It has an inbuilt chip that converts I2C serial data to parallel data for an #LCD. Directly interfacing LCD takes a lot of pins on the NodeMCU development board which makes the circuit more complicated. That is why interfacing is done via the I2C module. I2C module consists of four pins - VCC ( Power Supply ), GND ( Ground ), SDA ( Serial Data pin), SCL ( Serial Clock pin ).


Buy I2C Module with LCD from here.


LCD :

LCD

#LCD ( Liquid Crystal Display ) are mainly preferred for multi-segment light-emitting diodes and seven segments.


Buy LCD from here.


Jumper Wires :


Jumper Wires

Jumper wires are the connecting wires that have connector pins at each end, allowing them to be used to connect the two points without soldering. They typically come in three versions - male-to-male, male-to-female, and female-to-female.


Buy Jumper Wires from here.


USB Cable :


USB Cable

#USB ( Universal Serial Bus ) Cable is used to connect the development boards ( ESP8266 in this case ) to the system ( For eg: Laptops ).


Buy USB Cable from here.


Software required:


Arduino IDE :


Let us understand What is the Arduino IDE?


Arduino Integrated Development Environment is open-source software that facilitates the development and uploading of codes to the microcontroller. Program written in Arduino #IDE is called Sketch. These Sketch files are saved with the file extension ino.


Click on the link to download the software.


Circuit Connections :


The circuit connections for this interfacing are as follows -

Circuit Connections
  1. Vin pin of NodeMCU is connected to the VCC of LCD.

  2. GND of NodeMCU is connected to GND of LCD.

  3. D1 pin is connected to the SCL pin of the LCD.

  4. D2 is connected to the SDA pin of the LCD.


Code Explanation :


The code explanation is as follows -

#include<LiquidCrystal_I2C.h>   

The above command line defines a library for LCD to enable I2C communication.

#include<Wire.h>  

The above command line defines a library <Wire.h> to communicate serially through #NodeMCU to the I2C module.

LiquidCrystal_I2C lcd(0x27, 20, 4); 

The above command line creates an LCD object in which three parameters are passed. The three passed parameters are - I2C address, size of LCD ( column, row ).

char string_to_scroll[] = " Interfacing 20*4 LCD display with NodeMCU(esp8266) "; 

The above command lines define a character string that contains a message that is to be displayed on the LCD.

void setup()
{
  lcd.begin();                                
  Wire.begin(D2, D1);                // D1 is SCl and D2 is SDA.

We have enabled #I2C communication with LCD followed by serial communication using Wire. begin( ). The D1 and D2 pins refer to SCL ( Serial Clock pin ) and SDA ( Serial Data pin ) respectively.

 lcd.clear();  

This command line is used to clear the garbage value.

  lcd.setCursor(1, 0);             
  lcd.print("Learn Electronics,");          

The above command line sets the LCD cursor to column number 1 and row number 0 and then prints a message " Learn Electronics ".

  lcd.setCursor(4, 1);
  lcd.print("Welcomes You");
  

The above command line sets the LCD cursor to column number 4 and row number 1 and then prints a message " Welcomes You ".

lcd.setCursor(6, 3);
lcd.print("Good Day!");

The above command line sets the LCD cursor to column number 6 and row number 3 and then prints a message " Good Day ! ".

  delay(1500);
}

The above command line is used to set up a time delay for displaying messages on the LCD screen.

void loop()
{
  for (int ch = 0; ch <= strlen(string_to_scroll) - 20; ch++)         
  {
    scroll(0, ch);                 // calling defined function.
  }
}

We will shift the screen one by one using for loop to give a scrolling effect. Now, calling the scroll function to display the message on the LCD screen.

void scroll(int pos_1, int pos_2)              
// User Defined function for scrolling particular row.                         
{
  lcd.setCursor(pos_1, 2); 
  for (int ch = pos_2; ch <= pos_2 + 19; ch++)                        // for loop for printing the data on lcd display.
  {
    lcd.print(string_to_scroll[ch]);   // Printing Data on LCD 
  }
  lcd.print(" ");
  delay(450);
}

The above function scroll is used to scroll messages on a particular row and then print the message on an LCD screen.


Complete Code :


#include<LiquidCrystal_I2C.h>        // Library for LCD for I2C.
#include<Wire.h>                             
// Library for serial Serial data and serial clock.

LiquidCrystal_I2C lcd(0x27, 20, 4);     // Creating a lcd object.

char string_to_scroll[] = " Interfacing 20*4 LCD display with NodeMCU(esp8266) "; // string which is to be scrolled in LCD 

void setup()
{
  lcd.begin();                                
  Wire.begin(D2, D1);                // D1 is SCl and D2 is SDA.
 
  lcd.clear();                       // clearing display of LCD.
                                    
  lcd.setCursor(1, 0);             
  // seting cursor of lcd display to 1 column and 0 row.
  lcd.print("Learn Electronics,");           
   // Then print message Learn Electronics. 
  
  lcd.setCursor(4, 1);
  lcd.print("Welcomes You");
  
  lcd.setCursor(6, 3);
  lcd.print("Good Day!");
  delay(1500);
}

void loop()
{
  for (int ch = 0; ch <= strlen(string_to_scroll) - 20; ch++)         // for loop for shifting string by one.
  {
    scroll(0, ch);                 // calling defined function.
  }
}
void scroll(int pos_1, int pos_2)              
// User Defined function for scrolling particular row.                         
{
  lcd.setCursor(pos_1, 2); 
  for (int ch = pos_2; ch <= pos_2 + 19; ch++)                        // for loop for printing the data on lcd display.
  {
    lcd.print(string_to_scroll[ch]);   // Printing Data on LCD 
  }
  lcd.print(" ");
  delay(450);
}

Download the document given below, copy the code, and then paste it into the Arduino IDE code window.

LCD_Nodemcu
.txt
Download TXT • 2KB


Working :

LCD interfaced with NodeMCU ( Unpowered Setup )

Once the hardware connections are completed and the code is written, connect the ESP8266 board to the system via USB cable. Now, upload the code to the board and then run the program.


LCD interfaced with NodeMCU ( Powered Setup )

A message will be displayed on the LCD screen as shown in the above image. This indicates the successful interfacing of LCD with NodeMCU.


Do watch the video given below to get a better idea through practical implementation.


Video By - Harshit Gupta


Conclusion :


This article gives an overview of #interfacing LCD with NodeMCU to get important messages displayed on the LCD screen. It is the basic interfacing that is used in almost all #IoT projects and developments to track information with just a single glance.


See more projects on NodeMCU :





  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2021