Connect LCD display to Arduino with only two pins I2C adapter

In this tutorial learn how to connect a LCD display to arduino using I2C adapter module and thus be able to control our Alphanumeric LCD with just two 2 data pins and 2 pins for VCC and GND.

You might have experienced some issue when connecting a LCD display to Arduino with nearly 16 pins. Some times it is hard to put an LCD at a distance from Arduino  due to the bulky wires. So in this case its better to use an adapter which is made to simplify this process, by interfacing this adapter with only 2 wires we can control the LCD display with Arduino. This I2C adapter has some special inbuilt controls to change the contrast and backlight of the LCD display module.

This tutorial is similar to the  LCD Tutorial, connecting your Arduino to an LCD1602 and LCD2004 , with the slight difference that we will now use an  LCD to I2C adapter module We will work with few examples that demonstrate using the adapter module is as simple as if we were working directly with the LCD.

LCD to I2C Adapter Module Hardware

The LCD to I2C adapter module that we will use is based on the I2C PCF8574 controller, which is an I2C-controlled digital Input and Output Expander. Due to the PCB design, this module is specially used to control an Alphanumeric LCD.

The default I2C address of the module can be 0x3F or in other cases 0x27.  It is very important to correctly identify the I2C address of our module, otherwise our program will not work correctly. To identify the specific address of our module we can use a small test sketch called: I2C Scanner, which allows us to identify the I2C address of the device connected to the Arduino. If there is a need to work with more than one LCD, we can modify the I2C address of the adapter module. For this it is necessary to solder the jumpers A0, A1 and A2 present in the module, these three jumpers are the least significant bits of the I2C address of the module. The address 0x3F in binary would be: 0 | 0 | 1 | 1 | 1 | A2 | A1 | A0 and the address 0x27: 0 | 0 | 1 | 0 | 0 | A2 | A1 | A0. By default A0, A2, A1 are worth 1 but if we solder the bridges, they are connected to ground having a value of 0. For example if we solder the three bridges the new address would be 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 (0x20), for a chip that was previously 0x27.

I2C Serial Interface Adapter Module
I2C Serial Interface Adapter Module

To control the contrast of the digits on the LCD we only need to turn the potentiometer on the module, until we are satisfied with the contrast shown.

The backlight is mainly controlled by software from the Arduino, but the module also allows you to disconnect the Led from the backlight by removing an LED jumper.

Interfacing Arduino and LCD to I2C adapter module

The LCD to I2C adapter has the pins arranged to connect directly to the LCD, this can be done through a breadboard or by soldering directly to the LCD.

i2c adapter soldered to LCD display module

To connect to the module with the Arduino we only use the I2C pins of the Arduino (SDA and SCL) and power (GND and 5V), the I2C pins vary according to the Arduino model with which we work, in the following table we can see which They are the I2C pins for each Arduino model.

LCD to I2C adapter Arduino Uno, Nano, Mini. Arduino Mega, DUE Arduino Leonardo
  VCC 5V 5V 5V
  SDA A4 20 2
  SCL A5 21 3

Interfacing LCD and I2C adapter module to arduino circuit diagram* You can connect 20 x 4 LCD in the same way as shown in the above circuit diagram. As the I2C adapter used is same.

LiquidCrystal_I2C library for Arduino

There are different types and versions of libraries to work with the LCD to I2C Adapter module, more complete information can be found at: http://playground.arduino.cc/Code/LCDi2c ,

we will use the LiquidCrystal_I2C library. Download here.

The functions this library uses are similar to the Arduino LiquidCrystal library , Lets see what are the available functions and what they perform:

LiquidCrystal_I2C (lcd_Addr, lcd_cols, lcd_rows)

Constructor function, creates an object of class LiquidCrystal_I2C, with indicated address, columns and rows.

init ()

Initialize the LCD to I2C adapter module, this function internally configures and initializes the I2C and LCD.

clear ()

Clear the LCD screen and position the cursor in the upper left corner (position (0,0)).

setCursor (col, row)

Position the LCD cursor at the position indicated by col and row (x, y); that is, set the location where text written for the LCD will be displayed later.

print ()

Write a text or message on the LCD, its use is similar to a Serial.print

scrollDisplayLeft ()

Scrolls the screen content (text and cursor) one space to the left.

scrollDisplayRight ()

The screen content (text and cursor) is moved one space to the right.

backlight ();

Turn on the LCD Backlight

noBacklight ();

Turn off the LCD Backlight

createChar (num, data)

Create a custom character for use on the LCD screen. Up to eight 5×8 pixel characters (numbered 0-7) are supported. Where: num is the character number and data is an array containing the pixels of the character. An example of this will be seen later.

As we learnt about the functions lets see them perform tasks in live examples below

Example 1: Display simple text on LCD module using Arduino

In this example we just show a simple text on the display module. Just copy the code below and upload in the Arduino.

After upload the code your LCD display will display as the image shown below.

output on LCD i2c adapter

Example 2: Text Scrolling on the LCD module

In this example we will use the scrollDisplayLeft () function to move the text from right to left. Copy the code below and upload it on Arduino:

After uploading the code your display module shows as below image.

output for scrolling test on LCD i2c adapter

Example 3: Create custom characters on LED display using arduino

In some cases the LCD does not include by default the characters that we need, or we want to draw custom characters, in this case we use the createChar () function but before we study how a character is constituted:

A character is made up of an array of 5×8 pixels which are represented by 8 bytes, one for each row, the least significant 5 bits represent the pixels of the character:

binary hex creations for custom characters

If you cannot create those binary or hex codes for the your custom characters the simply use the  tool LCD Custom Character Generator from this link here.

custom character generator for LCD arduino binay code

The code for the this example will be automatically generated in the LCD Custom Character Generator.

If you find this project helpful, please support us by following our Facebook page and share it with your friends. If you have any doubts please comment below. Thanks

CircuitSchools Staff

We at CircuitSchools publish on basics of electronics and electric components and everything related to evolution of electrical technology with complete analysis of development boards and modules along with latest projects with innovative ideas.

Related Articles

Back to top button