Tutorial: LCD using only 2 arduino pins (with PCF8574 and I2C)

On this tutorial, we will learn how to use a standard 16x2 LCD with Arduino, but using just 2 pins. The magic behind is done by the PCF8574, an I/O expander that communicates with the micro-controller by I2C. If you want to learn about the PCF8574, check this previous tutorial.

Firstly, you have to download the library, there are different downloads for the 1.0 and 0022 Arduino versions:

After that, extract the files to your libraries folder inside your Arduino installation.

Get your breadboard and build the circuit show in the first picture.

Open your Arduino IDE and go to File > Examples > LiquidCrystal_I2C and select "Hello World". The following code will open:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(32,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
    lcd.init(); // initialize the lcd 

    // Print a message to the LCD.
    lcd.backlight();
    lcd.print("Hello, world!");
}

void loop()
{
}

Upload your code. You may need to turn the potentiometer to adjust the LCD contrast. You now show see the words "Hello, world!" on your display.

References:

http://arduino.cc/playground/Code/LCDi2c

http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/

Views: 77313

Comment by Mario_H on September 3, 2012 at 4:27pm

 

Just found the link to my library here and I would advise to add three resistors to the schematic above.

Two 4K7 pull-up resistors on the I2C lines (see I2C specifications).

And one current limiting resistor in series with the backlight LED to prevent damage to the backlight LED.

To calculate the correct limiting resistor you need the datasheet of the LCD.

Comment by Rob Whight on October 16, 2012 at 3:33am

Haven't got myself an LCD display yet (on day 2 with my Arduino !). Very interested in this circuit. Note it only uses two pins - would that mean that I could drive more than one display at the same time and if so, how do I go about send data to different displays ? Thx

Comment by Mario_H on October 16, 2012 at 4:32am

Yep, you can connect multiple displays to the I2C port.

Give each PCF8574 another address (using pins 1,2 and 3).

 

In the sketch define two lcd's

LiquidCrystal_I2C lcd1(0x20,16,2); // set the first LCD address to 0x20

LiquidCrystal_I2C lcd2(0x21,16,2); // set the second LCD address to 0x21

 

Initialize them in the setup-section:

lcd1.init(); // initialize the 1st lcd

lcd2.init(); // initialize the 2nd lcd

 

And send text:

lcd1.print("1st Hello!");

lcd2.print("2nd Hello!");

That's all.

More examples in the zip you can download from the link above.

Comment by Rob Whight on October 16, 2012 at 10:36am

OK - That's really helpful. The bit I think I'm struggling with is how each display knows which one it is and where it is connected. Is there a relationship between the 0x20 and 0x21 and the pinouts for example ? Appreciate your help for this here newbie !

Comment by Mario_H on October 16, 2012 at 3:32pm

On the hardware side you give each PFC an unique address (with pins 1-3).

To use them in the sketch:

First you define lcd1 as the one on address 0x20

Next you define lcd2 as the one on address 0x21

During the rest of the sketch you refer to lcd1 when you want to write to the first lcd and to lcd2 when you want to write to the second one.

So the LCD itself isn't aware of which one it is, it just displays the data it receives.

The selection is done by addressing the PCF. All data not sent to the configured address of a PCF is simply ignored. And just for clarity: to control two displays via I2c you need two of the circuits shown above.

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
yesterday
Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
yesterday
Sardar Tamoor is now a member of GarageLab (arduino, electronics, robotics, hacking)
Tuesday
Peter Davies posted a discussion

Anyone got stock of Garagelabs automation board

HiI have a requirement for 11 automation boards and have been able to source 8,  does anyone have a…See More
Tuesday
Profile IconGuilherme Barros, Rob Lambert and kevin parr joined GarageLab (arduino, electronics, robotics, hacking)
Apr 22
Tino Pascuzzi left a comment for stephen smith
"Hello, my name is Tino Pascuzzi and I'm the owner of The Sanctuary Haunted Attraction.  I…"
Apr 14
Tino Pascuzzi left a comment for Aaron Thiedt
"Hello, my name is Tino Pascuzzi and I'm the owner of The Sanctuary Haunted Attraction.  I…"
Apr 14
Tino Pascuzzi left a comment for Paul Ellison
"Hello, my name is Tino Pascuzzi and I'm the owner of The Sanctuary Haunted Attraction.  I…"
Apr 14
Tino Pascuzzi left a comment for Gary
"Hello, my name is Tino Pascuzzi and I'm the owner of The Sanctuary Haunted Attraction.  I…"
Apr 14
Tino Pascuzzi left a comment for Amauri
"Hello, my name is Tino Pascuzzi and I'm the owner of The Sanctuary Haunted Attraction.  I…"
Apr 14
Mark Mendelsihn is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 14
Tino Pascuzzi updated their profile
Apr 13
ade ljathanna is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 12
Marcelo Rodrigues commented on Steve Brune's blog post Toaster Oven Computer Modification
"lol... Cool! Congrats, Steve."
Apr 11
Steve Brune posted a blog post

Toaster Oven Computer Modification

A while back I built a Mini-Itx computer in a toaster oven. I posted it on my website here:…See More
Apr 11
Profile Iconchris yang and Hendra joined GarageLab (arduino, electronics, robotics, hacking)
Apr 11
kulvir saini is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 8
GarageLab replied to GarageLab's discussion Serious claims against BeagleBone's manufacturer CircuitCo
"Believe or not, nothing yet! CircuitCo didn't delivered the boards and they refused to refund…"
Apr 5
ammar imad is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 5
Spiros is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 4

© 2016   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service