Advertisement
I2C LCD Backpack Primer

Arduino I2C LCD Backpack Introductory Tutorial

Assume that you are moving towards a complex microcontroller project bundled with blinkers, beepers, and a display panel. To link a standard 16×2 LCD directly with the microcontroller, for instance Arduino, you would need atleast 6 I/O pins to talk to the LCD. However, if you use an LCD module with I2C interface, you only need 2 lines to process the display information. Now a days, it is not necessary to buy an expensive I2C LCD for this task because readymade serial backpack modules for standard LCDs are available at reasonable rates. You can use them with LCD modules that have a HD44780 compatible interface with various screen sizes by attaching to the back of the LCD module. This allows connection to your Arduino (or other microcontroller) using only four channels. Yippee!

I2C LCD Backpack Primer

I2C LCD Backpack

Hitachi’s HD44780 based 16×2 character LCD are very cheap and widely available, and is an essential part for any project that displays information. Using the LCD backpack, desired data can be displayed on the LCD through the I2C bus. In principle, such backpacks are built aorund PCF8574 (from NXP) which is a general purpose bidirectional 8 bit I/O port expander that uses the I2C protocol. The PCF8574 is a silicon CMOS circuit provides general purpose remote I/O expansion (an 8-bit quasi-bidirectional) for most microcontroller families via the two-line bidirectional bus (I2C-bus). Note that most backpack modules are centered around PCF8574T (SO16 package of PCF8574 in DIP16 package) with a default slave address of 0x27. If your backpack holds a PCF8574AT chip, then the default slave address will change to 0x3F. In short, your backpack is based on PCF8574T and the address connections (A0-A1- A2) are not bridged with solder it will have the slave address 0x27.

address selection pads in the lcd backpack

(address selection pads in the lcd backpack)

Reference circuit diagram of an Arduino-compatible LCD backpack is shown below. What follows next is information on how to use one of these inexpensive backpacks to interface with a microcontroller in ways it was exactly intended.

reference circuit diagram of the lcd backpack

(reference circuit diagram of the lcd backpack)

I2C LCD Display

Now let’s get started. At first you need to solder the backpack to your LCD module. Ensure that the backpack pins are straight and fit in the LCD module, then solder in the first pin while keeping the backpack in the same plane with the LCD. Once you have finished the soldering work , get four jumper wires and connect the LCD module to your Arduino as per the instruction given below.

lcd display to arduino wiring

(lcd display to arduino wiring)

Arduino Setup

For this experiment it is necessary to download and install the “Arduino I2C LCD” library. First of all, rename the existing “LiquidCrystal” library folder in your Arduino libraries folder as a backup, and proceed to the rest of the process.
Next, copy-paste this example sketch for the experiment into the blank code window, verify, and then upload.

/*
Project: I2C LCD Backpack Arduino Experiment
By: T.K.Hareendran/TechNode Protolabz
For: http://www.electroschematics.com
Includes: Library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads*
Hardware/Controller: See article
Software/Sketch: Precisely adapted – Ref: Internet
Date: December 2015
*/
#include "Wire.h" // For I2C
#include "LCD.h" // For LCD
#include "LiquidCrystal_I2C.h" // Added library*
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
void setup()
{
   // Set off LCD module
   lcd.begin (16,2); // 16 x 2 LCD module
   lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
   lcd.setBacklight(HIGH);
}
void loop()
{
   lcd.home (); // Set cursor to 0,0
   lcd.print("protolabz"); // Custom text
   lcd.setCursor (0,1); // Go to home of 2nd line
   lcd.print(millis());
   delay(1000); // Blinks of backlight
   lcd.setBacklight(LOW); // Backlight off
   delay(500);
   lcd.setBacklight(HIGH); // Backlight on
   delay(1000);
}

If you are 100% sure that everything is okay, but you don’t see any characters on the display, try to adjust the contrast control pot of the backpack and set it a position where the characters are bright and the background does not have dirty boxes behind the characters. Following is a partial view of author’s experiment with the above described code. Since the display used by the author is a very clear bright “black on yellow” type, it is very difficult to get a good catch due to polarization effects.

from author’s workbench

(from author’s workbench)

Lab Note

The hardware configuration described have been tested with an Arduino UNO R3, a 16×2 LCD, and an I2C LCD backpack purchased from an eBay seller. Further, the example sketch has been fully tested with a 4 bit interface as described using Arduino IDE0022. Source code for the library used here and its official documentation can be downloaded from the download section of this repository which comes in source and with examples that will get you started. Additionally you have a full description of the library in the docs folder in HTML format that you can browse. Have fun!

11 Comments

Join the conversation!

Error! Please fill all fields.
  • grswamy12367gmail-com

    Thank you very much sir, I wanted to connect some of those pins for rotary encoder to use interrupts.

    • T.K.Hareendran

      Welcome! Note that those 2 pins in your Arduino (SCL,SDA) can also be shared with other I2C based peripherals. Carry on….

  • grswamy12367gmail-com

    Thank you Mr Hareendran for the response. The clarification I required was : Do the other arguments represent the arduino pin numbers?. If so will I be able to
    use pins mentioned in the bracket for other purposes? (0x27,2,1,0,4,5,6,7). Are they required for communication in addition to SDA and SCL pins?. Your clarification will be of great help.

  • grswamy12367gmail-com

    Thank you Mr Hareendran for the response. The clarification I required was : Do the other arguments represent the arduino pin numbers?. If so will I be able use pins mentioned in the bracket for other purposes? (0x27,2,1,0,4,5,6,7). Are they required for communication in addition to SDA and SCL pins?. Your clarification will be of great help.

    • T.K.Hareendran

      To the best of my knowledge, the arguments (and the display hardware) are not connected with Arduino pins (except SDA & SCL). So you can use your Arduino I/O as desired. Actually, those arguments are required for the library to send correct signals to appropriate pins of the I²C module!

  • grswamy12367gmail-com

    Thank you Mr Hareendran for the response. The clarification I required was : Do the other arguments represent the arduino pin numbers?. If so will I be use pins mentioned in the bracket for other purposes? (0x27,2,1,0,4,5,6,7). Are they required for communication in addition to SDA and SCL pins?. Your clarification will be of great help.

  • grswamy12367gmail-com

    I use arduino mega 2560 r3 with pins 20 and 21 for sda and scl to communicate with i2c lcd backpack

    What exactly are the arguements in the brackets other than the address 0x27. (0x27,2,1,0,4,5,6,7) in the following command line.

    LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);

    • T.K.Hareendran

      As you may well know, there are several Character LCD I²C modules on the market. So you should use correct initialization code (might be slightly different for each module). After initialization,next is to instantiate the LCD object by calling LiquidCrystal_I²C class constructor. This constructor accepts parameter in following order: addr, en, rw, rs, d4, d5, d6, d7, bl, blpol. Note that the first argument (addr) is mandatory,other arguments are optional, if not specified they will be set to their default values. Hope this helps…

  • Lisa

    Really cool, I think you can upload your project on openhardware.io for sale.

  • tkhareendran

    While surfing I found a good I2C FAQ on the web. Ardent readers may find this very useful:

    http://mbouget.perso.neuf.fr/i2c-faq.html

Looking for the latest from TI?