LCD interface using I2C Module with Arduino

I2C module with LCD display using Arduino

 How to interface PCF85574 module with arduino?
To connect LCD display 16×2 or 20×4 to Arduino you know you’ll need at least 6 wires to connect, it means sacrificing some IO’s that could be used for connecting other components such as sensors or motors. another way is to use 74HC595 Shift register for interfacing. In this tutorial we will discuss on PCF8574 I2C LCD Display Interface.
A module that can be used to circumvent this problem is the I2C Module for LCD Display with PCF8574 (datasheet ):

With this module, you can control an LCD display, either 16×2 or 20×4, using only two pins Arduino: the analog input pin 4 (SDA) and the analog input pin 5 (SCL) forming the I2C interface.
I2C Module structure
In the module left side we have 4 pins, and two are for power ( Vcc and GND ), and the other two are the interface I2C ( SDA and SCL ) . The plate pot is for display contrast adjustment, and the jumper on the opposite side allows the back light is controlled by the program or remain off for power saving.
By default the module is configured with the address 0x27 , but you can change this address using the pins A0, A1 and A2 Jumper settings.

Step 1: Connection of I2C LCD Module with Arduino

 The module has 16 pins that can be directly connected to the display, or you can test the connection in breadboard, as I did riding the circuit below where I used a 16×2 LCD display with HD44780 controller connected to the Arduino Uno: If you are using an Arduino Mega 2560, use the pin 20 (SDA) and 21 (SCL) :
Circuit Arduino I2C Display LCD Interface
Circuit Arduino I2C Display LCD Interface

Step 2: Programming I2C LCD Module with Arduino

Download: LiquidCrystal_PCF8574 Library
To control this I2C module, use the library LiquidCrystal_PCF8574. Upload Library using menu Sketch >> Include Library >> Add .ZIP File
The commands for display control are almost the same library  LiquidCrystal we use normally with commands such as lcd.begin () , lcd.print ()   and lcd.setCursor () . In I2C library, the command lcd.setBacklight () alloy (HIGH ) or off ( LOW ) the display backlight.
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>

LiquidCrystal_PCF8574 lcd(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display

int show;

void setup()
{
  int error;

  Serial.begin(115200);
  Serial.println("LCD...");

  // See http://playground.arduino.cc/Main/I2cScanner
  Wire.begin();
  Wire.beginTransmission(0x27); //Your LCD Address
  error = Wire.endTransmission();
  Serial.print("Error: ");
  Serial.print(error);

  if (error == 0) {
    Serial.println(": LCD found.");

  } else {
    Serial.println(": LCD not found.");
  } // if

  lcd.begin(16, 2); // initialize the lcd
  show = 0;
} // setup()

void loop()
{
  if (show == 0) {
    lcd.setBacklight(255);
    lcd.home(); lcd.clear();
    lcd.print("Hello LCD");
    lcd.setCursor(0,1);<br>    lcd.print("circuits4You.com");
    delay(1000);

    lcd.setBacklight(0);
    delay(400);
    lcd.setBacklight(255);

  } else if (show == 1) {
    lcd.clear();
    lcd.print("Cursor On");
    lcd.cursor();

  } else if (show == 2) {
    lcd.clear();
    lcd.print("Cursor Blink");
    lcd.blink();

  } else if (show == 3) {
    lcd.clear();
    lcd.print("Cursor OFF");
    lcd.noBlink();
    lcd.noCursor();

  } else if (show == 4) {
    lcd.clear();
    lcd.print("Display Off");
    lcd.noDisplay();

  } else if (show == 5) {
    lcd.clear();
    lcd.print("Display On");
    lcd.display();

  } else if (show == 7) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*** first line.");
    lcd.setCursor(0, 1);
    lcd.print("*** second line.");

  } else if (show == 8) {
    lcd.scrollDisplayLeft();
  } else if (show == 9) {
    lcd.scrollDisplayLeft();
  } else if (show == 10) {
    lcd.scrollDisplayLeft();
  } else if (show == 11) {
    lcd.scrollDisplayRight();
  } // if

  delay(2000);
  show = (show + 1) % 12;
} // loop()

Use of I2C Reduces required IO lines and you can connect many devices on same I2C wires.

One thought on “LCD interface using I2C Module with Arduino

Leave a Reply