<LiquidCrystal_I2C.h> Hello World doesn't work!

Hi,

I’m able to upload the following hello world code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,16,2);  // set the LCD address to 0x20 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd 
 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello, world!");
}

void loop()
{
}

However the only thing I get are the 16 squares on the display, they never go away! I’m using the SainSmart IIC/I2C/TWI 1602 Serial LCD Module.

Any solution? I never guessed how difficult arduino is… It shouldn’t be!

Thanks

You have specified the source of the I2C adapter you are using but you have not specified which library you are using. Unless the two are compatible you are going to get the results that you describe.

Don

In short, the default LiquidCrystal_I2C Arduino library does not work with most I2C backpacks.

It's a chronic nuisance with the Arduino project management.

Paul__B: In short, the default LiquidCrystal_I2C Arduino library does not work with most I2C backpacks.

It's a chronic nuisance with the Arduino project management.

Which library are you referring to?

Don

The regular liquid crystal library is much better for the 1602. Follow the instructions carefully on adafruit.

Use this code:

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
 LiquidCrystal lcd(7,8,9,10,11,12);

void setup() {
  // set up the LCD's number of columns and rows:
 
  lcd.begin(16, 2);
 
  //lcd.display();
  //delay(200);
  lcd.setCursor(0,1);
  delay(200);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  delay(5000);
  lcd.clear();

}

void loop() {

  // set the cursor to column 0, line 1
  lcd.display();
  //delay(200);
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

The regular liquid crystal library is much better for the 1602. . .

Not if he is using an I2C interface.

Don

Use this code: . . .

Shouldn't you explain why you are recommending that code over the traditional "Hello World" code?

In my opinion his code was better than both of the above choices since it does nothing in loop that could obscure the original message, the one that proves that the display is working.

Don

Did you check the used I2C address (0x20) with I2CScan?

My standard I2C backback uses an I2C address of 0x27.

Then he should not use the I2C interface, I got my shit to work without it.

Are you being sarcastic? It shows the number of seconds since reset, I'm done.

@ruiseixas

If you are using this display then the I2C addresses are 0x3F and 0x40, not 0x20 and not 0x27.

Try:

LiquidCrystal_I2C lcd(0x3F,20,4);

If that does not work then provide more info on your setup and a link to your display.

If you are using this display then the I2C addresses are 0x3F and 0x40, not 0x20 and not 0x27.

How can you be so sure which range of addresses is correct? Can you determine which version of the chip the manufacturer happened to put on his specific pc board on the particular day that his board was stuffed?

Also: the possible address ranges are 0x20 <–> 0x27 or 0x38 <–> 0x3F. It is not possible to have address 0x40.

Don

2trillion: Are you being sarcastic? It shows the number of seconds since reset, I'm done.

No, he was pointing out that you have either not adequately read, or not understood, the original posting.

Unless the OP understands that your contribution is irrelevant to his situation, he may become further confused as a result. :roll_eyes:

Ok, this code worked just fine:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
	// initialize the LCD
	lcd.begin();

	// Turn on the blacklight and print a message.
	lcd.backlight();
	lcd.print("Hello, world!");
}

void loop()
{
	// Do nothing here...
}

:o

Good. It looks like all that was wrong was the I2C address.

Your adapter module uses a PCF8574 chip (as opposed to a PCF8574A) and therefore must have an address in the 0x20 <–> 0x27 range. The three address lines have been pulled high by circuitry on the adapter pc board to give you the 0x27 address.

Next you can experiment by displaying a message on the second line of the display by adding a ‘set cursor’ command followed by another ‘print’ statement, both of these in setup().

After that try displaying some changing information in loop() as shown in the Arduino ‘Hello World’ tutorial.

Don