I2C LCD Controller (the Easy Way)

457,155

156

68

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

Intro: I2C LCD Controller (the Easy Way)

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

  • Plastics Contest

    Plastics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Audio Contest 2018

    Audio Contest 2018

68 Discussions

0
None
AndraȘ6

Question 8 months ago on Step 4

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!

0
None
stevenf117

9 months ago

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.

0
None
milky0071

1 year ago

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

0
None
bkeskin

1 year ago

Does it work with 1604 as well?

0
None
wimvanasperen

1 year ago

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

0
None
MassimoB3

1 year ago

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

0
None
DennisK44

1 year ago

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

0
None
verdeljrun7

Reply 1 year ago

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

0
None
SteveA96

2 years ago

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

5 replies
0
None
verdeljSteveA96

Reply 2 years ago

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

0
None
SteveA96verdelj

Reply 2 years ago

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
0
None
teddlesrussSteveA96

Reply 2 years ago

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.

0
None
mrsyfySteveA96

Reply 2 years ago

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.

0
None
AJRSousa

1 year ago

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

Great help!!

0
None
Karanronin

1 year ago

Guys no text, only light is present. Any suggesstions

0
None
Ralphxyz

1 year ago

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