Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Answer:
To perform this project we need to have Arduino Uno as master device
one more Arduino Uno as slave device
LCD displa with I2C communication CHIP ( 16X2)
and some wires for connections
Below should be the hardware connections:
1) Make connections for i2C
2) Connect Power supply
3) Make other necessary connections
Below is the code we shall use for Arduino Master
#include <Wire.h>
void setup() {
Wire.begin(); // Join I2C bus as master
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(9); // Address of the Slave Arduino
Wire.write("Hello from Master!"); // Send message to Slave
Wire.endTransmission();
delay(1000);
}
Below code for the Slave:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address
void setup() {
Wire.begin(9); // Join I2C bus with address 9
Wire.onReceive(receiveEvent); // Register receive event
lcd.begin(16, 2); // Initialize LCD
lcd.backlight(); // Turn on the backlight
lcd.clear();
}
void loop() {
// Additional code if needed
}
void receiveEvent() {
while (Wire.available()) {
char c = Wire.read();
lcd.print(c);
}
}