I recently bought an I2C LCD screen module (Ref 1602A), and I can't get it to display anything when I connect it to my Arduino Mega 2560. Here's what I did so far:
Then I figured I would run a very simple sketch to check only the display:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(2,0); //Set cursor to character 2 on line 0
lcd.print("it works");
lcd.setCursor(2,1); //Move cursor to character 2 on line 1
lcd.print("or not...");
}
void loop() {
}
When I load this sketch, the LCD backlight is ON, but nothing is displayed on the screen...
I read various topics on forums and online resources, but I can't find what I'm doing wrong here, so - the question is:
"Am I even dumber than I already know I am, or is my LCD defective?"
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Do you see a potentiometer anywhere in your setup? There should be one on the I2C backpack. When your program is running in the Arduino, adjust the potentiometer, see if your problem is just contrast.
wrong I2C-adress: run the I2C-Scanner to determine the I2C-adress
wrong adjusted contrast: most LCDs have a small potentiometer for adjusting the contrast
Post datasheet and pictures of both sides of your lcd
you can check If it is just a contrast-problem with this code
which switches the backlight on/off every second
If the backlight does go on/off I2C-communication is working and it is very likely wrong adjusted contrast
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
unsigned long MyTestTimer = 0; // Timer-variables MUST be of type unsigned long
boolean OnOff = true;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
// Print a message on both lines of the LCD.
lcd.setCursor(2, 0); //Set cursor to character 2 on line 0
lcd.print("it works");
lcd.setCursor(2, 1); //Move cursor to character 2 on line 1
lcd.print("or not...");// easy to use helper-function for non-blocking timing
}
void loop() {
// check if 1005 milliseconds have passed by
if ( TimePeriodIsOver(MyTestTimer, 1005) ) {
// if REALLY 1005 milliseconds have passed by
// automatically update variable MyTestTimer
if ( OnOff ) {
lcd.noBacklight();
OnOff = false;
}
else {
lcd.backlight();
OnOff = true;
}
}
}
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
Thanks for the hint, as soon as I get back home, I'll give it a try (there's indeed a pot at the back of the I2C module, but I didn't think about it, considering it's brand new and it would be a bad idea to ship such displays with the contast set to zero...