Introduction: 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);
}
68 Comments
Question 5 years 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!
5 years 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.
6 years ago
Not Working out for me and my Arduino Pro Mini... HELP. Cannot find LCD Address
6 years ago
Does it work with 1604 as well?
6 years ago
why using port 0 thru 6, when using the I2C interface???
6 years ago
Salve ma come devo fare se alla fine della scritta si accenda i led???? non ci riesco...
6 years ago
The code to search I2C address is awesome...Very Helpfull!
6 years ago
were can you find the LCD.H Library
Reply 6 years ago
You need to install this library
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
Reply 6 years ago
good question
6 years ago
check this site https://arduino-info.wikispaces.com/LCD-Blue-I2C?r...
having lot of info on these I2C devices. I2C ADDRESS SCANNER is a cool one, you can find the address of your display with this
7 years ago
Two days and all I get is white boxes..
same on the Uno and Nano..
I am over it..
Reply 7 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.
Reply 7 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.
Reply 6 years ago
How did you solve this?
Reply 7 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.
Reply 7 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.
6 years ago
Really thanks!! The address are diferent!! 27 and 3F
Great help!!
6 years ago
Guys no text, only light is present. Any suggesstions
6 years 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