Home > Optoelectronic Circuits >LCD Display Circuits > Two-wire I2C Arduino LCD display

Two-wire I2C Arduino LCD display

Source: InternetPublisher:z6HnSmwHu Keywords: Arduino LCD display I2C Updated: 2026/01/06

Two-wire I2C Arduino LCD display

Dual-line I2C Arduino LCD Display

In this tutorial, you will learn how to build a simple serial 16x2 LCD display controlled via an Arduino board using only two wires. The underlying principle is implemented using the PCF8574 chip, an I/O expander that communicates with a microcontroller using the I2C protocol. The PCF8574 is a quick and easy solution for expanding and adding output/input ports to an Arduino. This chip connects to the standard I2C bus and adds eight additional output ports. A total of eight LCD displays can be connected to the same two-wire I2C bus, each with a different address.

Two-wire I2C Arduino LCD display

First, you must download the library; there are different downloads available for Arduino versions 1.0 and 0022:

Arduino 1.0 libraries

Libraries for Arduino 0022 and earlier versions

Next, extract the files to the libraries folder in your Arduino installation directory.

Prepare your breadboard and build the circuit as shown in the first picture.

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


#include



`LiquidCrystal_I2C lcd(0x20,16,2);` // Sets the LCD address to 0x20 for 16 characters and 2 lines of display.

`void setup()
{
 lcd.init(); // Initializes the LCD

 // Prints messages to the LCD.
 lcd.backlight();
 lcd.print("Hello, world!");
 lcd.print("Electronics-DIY.com");
}

void loop()
{
}`

Learn how the PCF8574 works.

The PCF8574 is an 8-bit I/O port expander that uses the I2C protocol. This protocol uses a two-wire serial interface for communication, with one wire for serial clock (SCL) and the other for serial data (SDA). Using this IC, you can control up to eight digital I/O ports using only two ports on your Arduino board. In the I2C protocol, each IC has a unique address; for the PCF8574, you have a 3-bit address, allowing you to connect up to eight devices for a total of 64 ports.

We can view the pinout of the PCF8574 in the datasheet:

Where: A0, A1, and A2 are address pins.

P0, P1, P2, P3, P4, P5, P6, and P7 are digital I/O ports (each is 1 bit).

SDA and SCL are I2C pins for communicating with the microcontroller.

For the IC to function, an address needs to be set; this information can be found in the datasheet.

Where: L represents low level or 0V (GND), H represents high level or VCC

To define the addresses, set A0, A1, and A2 to your desired H or L. Remember that each IC should have a different address.

By examining the data interface, we can see how the I2C interface works on the PCF8574:

If you send an I/O data byte, it will turn the corresponding pins P1 through P7 on or off depending on the byte sent. For example, if you send the number 32, it will be binary 00100000, which will only turn on the P5 output. The same applies to reading; if you receive the number 32, it means that only port P5 is open at that time.

Two-wire I2C Arduino LCD display

Two-wire I2C Arduino LCD display

Two-wire I2C Arduino LCD display

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号