Challenge

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

Dear Sir/Mam

Good Morning

Please see the my ans.

If any error show in this code plese confirm me.

Master Code

#include<Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.begin(2);
Wire.onRequest(requestEvent);
}
void loop()
{

}
void requestEvent()
{
byte SlaveSend = 1 ;
Wire.write(SlaveSend);
}

Slave code

#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(34, 16, 2);
void setup()

{
Wire.begin();
Serial.begin(9600);
lcd.init();
lcd.backlight();


}
void loop()
{
Wire.requestFrom(2,1);
byte SlaveRecive = Wire.read();
Serial.println("Slave Received From Master");
Serial.println(SlaveRecive);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Slave Received ");
lcd.setCursor(0,1);
lcd.println(SlaveRecive);
delay(500);
}

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.