I2C LCD

Why I2C (IIC) Type LCD?

If you plan to add a simple readable interface in your next project. alphanumeric LCD may be the most preferred one due to various factors such as low cost, easily programmable, having no limitation of displaying special & even custom characters.

But to use it directly with  a microcontroller, you would need atleast 6 pins – RS, EN, D7, D6, D5, and D4 (with R/W pin permanently grounded for write operation). When you are engaged in a complex project bundled with large number of modules, you may face pin shortage for your microcontroller. In such situations, I2C LCD comes handy making use of only 2 pins (SDA & SCL) to talk to MCU, thereby saving atleast 4 pins. If you already have I2C devices, this LCD module actually uses no more pins at all.

Before moving further, lets see how an LCD can be controlled by I2C. In the image shown above, you can see a backpack module fitted to the back of the LCD. He does the work using an I/O expander PCF8574, that communicates with the micro-controller by I2C.

Remote 8-bit I/O expander PCF8574

The PCF8574 provides general purpose remote I/O expansion for most microcontroller families via the two-line bidirectional bus (I2C-bus). The device consists of an 8-bit quasi-bidirectional port and an I2C-bus interface.

A quasi-bidirectional I/O can be used as an input or output without the use of a control signal for data direction. The PCF8574 has a low current consumption and includes latched outputs with high current drive capability. It also possesses an interrupt line (INT) which can be connected to the interrupt logic of the microcontroller. By sending an interrupt signal on this line, the remote I/O can inform the microcontroller if there is incoming data on its ports without having to communicate via the I2C-bus. This means that the PCF8574 can remain a simple slave device.

I2C LCD Backpack

You can use this with LCD modules that have a HD44780-compatible interface with various screen sizes. The key is that your LCD must have the interface pads in a single row of sixteen, so it matches the pins on the backpack.

As shown in the above image, the backpack has 4 pins namely GND, Vcc, SDA and SCL.

Besides, the backpack has the following key features

  • LED jumper should be in position to turn on the back-light.

  • The blue potentiometer on the backpack bord adjusts contrast. Adjust it to a position where the characters are bright and the background does not have boxes behind the characters.

  • The three hardware address pins A0, A1 and A2 allow eight devices to be on the same I2C-bus. You can change the address of the device according to the status of each of these pins. The default address of the device is 0X3F (with PCF8574AT).

Note that backpack modules centered around PCF8574/PCF8574T (SO16 package of PCF8574 in DIP16 package) have a default slave address of 0×27. For those with PCF8574A/PCF8574AT chip, the default slave address will change to 0x3F. 

Once all the necessary connections are made, you can communicate with LCD using I2C.

Interfacing with Arduino

On Arduino UNO board, SDA (data line) is on analog pin 4, and SCL (clock line) is on analog pin 5. On the newer Arduino UNO (“R3″ layout), the SCL and SDA pins are available as separate pins. If you are using a different board, ensure that you connect the SDA and SCL pins. Power the board with 5V.  The interfacing diagram is shown below.

You can get library from here. Add the library to your Arduino folder. We used the library NewliquidCrystal_1.3.4

Note: If you are using an Arduino board that works in 3.3V level, you need to use a level converter to communicate with the backpack.

Sample code for 16×2 LCD is given below. Upload the sketch to your Arduino board and you can see the LCD working. For 20×4 LCD, use the commented setup and comment the current setup.

Resources

Shop with us