All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Overview of the Project: In this project implementing the Code for “Interfacing a 16*2 LCD with two Arduino’s (one for Master and one for Slave) using Inter-Integrated Circuit (I2C) communication protocol” by sending the message to LCD using I2C communication protocol and display the message on…
Chandrakumar ADEPU
updated on 31 Mar 2023
Overview of the Project:
In this project implementing the Code for “Interfacing a 16*2 LCD with two Arduino’s (one for Master and one for Slave) using Inter-Integrated Circuit (I2C) communication protocol” by sending the message to LCD using I2C communication protocol and display the message on LCD screen.
Goals:
Key Highlights of the Project:
Deliverables of this project:
Expected Outcomes:
Explanation:
The LiquidCrystal library allows you to control LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface.
The LCDs have a parallel interface, meaning that the microcontroller has to manipulate several interface pins at once to control the display. The interface consists of the following pins:
There's also a display contrast pin (Vo), power supply pins (+5V and GND) and LED Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off the LED backlight, respectively.
The process of controlling the display involves putting the data that form the image of what you want to display into the data registers, then putting instructions in the instruction register. The LiquidCrystal Library simplifies this for you so you don't need to know the low-level instructions.
The Hitachi-compatible LCDs can be controlled in two modes: 4-bit or 8-bit. The 4-bit mode requires seven I/O pins from the Arduino, while the 8-bit mode requires 11 pins. For displaying text on the screen, you can do most everything in 4-bit mode, so the example shows how to control a 16x2 LCD in 4-bit mode.
Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14 (or 16) pin count connector of the LCD screen, as you can see in the image further up.
To wire your LCD screen to your board, connect the following pins:
Additionally, wire a 10k potentiometer to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3).
The I2C protocol involves using two lines to send and receive data: a serial clock pin (SCL) that the Arduino Controller board pulses at a regular interval, and a serial data pin (SDA) over which data is sent between the two devices. As the clock line changes from low to high (known as the rising edge of the clock pulse), a single bit of information - that will form in sequence the address of a specific device and a command or data - is transferred from the board to the I2C device over the SDA line. When this information is sent - bit after bit -, the called upon device executes the request and transmits it's data back - if required - to the board over the same line using the clock signal still generated by the Controller on SCL as timing.
Because the I2C protocol allows for each enabled device to have it's own unique address, and as both controller and peripheral devices to take turns communicating over a single line, it is possible for your Arduino board to communicate (in turn) with many devices, or other boards, while using just two pins of your microcontroller.
// Wire Master Writer
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop()
{
Wire.beginTransmission(4); // transmit to device #4
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
//x++;
x=x+2;
delay(1000);
}
// Wire Slave Reader
#include <Wire.h>
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
Wire.begin(4);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello world!");
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// lcd.print(millis() / 1000);
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
lcd.setCursor(1,2);
lcd.print("x is");
lcd.setCursor(6,2);
lcd.print(x);
delay(500);
}
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week - 4
Implement control logic of a “washing machine” using Stateflow as per given sequence: If the power supply is available, the system gets activated If the Water supply is not available, stop the process & indicate through LED Soaking time should be 200s followed by Washing time of 100s. Then rinsing…
29 Sep 2023 07:17 AM IST
Project 2 - V&V SW Analysis II
Q:- 1. Perform Static Code Review Analysis for “C:\**\LDRA_workarea\Examples\C_Testbed_examples\Testrain\Testrain.c” Generate Code review report and upload them. Ans: Aim: To gernetate the code review report and upload them. Steps: Steps for White box testing:- Source ->…
18 Aug 2023 01:16 PM IST
Project 1 - V&V SW Analysis - I
Q:- Write a Test plan to test features of a new mobile phone (Blackbox test) that needs to be implemented based on the following requirements. (The product is still under development stage and is yet to be UA (User Acceptance ) tested…
12 Jul 2023 03:17 AM IST
Project 2 - Measuring distance of an object using ultrasonic sensor (HC-SR04)
PROJECT-2: Aim: To write a program to measure the distance using ultasonic sensot Schematic Diagram: Steps of Programming ATmega16 microcontroller needs to transmit at least 10 us trigger pulse to the HC-SR04 Trig Pin. After getting a trigger pulse, HC-SR04 automatically sends eight 40 kHz sound waves and the microcontroller…
24 Jun 2023 09:50 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.