User Manual

3/6/2018 I2C LCD2004 - Wiki
http://wiki.sunfounder.cc/index.php?title=I2C_LCD2004 4/5
Read I2C Address
If everything is correct,But the display just shows 16 black rectangles on Line 1.it may be the address of i2c is not 0x27,therfore you need to run the following code to read the
address,then modify the 0x27 to which you read.
LiquidCrystal_I2C lcd(0x27,16,2);
/*****************************************************
* name:I2C_Address
* function:read the address of the I2C lcd1602
* Connection:
* I2C UNO
* GND GND
* VCC 5V
* SDA A4(pin20 in mega2560)
* SCL A5(pin21 in mega2560)
********************************************************/
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;