loading

Most of the projects needs an LCD display for viewing a number of parameter values. While you are doing a project with a microcontroller, you have to interface a common LCD display(2x16) using parallel interface which needs a total of 11 pins of controller to be used. 8 line are for 8bit data and three control lines namely RS, W/R and E. one solution is to write code for a 4bit interfacing using only four data line which may indeed reduces four data line but it is having heavy coding. While using an Arduino board you can interface an LCD pretty simply by 4bit using the "LiquidCrystal.h" library. Using this library, you only needed to specify the data pins and mode of operation(16x1 or 16x2 or 16x4 etc). But it still need four line for interfacing. In this simple project I am explaining how to interface an LCD(16x2) module with only two wires which take only two pins of you Arduino board.

Step 1: The Protocol

In order to interface the LCD using only Two pins, we must need a serial communication, but we can not use USART or I2C / TWI directly because it is not supported by the LCD module like a one shown in the picture. But we can send serial data from Arduino to a serial to parallel converter ic which in turns converts the serial data from Arduino in to 8bit parallel line and connect to the LCD. We can use USART or I2C / TWI protocol for this purpose but note that the protocol which you are using for sending serial data must be supported by your serial to parallel converter ic. So now we need to find out a serial to parallel converter ic which support one of this protocol. Please note the following two points.

1. If you converter ic supports USART(USART to Parallel), you can only connect one LCD module.

2. If you converter ic supports I2C / TWI, you can connect more than one LCD module and also another devices which supports I2C / TWI on the same two line because in this protocol you can set unique address for each device.

So it is better to use one which having I2C / TWI protocol. Philips has got an ic named PCF8574AT

Step 2: PCF8574AT Remote 8-bit I/O Expander for I2C-bus

PCF8574AT converts I2C-bus serial data into 8bit parallel data suitable for connecting an LCD. By observing the pin diagram, SDA and ACL are I2C-bus line through which the data coming in to the ic and P0 to P7 are the parallel 8bit output which is connected to the 8bit input lines of the LCD.

Step 3: Setting Address for PCF8574AT

the fist four bits of the address register are fixed. the bits named A0,A1,A2 are user defined bits. so there will be 2^3=8 address are possible, so you can use a maximum of 8ics in line. For setting the address of your LCD, change A0,A1,A2 values. for example if these values are 0 (A0=0,A1=0,A2=0), then the address is 20 in hexadecimal. if these values are 1 (A0=1,A1=1,A2=1), then the address is 2E in hexadecimal. You can wire the ic with LCD or you can buy a an interface board that will be explained in the next step.

Step 4: I2C Interface LCD Module

An I2C interface LCD module is shown in the figure which is having the ic PCF8574AT. the default address for this module is 27 in hex. Use this address by default or you can change if you are using more than one module by setting A0 A1 A2 pins.

Step 5: Arduino Code

Before coding in Arduino, you need LiquidCrystal_I2C library .

#include <LiquidCrystal_I2C.h>

#include<Wire.h>

LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display


void setup()

{

lcd.init(); // initialize the lcd

lcd.backlight(); //Turn on back light

lcd.setCursor(0,0); //cursor position

lcd.print("A"); // print A

LCD_string_write("HELLO"); // for printing a word (string)use this

}

void loop()
{ }


void LCD_string_write(const char *value)
{

int i=0;

while(value[i]!='\0')

{

lcd.print(value[i]); // sending data on CD byte by byte

i++;

}

}

<p>Interesting trick. Thanks for sharing the info.</p>

About This Instructable

762views

18favorites

License:

More by sreejeesh:Two Wire Interfacing of LCD With Arduino Nano 
Add instructable to: