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 *