You are on page 1of 7

16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial

Home (http://www.electroschematics.com)/Arduino (http://www.electroschematics.com/arduino/)/Arduino I2C LCD Backpack


Introductory Tutorial

(http://www.electroschematics.com/wp-content/uploads/2015/12/I2C-

LCD-Backpack-Primer.png)

Arduino I2C LCD Backpack Introductory Tutorial


T.K. HAREENDRAN (HTTP://WWW.ELECTROSCHEMATICS.COM/AUTHOR/HAREENDRAN/)

(https://www.facebook.com/sharer/sharer.php?u=http://www.electroschematics.com/12459/arduino-i2c-lcd-
backpack-introductory-tutorial/) (https://twitter.com/share) (/qa/)
Assume that you are moving towards a complex microcontroller project bundled with blinkers, beepers, and a display panel.
To link a standard 162 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!

http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 1/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial

(http://www.electroschematics.com/wp-content/uploads/2015/12/I2C-LCD-Backpack-Primer.png)

I2C LCD Backpack


Hitachis HD44780 based 162 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.

(http://www.electroschematics.com/wp-
content/uploads/2015/12/address-
selection-pads-in-the-lcd-
backpack.png)
(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.

(http://www.electroschematics.com/wp-
content/uploads/2015/12/reference-circuit-diagram-of-the-lcd-
backpack.png)

http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 2/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial
(reference circuit diagram of the lcd backpack)

I2C LCD Display


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

(http://www.electroschematics.com/wp-
content/uploads/2015/12/lcd-display-to-arduino-wiring.png)
(lcd display to arduino wiring)

Arduino Setup
For this experiment it is necessary to
download (http://www.electroschematics.com/wp-content/uploads/2015/12/Liquid-Crystal-Libray-Download.rar) 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.

1./*
2.Project:I2CLCDBackpackArduinoExperiment
3.By:T.K.Hareendran/TechNodeProtolabz
4.For:http://www.electroschematics.com
5.Includes:Libraryfromhttps://bitbucket.org/fmalpartida/newliquidcrystal/downloads*
6.Hardware/Controller:Seearticle
7.Software/Sketch:PreciselyadaptedRef:Internet
8.Date:December2015
9.*/
10.#include"Wire.h"//ForI2C
11.#include"LCD.h"//ForLCD
12.#include"LiquidCrystal_I2C.h"//Addedlibrary*
13.//SetthepinsontheI2CchipusedforLCDconnections
14.//ADDR,EN,R/W,RS,D4,D5,D6,D7
15.LiquidCrystal_I2Clcd(0x27,2,1,0,4,5,6,7);//0x27isthedefaultI2Cbusaddressofthebackpackseearticle
16.voidsetup()
17.{
18.//SetoffLCDmodule
19.lcd.begin(16,2);//16x2LCDmodule
20.lcd.setBacklightPin(3,POSITIVE);//BL,BL_POL
21.lcd.setBacklight(HIGH);
22.}
23.voidloop()
24.{
25.lcd.home();//Setcursorto0,0
26.lcd.print("protolabz");//Customtext
27.lcd.setCursor(0,1);//Gotohomeof2ndline
28.lcd.print(millis()); (/)
29.delay(1000);//Blinksofbacklight
30.lcd.setBacklight(LOW);//Backlightoff
31.delay(500);
32.lcd.setBacklight(HIGH);//Backlighton
33.delay(1000);
34.}

download the sketch (http://www.electroschematics.com/wp-content/uploads/2015/12/Example-Sketch-Author.rar)


If you are 100% sure that everything is okay, but you dont 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 authors 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 di cult to get a good catch due to polarization e ects.

http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 3/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial

(http://www.electroschematics.com/wp-
content/uploads/2015/12/from-authors-workbench.png)
(from authors workbench)

Lab Note
The hardware con guration described have been tested with an Arduino UNO R3, a 162 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 o cial documentation can be downloaded from the download
section of this repository (https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads) 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!

Previous
Arduino with Keypad
Tutorial
(http://www.electroschematics.com/12446/arduino-with-keypad/)

Next
CAN Transceiver for
Automotive
(http://www.electroschematics.com/12468/can-transceiver-for-
automotive/)

Related Tutorials

Arduino Stepper Motor Driver (http://www.electroschematics.com/12353/arduino-stepper-motor-driver/)


Arduino with Keypad Tutorial (http://www.electroschematics.com/12446/arduino-with-keypad/)
Arduino Joystick Experiment Tutorial #10 (http://www.electroschematics.com/10619/arduino-joystick-experiment/)
Arduino 7 Segment LED Display and Counter Tutorial #8 (http://www.electroschematics.com/9636/arduino-segment-display-counter/)

11This
Comments
website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More (/policy/)

(/)

Join the conversation!


You must be logged in (http://www.electroschematics.com/wp-login.php?
redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-backpack-introductory-
tutorial%2F) to post a comment.

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

Posted on October 09th 2016 | 5:30 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901295)


http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 4/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial
Posted on October 09th 2016 | 5:30 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901295)
Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

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.

Posted on October 11th 2016 | 4:04 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-


1901301)

grswamy12367gmail-com
Thank you Mr Hareendran for the response. The clari cation 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 clari cation will be of great help.

Posted on October 09th 2016 | 4:58 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901293)


Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

grswamy12367gmail-com
Thank you Mr Hareendran for the response. The clari cation 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 clari cation will be of great help.

Posted on October 09th 2016 | 4:57 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901292)


Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

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 IC module!

Posted on October 09th 2016 | 5:20 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-


1901294)

grswamy12367gmail-com
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More (/policy/)

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

Posted on October 09th 2016 | 4:55 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901291)


Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

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);
Posted on October 09th 2016 | 11:16 am (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901289)
http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 5/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial
Posted on October 09th 2016 | 11:16 am (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1901289)
Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

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

Posted on October 09th 2016 | 4:34 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-


1901290)

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

Posted on May 10th 2016 | 10:58 am (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1900320)


Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

T.K.Hareendran
@Lisa: Thanks for your feedback, and suggestions!

Posted on May 12th 2016 | 6:25 am (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1900397)


tkhareendran
While sur ng I found a good I2C FAQ on the web. Ardent readers may nd this very useful:

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

Posted on December 01st 2015 | 4:50 pm (http://www.electroschematics.com/12459/arduino-i2c-lcd-backpack-introductory-tutorial/#comment-1871662)


Log in to Reply (http://www.electroschematics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.electroschematics.com%2F12459%2Farduino-i2c-lcd-
backpack-introductory-tutorial%2F)

Login
Email
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More (/policy/)

(/)
Password

Remember Me

Log In

Register (http://www.electroschematics.com/register) | Lost your password? (http://www.electroschematics.com/lostpassword)

Latest Article Comments

http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 6/7
16/12/2016 ArduinoI2CLCDBackpackIntroductoryTutorial

Static Reversing the 3 Phase Induction... (http://www.electroschematics.com/12284/static-reversing-the-3-phase-


induction-motor/#li-comment-1901860)
"in Static Reversing the 3 Phase Induction Motor diagrams i have some problems think we are in"

Fan Speed Controlled by Temperature and... (http://www.electroschematics.com/9540/arduino-fan-speed-controlled-


temperature/#li-comment-1901859)
"I have a problem with compiling that code. i am newbie in this so i dont know how to set the code"

Fan Speed Controlled by Temperature and... (http://www.electroschematics.com/9540/arduino-fan-speed-controlled-


temperature/#li-comment-1901858)
"Hi,I still have a problem with that code. can you send me your"

Working With Bootloaders & Build Your Own Bootloader -... (http://www.electroschematics.com/10922/working-
bootloaders-build-bootloader-2/#li-comment-1901857)
"where i can download bootloader"

Temperature Controlled Relay with Arduino - Tutorial... (http://www.electroschematics.com/8998/arduino-temperature-


controlled-relay/#li-comment-1901855)
"Hey i wanna ask that if i use DHT 11 to change as LM35 the program still can be"

View More ()

New Projects Recent Q&A

Inexpensive DIY Gauss Meter Project (http://www.electroschematics.com/13035/inexpensive-diy-gauss-meter-project/)

Mobile Phone Battery Emulator (http://www.electroschematics.com/13031/mobile-phone-battery-emulator/)

Sine Wave Generator Circuit (http://www.electroschematics.com/13021/sine-wave-generator-circuit/)

Portable Power Inverter Circuit (http://www.electroschematics.com/13015/portable-power-inverter/)

Projector Hushbox with the STM32F4 Firmware (http://www.electroschematics.com/13002/13002/)

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More (/policy/)

(/)

http://www.electroschematics.com/12459/arduinoi2clcdbackpackintroductorytutorial/ 7/7