Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address if necessary
void setup() {
Wire.begin();
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
sendMessageToSlave("Hello, Slave!");
delay(2000);
}
void sendMessageToSlave(const char* message) {
Wire.beginTransmission(9); // Address of the Slave Arduino (change if necessary)
Wire.write(message);
Wire.endTransmission();
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address if necessary
void setup() {
Wire.begin(9); // Address of the Slave Arduino (change if necessary)
Wire.onReceive(receiveMessageFromMaster);
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
// Nothing to do in the loop as we will receive data through I2C interrupt
}
void receiveMessageFromMaster(int byteCount) {
String message = "";
while (Wire.available()) {
char c = Wire.read();
message += c;
}
// Display the received message on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Received:");
lcd.setCursor(0, 1);
lcd.print(message);
}