20x4 LCD with I2C backpack
Testing a 20x4 LCD - for use in future control panel
I recently bought a 2004 LCD with an I2C backpack and my initial test to check it was working had just the back-light blinking but no text. I'd only used the ones with the parallel interface before so I tried different I2C addresses but was clearly missing something. Some Googling indicated I may have the wrong library. After running an I2C scanner to confirm the address and making some tweaks to the example code it lit up with text, success!
My test code is a slightly modified version of John Boxall's found here:
/* Demonstration sketch for PCF8574T I2C LCD Backpack
Uses library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads GNU General Public License, version 3 (GPL-3.0) */
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // 0x27 is the I2C bus address for an unmodified backpack
void setup()
{
// activate LCD module
lcd.begin (20, 4); // for 16 x 2 LCD module
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
}
void loop()
{
lcd.home (); // set cursor to 0,0
lcd.print("2004 I2C LCD test");
lcd.setCursor (0, 1); // go to start of 2nd line
lcd.print("Count: ");
lcd.setCursor (6, 1); //
lcd.print(millis());
delay(1000);
lcd.setCursor (0, 2); //
lcd.print("Line 3...?");
lcd.setCursor (0, 3); //
lcd.print("Line 4...?");
lcd.setBacklight(LOW); // Backlight off
delay(500);
lcd.setBacklight(HIGH); // Backlight on
delay(1000);
}
Comments
Post a Comment