I2C LCD Controller (the Easy Way)

449,238

156

67

Published

Introduction: I2C LCD Controller (the Easy Way)

About: Master Diesel Tech, in California. I love electronics and everything science .

I am working on an alarm/weather station project and I wanted to use an LCD but dint want to have a lot of wires so I order a controller. This is just a very basic tutorial on how to hook it up, for the beginners like my self.

Step 1: Parts

Parts list:

 

 

 

1. LCD in this case a 16x02

 

1. I2C 1602 LCD Controller ($1.99 on ebay free shipping)

 

4. Jumper wires

 

1. Arduino ( I have a mega)    

 

Step 2: Soldering

Now we solder the LCD and the controller. make sure you have the correct pin arrangement. Mine doesn't have a mark for pin one, but I just looked at the 5+ and GND inputs to figure it out.

Step 3: Connecting

it is very simple to connect only 4 wire 5+ and GND and  SDA goes to Arduino pin 20 and SCL to pin 21 on my arduino mega. depending on what you have it might be different.

Step 4: The Code

Since the seller doesn't provide any info I neede to find the address for the module so I ran an I2C scanner
 //Written by Nick Gammon
// Date: 20th April 2011

#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++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Step 5: The Code Part II

the code is very simple..................................but you are going to need F Malpartida's   LCD LIB https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads Once again very basic very simple.                                                                                                                                                                                                                            
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library


#define I2C_ADDR    0x20  // Define I2C Address for controller
#define BACKLIGHT_PIN  7
#define En_pin  4
#define Rw_pin  5
#define Rs_pin  6
#define D4_pin  0
#define D5_pin  1
#define D6_pin  2
#define D7_pin  3

#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() 
{
  lcd.begin (16,2);  // initialize the lcd
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(LED_ON);
}

void loop()  
{

// Reset the display 
  lcd.clear();
  delay(1000);
  lcd.home();
 
// Print on the LCD
  lcd.backlight();  
  lcd.setCursor(0,0); 
  lcd.print("Hello, world!");
  delay(8000);
}

8 People Made This Project!

Recommendations

  • Make it Move Contest

    Make it Move Contest
  • Casting Contest

    Casting Contest
  • Clocks Contest

    Clocks Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

Hello. I am trying to see if my LCD works and after I use this code I can not see any information. Which can be the root cause? I mention that my compiling and uploading works without errors. Thank you!

67 Comments

guyss pleasee help me for this. it wont work

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\admin\Desktop\LCD\LCD.ino:1:17: fatal error: LCD.h: No such file or directory

#include <LCD.h>

^

compilation terminated.

exit status 1

Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

Not Working out for me and my Arduino Pro Mini... HELP. Cannot find LCD Address

Does it work with 1604 as well?

why using port 0 thru 6, when using the I2C interface???

Salve ma come devo fare se alla fine della scritta si accenda i led???? non ci riesco...

The code to search I2C address is awesome...Very Helpfull!

You need to install this library
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/

Two days and all I get is white boxes..
same on the Uno and Nano..
I am over it..

5 replies

We need more info what controller and what lcd are you using. It sounds to me like your backlight is out of adjustment.

The DF Robot display works fine (only tested on the Nano) with a certain program but the other thing doesn't work at all on both my Nano or Uno, just a blue led backlight and white boxes.

P1030953.JPGP1030954.JPGP1030955.JPG

How did you solve this?

I found that the white boxes were a result of the contrast control being set wrong, once I figured that out it worked for me.

send me your code and I will take a look at it for you. I am working on a four line display using the I2C and have been sending text to easy.

Really thanks!! The address are diferent!! 27 and 3F

Great help!!

Guys no text, only light is present. Any suggesstions

First thing THANKS EVERYONE FOR YOUR CONTRIBUTIONS!!

I finally got it working thanks to your help!!

markwills, it was your code that finally worked.

Now what /why are the pins defined?

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

#define BACKLIGHT 3

How would they be used?

Thanks again,

Ralph

i come alltime i try test "Hello wordl" text same, proplem lcd show only "H" letter not more and second row have "heart" not more. what have wrong at library ?