Embedded systems

Use Your LCD with I2C

In this article, weā€™ll look at how to reduce the wires used four LCD to just two!. Yes thatā€™s right, you can use two wires (excluding power/ground) to drive your LCD.

As you all know LCD and other displays enhances the HMI (Human Machine Interface) experience.Ā Assume that you are moving towards a complex micro-controller project involving blinkers, beepers, and a display panel.Ā To link a standard 16Ɨ2 LCD directly with the micro-controller, for instance Arduino, you would need at least 6 I/O pins to talk to the LCD. However, if you use an LCD module with I2C interface, you only need 2 wires to process the display information.Ā  An PCF857AT I2C moduleĀ with an I2C bus was developed by to solve the problem.

You can use them with Ā HD44780Ā compatible LCD modulesĀ interface with various screen sizes by attaching to the back of the LCD module. This allows connection to your Arduino (or other micro-controller) using only four channels. I2C bus is a type of serial bus invented by PHLLIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple-host system. I2C uses two bi-directional lines, SDA (Serial Data line) and SCL (Serial Clock line) pulled up with resistors. Typical voltage used is between 3.3V to 5V. The blue potentiometer is used to adjust the back-light.

PCF857AT I2C module to arduino circuit

Youā€™ll need the following to carry out this project

Components

  • 1 x Arduino UNO, get itĀ here
  • 1 x PCF857AT I2C module, get itĀ here
  • 1 x 16Ɨ2 LCD, get itĀ here

Software

  • Latest Arduino IDE, downloadĀ here
  • LiquidCrystal_I2C library, downloadĀ here

IMPLEMENTATION

Step 1: Circuitry

LCM1602 to arduino connection
LCM1602 to arduino connection

Step 2: Upload the code

  • Install the LiquidCrystal_I2C library in your library folder of your Arduino
  • To get the I2C address of your PCF857AT I2C module, upload the code below
#include <Wire.h>

void setup() {
Ā  Serial.begin (115200);

Ā  // Leonardo: wait for serial port to connect
Ā  while (!Serial)
Ā Ā Ā  {
Ā Ā Ā  }

Ā  Serial.println ();
Ā  Serial.println ("I2C scanner. Scanning ...");
Ā  byte count = 0;
Ā 
Ā  Wire.begin();
Ā  for (byte i = 1; i < 120; i++)
Ā  {
Ā Ā Ā  Wire.beginTransmission (i);
Ā Ā Ā  if (Wire.endTransmission () == 0)
Ā Ā Ā Ā Ā  {
Ā Ā Ā Ā Ā  Serial.print ("Found address: ");
Ā Ā Ā Ā Ā  Serial.print (i, DEC);
Ā Ā Ā Ā Ā  Serial.print (" (0x");
Ā Ā Ā Ā Ā  Serial.print (i, HEX);
Ā Ā Ā Ā Ā  Serial.println (")");
Ā Ā Ā Ā Ā  count++;
Ā Ā Ā Ā Ā  }
Ā  } // end of for loop

Ā  Serial.println ("Done.");
Ā  Serial.print ("Found ");
Ā  Serial.print (count, DEC);
Ā  Serial.println (" device(s).");
}Ā  // end of setup

void loop() {}
  • Open your Serial monitor and set the baud rate to 115200. If your I2C address isnā€™t found, switch the SDA and SCL wires of your Arduino
  • Upload the following code to write to the LCD
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

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

void setup()
{
 lcd.init(); // initialize the lcd 
 lcd.init();
 // Print a message to the LCD.
 lcd.backlight();
 lcd.setCursor(4,0);
 lcd.print("NERDSHED");
 lcd.setCursor(0,1);
 lcd.print("nerdshed.com.ng");
}

void loop()
{
}

Step 3: Result

LCM1602 Arduino result
LCM1602 Arduino result

If nothing shows up on the LCD, use a screw driver to rotate the potentiometer so as to adjust the contrast.

Letā€™s do something more useful like reading the temperature and humidity of an environment and displaying to the LCD

Wanna do more?

How about building a temperature and humidity monitoring system? Components needed are

  • DHT11 temperature and humidity sensor, get itĀ here
  • 10k ohm resistor.

Hereā€™s an article to guide you, check it out here.

Leave a Reply

Your email address will not be published. Required fields are marked *