Open In App

How to interface I2C LCD display with Arduino ?

In this article, we will learn how to interface LCD displays with Arduino Uno R3.

Arduino is an open-source electronics platform. It consists ATmega328P 8-bit Microcontroller. It can be able to read inputs from different sensors & we can send instructions to the microcontroller in the Arduino. It provides Arduino IDE to write code & connect the hardware devices like Arduino boards & sensors.



LCD Display:

LCD stands for Liquid Crystal Display.  LCD is a flat-paneled display. It uses liquid crystals combined with polarized to display the content. LCD uses the light modulation property of LCD. LCD is available both in Monochrome and Multicolor. It cannot emit light directly without a backlight. In some LCDs, It displays the content only with the help of a backlight in a dark place. 

I2C communication:

I2C or IIC stands for Inter-Integrated Communication. I2C is a serial communication interface to communicate with other I2C devices. I2C uses multi-master / multi slave method. I2C uses 2 lines named SCL and SDA for transmission/reception and another 2 lines for power supply and ground. Each and every I2C device has I2C address to identify. I2C addresses of multiple devices may have the same address. The address is in the format of “0x20” (Example address). Steps to find out I2C address device is discussed in the following (step 4).



I2C LCD: 

I2C LCD uses I2C communication interface to transfer the information required to display the content. I2C LCD requires only 2 lines (SDA and SCL) for transferring the data. So, the complexity of the circuit is reduced.

Interfacing I2C LCD to the Arduino:

I2C LCD can be connected to the Arduino directly with SDA pin to SDA pin and SCL pin to SCL pin as per the below circuit diagram. I2C LCD requires additional library to be installed. The next step is to connect the LCD to the address of the device using the following code. Those steps are explained in detail below.

Components required:

  1. Arduino Uno R3
  2. I2C LCD display
  3. Jumper Wires

Steps to interface LCD display with Arduino:

Step 1: Install the library for LCD display in Arduino IDE.

Library Manager

Step 2: Import “LiquidCrystal_I2C.h” header file in the code.

Step 3: Connect display device to Arduino.

LCD display interfacing circuit

Step 4: Find the I2C Address of the display device.

Online simulation of I2C address finding using Tinkercad: https://www.tinkercad.com/things/0siOxvpmVNJ

Arduino code for I2C Address finding:




// I2C address finding
#include <Wire.h>
 
void setup()
{
    //Initializing wire
    Wire.begin();
    //Initializing seraial monitor at the baudrate of 9600
    Serial.begin(9600);
}
 
void loop()
{
    byte err, addr;
    //Declaring variable to detect and count no. of I2C device found
    int devices = 0;
     
    // For loop to try multiple combinations of Address
    for (addr = 1; addr < 127; addr++)
    {
        Wire.beginTransmission(addr);
        err = Wire.endTransmission();
 
        if (!err)
        {
            Serial.print("Address 0x");
            if (addr < 16)
            {
              Serial.print("0");
            }
            Serial.println(addr, HEX);
            devices++;
        }
        else if (err == 4)
        {
            Serial.print("Error at address 0x");
            if (addr < 16)
            {
              Serial.print("0");
            }
            Serial.println(addr, HEX);
        }
    }
     
    //Exception, when there is no I2C device found
    if (!devices)
    {
      Serial.println("Please connect your I2C device");
    }
     
    //Waiting for 2 seconds
    delay(2000);
}

Note: Make sure that you have connected the device properly.

Output:

I2C Address finding

Step 5: Define display device.




#include <LiquidCrystal_I2C.h>
 
// Format => (ADDRESS,Width,Height )
LiquidCrystal_I2C lcd(0x20, 16, 2);
 
void setup()
{
    // Initialize the lcd
    lcd.init();
    // Turn on the Backlight
    lcd.backlight();
 
    // ....
}

Step 6: Print characters in LCD.

Arduino code:




#include <LiquidCrystal_I2C.h>
 
LiquidCrystal_I2C lcd(0x20, 16, 2); // Format -> (Address,Width,Height )
 
void setup()
{
    // initialize the lcd
    lcd.init();
    // Turn on the Backlight
    lcd.backlight();
}
 
void loop()
{
    // Clear the display buffer
    lcd.clear();
    // Set cursor (Column, Row)
    lcd.setCursor(0, 0);
    // print "Hello" at (0, 0)       
    lcd.print("Hello");
    // Set cursor (Column, Row)
    lcd.setCursor(0,1);
    // print "Geek" at (0, 1)
    lcd.print("Geek");
 
    delay(100);
}

Working of code:

Initially, the library, address, height and width are defined in the code. 

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20, 16, 2);

In the setup() function, initialization and backlight are enabled.

lcd.init();
lcd.backlight();

In the loop() function,

lcd.clear(); 

  // Set cursor (Column, Row)
lcd.setCursor(0, 0);

  // print “Hello” at (0, 0)  
lcd.print(“Hello”); 

Output:

Printing characters using LCD display


Article Tags :