There are a number of things that can go wrong.
I suggest you run this code:
/*
** Example Arduino sketch for SainSmart I2C LCD Screen 16x2
** based on Bitbucket
** by Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal
** Modified - Ian Brennan ianbren at hotmail.com 23-10-2012 to support Tutorial posted to Arduino.cc
** Modified 24/11/15 by Alan Howlett of www.DataTechnologies.co.uk to aid in finding LCD devices on the I2C bus.
** It assumes an LCD might exist on any of the 127 valid addresses and send them a message like "I am on 0x3F".
** If you run this and can't see anything:
** 1. Have a look on Tools, Serial Monitor- do you see a message saying it was found? If not, check your wiring.
** 2. You might need to adjust the contrast screw on the back of the I2C module on your display to see anything!
** Some of this code copied from the I2C_Scanner utility that some kind anonymous person wrote. Thank you, whoever!
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 3
#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
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
// Send a message to every possible LCD display on the I2C bus
for (int address=0; address<127; address++) {
LiquidCrystal_I2C lcd(address,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
lcd.begin (20,4); //(How many columns, how many rows) in your display
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go to top left position
lcd.print("LCD on 0x");
lcd.print(address, HEX);
lcd.setCursor(0,1);
lcd.print("0x");
lcd.print(address, HEX);
lcd.print(" LCD address");
Wire.beginTransmission(address); //Now check the I2C bus communications
// Wire.write("fred");
int error = Wire.endTransmission(); //Get the error code, if any.
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
Serial.println("--------------------------------------------------------");
Serial.println("");
digitalWrite(13,LOW);
delay(500);
digitalWrite(13,HIGH);
delay(500);
}
- You should be able to see on the serial port whether it has found an I2C device, and
- If you adjust the contrast on the LCD display (essential!) you should see the address of the display on the display. Always check the contrast- you usually can't see anything useful until it's adjusted.
- Write the I2C address on the back of the display with a permanent marker so you won't forget it!