Interface I2C 16×2 LCD with Arduino Uno (Just 4 wires) GPL3+
Interface a 16×2 Liquid Crystal Display with Arduino Uno. Here we just use 4 wires.
- 80,627 views
- 15 comments
- 32 respects
Components and supplies
Apps and online services
About this project
Interface I2C 16×2 LCD with Arduino Uno
In this article I am going to interface a 16×2 I2C LCD with Arduino Uno. In my previous article is discuss about interfacing of 16×2 LCD with Arduino Uno . The difference is in number of wires. There we need more than 12 wires. But here only use just 4 wires. How . Before I use parallel communication method for interfacing LCD with Arduino. But now I am using I2C Communication.
Here I use the same 16X2 LCD in my previous article. But additionally attach a I2C Module to the 16×2 LCD. It work as an inter mediator between the LCD and MCU (here Arduino).
Before starting you must know about I2C Serial Interface Adapter (I2C Module) , I2C communication , and Addressof I2C LCD
I2C is short for Inter-IC. And it is a type of BUS. This is designed by Philips semiconductors. I2C is a synchronous, multi slave, multi master packet switched, single-ended serial bus. ie. multiple chips can be connect to the same bus.I2C uses only two bidirectional open collector or open drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V, although systems with other voltages are permitted. For more about I2C protocol click here .
I2C Serial Interface Adapter
It is also known as I2C Module. It has total of 20 male pins. 16 pins are faced to rear side and 4 pins faced towards front side. The 16 pins for connect to 16×2 LCD and the 2 pins out of 4 pins are SDA and SCL. SDA is the serial data pin and SCL is the clock pin. The rest 2 pins for power supply (Vcc and ground).There is a POT on the I2C Module. We can control the contrast of the LCD display by rotating this POT. And there is a jumber fixed on the module. When we remove the jumber, the backlight of the LCD display will go OFF.
Address of I2C LCD
Before starting we need to know about addressing of I2C devices. Every device which can attached to MCU have an address. We need to know this address for communicate with that particular device.
You can see three solder pads on the I2C module. which is labeled as A0, A1 and A2. This is Address selectors. ie, each solder pads have one upper potion and a one lower potion. if, there is a connection between upper potion with lower connection it is called " Connected " otherwise it is called " Not connected ". When A0, A1, A2 are in "Not Connected" condition ( A0 = 0, A1 = 0, A2 = 0) the address would be 0x27. In default the A0, A1, A2 are in "Not connected" condition. And some time default address is 0x3F. There is no need to change the address of the I2C module when we use only one LCD. But when we use more than one LCD, need to change the address. Because two or more different device can’t communicate with the same address. For more address see the table given below.
In some cases A0, A1, A2 are "Not connected" state, but the address is not 0x27. We can’t communicate with this address. So we need to find the original address of that device. For that we need to run the Arduino with "I2C Scanner" code.
I2C Scanner Code
I2C Scanner code is used for find the number of I2C devices and address of I2C devices. First add the header file for include "Wire.h" library. Then in setup part, begin the "Wire" library by "Wire.begin()". Then begin the serial monitor as the baud rate of 9600 by "Serial.begin()". Next in loop part, define two variables with the datatype "byte" named "error" and "address". Then define another variable with the "Integer ( int)" datatype named as "Devices". And set initial value as 0. Next start a for loop with minimum value of 1 and maximum of 127. "address" used as loop variable. Next input the address to wire with the function "Wire.beginTransmission()". The i2c_scanner uses the return value of the "Write.endTransmisstion()" to see if a device did acknowledge to the address. This return value store the value to the variable "error". The return value become 0, if a device acknowledge to the address. Otherwise, the return value become 4. Next use a if. And the condition is "error==0". Then print the particular address to the serial monitor only if the address16. Here we print the address in Hexadecimal. The printing instruction is "Serial.print(address, HEX)". And count the Device. The complete I2C Scanner code is given below
Upload the I2C Scanner Code to Arduino Uno.
If you have a I2C LCD please skip this step. But if you have a 16×2 LCD and a I2C Module see the step to connect this module to LCD.
First solder the I2C Module. There is no label on the I2C Module for connecting to 16×2 LCD. So solder it with the help of the image given below