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!
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.
#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);
}
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.
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.
#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...
}
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.