Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Aim:
In this project, I implemented 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 displaying the message on the LCD screen.
//MASTER//I2C Communication between Two Arduino//
#include <Wire.h> //Library for I2C Communication functions
#include <LiquidCrystal.h> //Library for LCD display function
LiquidCrystal lcd(2,3,4,5,6,7); //Aurdino pins connected to LCD Digital pin 4=D4,5=D5,6=D7,7=D7,2=Reset and 3=Enable
char MasterReceive[16]; //string to get the message
void setup()
{
Serial.begin(9600); //Begins Serial Communication at 9600 baud rate
Wire.begin(); //Begins I2C communication with pins (A4,A5)
lcd.begin(16,2);
lcd.clear(); //Clears LCD display
}
void loop()
{
Wire.requestFrom(8,16); //8 Address 16 characters
lcd.setCursor(0,0); //To move the cursor the begining
lcd.print("MASTER"); //TO print in display
lcd.setCursor(0,1); //To move the cursor to the next line
int i=0;
while(0<Wire.available()) // To check the number bytes available
{
MasterReceive[i]=Wire.read(); //To print Charactor by charactor
i++;
}
lcd.print(MasterReceive); //TO print the received message
delay(1000); //delay for 1 second
Wire.end(); //to end the I2C Transmission
}
//SLAVE//I2C Communication between Two Arduino
#include <Wire.h> //Library for I2C Communication functions
#include <LiquidCrystal.h> //Library for LCD display function
LiquidCrystal lcd(2,3,4,5,6,7); //Define LCD Module Pins 2,3,4,5,6,7 are Digital pins connected to LCD pins (RS,EN,D4,D5,D6,D7) respectively
void setup()
{
Serial.begin(9600); //Begins Serial Communication at 9600 baud rate
Wire.begin(8); //Begins I2C communication with Slave Address as 8 at pin (A4,A5)
Wire.onRequest(send); // TO call the send function
lcd.begin(16,2); //To start the LCD Display
lcd.clear(); //Clears LCD display
}
void loop()
{
lcd.setCursor(0,0); //To move the cursor to the begining
lcd.print("SLAVE"); //To display in LCD
lcd.setCursor(0,1); //To move the cursor to the next line
lcd.println("Message sent"); //To display in LCD
}
void send()
{
char ch[14]="Slave Message"; //Creating the string
Wire.write(ch); //To send message to master
}
OUTPUT:


