Using displays in a hardware project is cool. We can add a display to interact with the user to make the project more user-friendly. Which adds value to any IoT or embedded project. We can use LCD display, LED display, OLED display, AMOLED display, or any other display in our project. But LCD (Liquid Crystal Display) is very popular among all embedded systems projects.
Today, we will learn how to interface LCD display with Arduino using the I2C protocol. Which uses only 4 wires as follows:
- SCL
- SDA
- VCC
- GND
Interface 16x2 LCD with Arduino using I2C
We had to use 12 wires to interface the LCD display with microcontrollers in parallel communication. But using I2C communication, we can use only 2 wires to interface LCD displays with any I2C supported microcontrollers. For this, we need I2C Serial Interface Adapter (I2C Module).
I2C Serial Interface Adapter |
I2C Serial Interface Adapter Pinout
The I2C module has a total of 20 pins. The 16 pins at the top are for the 16x2 display. The rest of the 4 pins are SCL SDA VCC and GND. The 20 pins have to connect with the LCD's 20 pins, as shown in the diagram.
Connections between Arduino and I2C Module
VCC is the power supply to the I2C module. This pin connects to the 5 volts of Arduino Uno.
GND pin should be connected to the Arduino GND pin.
SDA pin should be connected to the Arduino Uno Analog pin A4.
SCL pin should be connected to the Arduino Uno Analog pin A5.
Arduino Uno and I2C module wiring table:
I2C Module | Arduino Uno |
VCC | 5Volts |
GND | GND |
SDA | A4 |
SCL | A5 |
|
The I2C pin table for some standard Arduino boards is given below:
Board | I2C / TWI pins |
Uno, Ethernet | A4 (SDA), A5 (SCL) |
Mega2560 | 20 (SDA), 21 (SCL) |
Leonardo | 2 (SDA), 3 (SCL) |
Due | 20 (SDA), 21 (SCL), SDA1, SCL1 |
Address of I2C Module
In I2C communication, there can be 1 master and multiple slaves. That means we can attach various I2C devices with a single I2C enabled board. The master can communicate with the slaves using an address. We can easily find the address of the connected I2C modules using a simple Arduino scratch.
The default I2C scanner example code can be found in the Arduino IDE. Go to Arduino, File, Example, Wire, i2c scanner. Or simply copy and paste the given code.
Upload the code and open the serial monitor. The default address is 0x3F. But it can be different based on the I2C modules hardware configuration.
I2C Scanner |
Library Installation for I2C LCD Display
For the I2C liquid crystal display, we will use a library called LiquidCrystal_I2C. The library includes simple functions to operate LCD displays using the I2C module. To install this library, go to Arduino IDE. Then go to sketch> Include Library> Library manager.
Arduino Library Manager |
Now, wait for the library manager to check the list of the installed library. Now on library manager, search for "LiquidCrystal I2C". From the search result, scroll down and install the "LiquidCrystal I2C" library by Marcos Schwartz.
"LiquidCrystal I2C" Arduino library by Marcos Schwartz |
Now we are ready to print something for our LCD I2C 4 wire display.
Arduino Code for I2C LCD Display
Edit the following Arduino source code according to the I2C address found before and upload.
This is the basic "Hello World" code to display 2 lines in the LCD display.
I2C LCD Display |
Post a Comment