Challenge

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

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.