Challenge

Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol

Aim:

Overview of the Project:

In this project implementing the Code for “Interfacing a 16*2 LCD with two Arduino’s (one for Master and one for Slave) using Inter-Integrated Circuit (I2C) communication protocol” by sending the message to LCD using I2C communication protocol and display the message on LCD screen.

Goals:

  • Communication between Arduino and 16*2 LCD using I2C protocol.
  • Displaying the message sent by Master and received by slave i.e. LCD display.

Key Highlights of the Project:

  • Using the inter-integrated circuit communication protocol, transferring the data i.e. the message we want to display is sent to the LCD.
  • Two Arduino’s connected to the LCD display and the communication is executed using I2C protocol between Arduino and the LDC display.

Deliverables of this project:

  • Communication between the Arduino’s and LCD using I2C.
  • The message passed from master to slave and displayed on the 16*2 LCD.

Expected Outcomes:

  • Students will get the Knowledge of I2C communication Protocol and the Arduino.
  • The Hardware connection of all components used in this project.
  • Displaying the message sent by master (Arduino) and received by the slave (16*2 LCD display).

Notes:

I2C lcd display overview

A typical I2C LCD display consists of a HD44780 based character LCD display and an I2C LCD.

Character LCD Display

True to its name, these LCDs are ideal for displaying text/characters only. A 16×2 character LCD, for example, has an LED backlight and can display 32 ASCII characters in two rows with 16 characters on each row.

If you look closely, you can actually see the little rectangles for each character on the display and the pixels that make up a character. Each of these rectangles is a grid of 5×8 pixels.

I2C LCD Adapter

At the heart of the adapter is an 8-Bit I/O Expander chip – PCF8574. This chip converts the I2C data from an Arduino into the parallel data required by the LCD display.

The board also comes with a small trimpot to make fine adjustments to the contrast of the display.

In addition, there is a jumper on the board that supplies power to the backlight. To control the intensity of the backlight, you can remove the jumper and apply an external voltage to the header pin that is marked as ‘LED’.

I2C Address of LCD

If you are using multiple devices on the same I2C bus, you may need to set a different I2C address for the board, so that it does not conflict with another I2C device.

To do so, the board has three solder jumpers (A0, A1 and A2) or solder pads.

Each of these is used to hardcode the address. If a jumper is shorted with a blob of solder, it sets the address.

An important point here is that many companies manufacture the same PCF8574 chip: Texas Instruments and NXP Semiconductors to name a few. And the I2C address of your LCD depends on the chip manufacturer.

The 3 address input can have 2 states, either HIGH / LOW, giving us 8 (23) different combinations.

By default, all the 3 address inputs are pulled HIGH using onboard pullups, giving PCF8574 a default I2C address of 0111111Binary or 0x3FHex.

By shorting the solder jumpers, the address inputs are puled LOW. If you were to short all three jumpers, the address would be 0x38. The range of all possible addresses spans from 0x38 to 0x3F. Please refer the below illustration.

I2C LCD display Pinout

An I2C LCD has only 4 pins that interface it to the outside world. The connections are as follows:

GND is a ground pin and should be connected to the ground of Arduino.

VCC supplies power to the module and the LCD. Connect it to the 5V output of the Arduino or a separate power supply.

SDA is a Serial Data pin. This line is used for both transmit and receive. Connect to the SDA pin on the Arduino.

SCL is a Serial Clock pin. This is a timing signal supplied by the Bus Master device. Connect to the SCL pin on the Arduino.

Hooking up an Arduino Uno to an I2C LCD display

It is much easier to connect an I2C LCD than to connect a standard LCD. You only need to connect 4 pins instead of 12. Start by connecting VIN pin to the 5V output on the Arduino and connect GND to ground.

Now we are remaining with the pins that are used for I2C communication. Note that each Arduino Board has different I2C pins which should be connected accordingly. On the Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also known as A5 (SCL) and A4 (SDA).

The following diagram shows you how to wire everything.

Adjusting The LCD Contrast

After you wire the LCD, you will need to adjust the contrast of the display. On the I2C module, you will find a potentiometer that you can turn with a small screwdriver.

Plug in the USB connector of the Arduino to power the LCD. You should see the backlight light up. Now rotate the potentiometer until the first line of the rectangle appears.

Once that is done, we can start programming the LCD.

Program:

Master code:

#include<LiquidCrystal.h> //Library for LCD display function

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Define LCD Module Pins (RS,EN,D4,D5,D6,D7)

int val1=A4;

int val2=A5;

void setup()

{

lccd.begin(16,2);

}

void loop()

{

lcd.setCursor(0,0); //Sets Cursor at line one of LCD

lcd.print(">> Master <<"); //Prints >> Master << at LCD

lcd.setCursor(0,1); //Sets Cursor at line two of LCD

lcd.Print("SlaveVal: 99"); //Prints SlaveVal: in LCD

LCD

delay(1000);

}

Slave Code:

#include <LiquidCrystal.h> //Library for LCD Display Function

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Define LCD

Module Pins(RS,EN,D4,D5,D6,D7)

int val1=A4;

int val2=A5;

void setup()

{

lcd.begin(16,2);

}

void loop()

{

lcd.setCursor(0,0); //Sets Cursor at line one of LCD

lcd.print(">> Slave <<"); //Prints >> Slave << at LCD

lcd.setCursor?(0,1); // Sets Cursor ar line two of LCD

lcd.print("MasterVal: 100"); //Prints MasterVal: in LCD

delay(1000);

}

Reference website : https: //lastminuteengineers.com/i2c-lcd-arduino-tutorial/

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.