Challenge

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

I2C is short for Inter-IC. And it is a type of BUS. This is designed by Philips semiconductors. I2C is a synchronous, multi slave, multi master packet switched, single-ended serial bus. ie. multiple chips can be connect to the same bus.I2C uses only two bidirectional open collector or open drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V, although systems with other voltages are permitted. For more about I2C protocol.

It is also known as I2C Module. It has total of 20 male pins. 16 pins are faced to rear side and 4 pins faced towards front side. The 16 pins for connect to 16x2 LCD and the 2 pins out of 4 pins are SDA and SCL. SDA is the serial data pin and SCL is the clock pin. The rest 2 pins for power supply (Vcc and ground).There is a POT on the I2C Module. We can control the contrast of the LCD display by rotating this POT. And there is a jumber fixed on the module. When we remove the jumber, the backlight of the LCD display will go OFF.

Before starting we need to know about addressing of I2C devices. Every device which can attached to MCU have an address. We need to know this address for communicate with that particular device.

You can see three solder pads on the I2C module. which is labeled as A0, A1 and A2. This is Address selectors. ie, each solder pads have one upper potion and a one lower potion. if, there is a connection between upper potion with lower connection it is called "Connected" otherwise it is called "Not connected". When A0, A1, A2 are in "Not Connected" condition ( A0 = 0, A1 = 0, A2 = 0) the address would be 0x27. In default the A0, A1, A2 are in "Not connected" condition. And some time default address is 0x3F. There is no need to change the address of the I2C module when we use only one LCD. But when we use more than one LCD, need to change the address. Because two or more different device can't communicate with the same address.

 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);

}
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.