bperrybap:
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
Yep, apart from the disparity between the comment and the constructor, that is the right constructor for the "LCM1602" - in contrast to the mjkdz where it is:
#define lcdAddr 0x20 // set the address of the I2C device the LCD is connected to
// create an lcd instance with correct constructor for how the lcd is wired to the I2C chip
LiquidCrystal_I2C lcd(lcdAddr, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY
Got me up and going just fine. 8)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define lcdAddr 0x27 // set the address of the I2C device the LCD is connected to
// create an lcd instance with correct constructor for how the lcd is wired to the I2C chip
LiquidCrystal_I2C lcd(lcdAddr, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // addr, EN, RW, RS, D4, D5, D6, D7, Backlight, POLARITY
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{ 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
{ 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
{ 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
{ 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
{ 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
{ 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
{ 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
{ 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
};
void setup()
{
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
lcd.begin(16,2); // initialize the lcd as 20x4 (16,2 for 16x2)
lcd.setBacklight(1); // switch on the backlight
for ( int i = 0; i < charBitmapSize; i++ )
{
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
}
lcd.home (); // go home to character 0 on line 0 (1st line)
lcd.print("Hello, ARDUINO ");
lcd.setCursor(0,1); // character 0 on line 1 (2nd line)
lcd.print (" FORUM - fm ");
/*
lcd.setCursor(0,2); // character 0 on line 2 (3rd line)
lcd.print("This is line 2");
lcd.setCursor(0,3); // character 0 on line 3 (4th line)
lcd.print("This is line 3");
*/
delay(4000);
}
void loop()
{
lcd.clear();
lcd.home ();
// Do a little animation by writing to the same location
for ( int i = 0; i < 2; i++ )
{
for ( int j = 0; j < 16; j++ )
{
lcd.print (char(random(7)));
}
lcd.setCursor ( 0, 1 );
}
delay (200);
}