Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol
Simulation was done on Tinkercad. Tinkecad design link is shown below:
* Screenshot of circuit schematic, PDF schematic & BOM (both downloaded from Tinkercad) are attached
**Screenshots of data send by master-node which is received by the slave-node & displayed on i2c LCD are attached.
*** Arduino Codes of Master-Node and Slave-Node are given below
Master Node Arduino Code
// Include the required Wire library for I2C
#include
int x = 0;
void setup()
{
Wire.begin(); // Start the I2C Bus as Master
}
void loop()
{
Wire.beginTransmission(9); // transmit to device with address 9
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting
x++; // Increment x
if (x > 100)
{
x = 0; // reset x once it gets 100
}
delay(750);
}
Slave Node Arduino Code
// Include the required Wire library for I2C
#include
#include
int x = 0;
LiquidCrystal_I2C lcd(0x20,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display
void setup()
{
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
Wire.begin(9); // Start the I2C Bus as Slave on address 9
Wire.onReceive(receiveEvent);
// Print a message on the first line of the LCD.
lcd.setCursor(1,0); //Set cursor to character 2 on line 0
lcd.print("Data Received:");
}
void receiveEvent(int bytes)
{
x = Wire.read(); // read one character from the I2C
}
void loop()
{
lcd.setCursor(2,1); //Move cursor to character 2 on line 1
lcd.print(x);
delay(500);
}