Figuring out how to control an I2C LCD unit

Hi all.

I bought a 2x16 LCD with a built-in I2C "backpack" (model MOD-0001602, from oddWires.com.)
I haven't worked with i2C before, but I'm an experienced SW developer and a pretty handy electronics tinkerer.

I expected it to come with a data-sheet, but no joy. The ONLY thing provided is a code snippet on the page for the item: https://www.oddwires.com/16x2-lcd-display-with-i2c-interface/

(This should serve as a cautionary tale for anyone else who stumbles upon oddWires when searching for components. I ordered quite a bit of stuff and NONE of it came with documentation.)

The code snippet is the following:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.begin(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("Hello, world!");
}
void loop()
{
}

That appears to use the Newliquidcrystal library, based on the include of LiquidCrystal_I2C.h.

However, the format of the first command, LiquidCrystal_I2C lcd(0x27,16,2), appears to have changed. It looks like there is an initializer that just takes the address of the device, or there is an initializer that takes the address, the backlighPin, and the backlight polarity. (I've run the i2C scanner and verified that the device is at address 0x27.)

I've tried changing that line to LiquidCrystal_I2C lcd(0x27) and the begin command to lcd.begin(16, 2).

That sends commands to the LCD, and I can see the cursor moving, but the backlight turns off.

After some trial and error, I figured out that the command LiquidCrystal_I2C lcd(0x27, 3, POSITIVE) causes the LCD backlight to light, but I'm still not able to control the LCD correctly. With that change it shows

My guess is that the default i2C control pin assignments are wrong for this model, so the backpack isn't getting the correct signals.

Has anybody else used this particular model of LCD? Failing that, is there some way to examine the board or interrogate the I2C backpack to find out how to control it? I'm not optimistic about getting support from the seller, given the dreadful information that was provided.

The LCD's PCB has markings for the pins that connect it to the "backpack", but I can't tell the pin numbers for the backpack itself.

The PCB on the LCD has markings as follows:

RS RW E D0 D1 D2 D3 D4 D5 D6 D7 A K

Most of those pinouts are self-explanatory. RS is the register select line. RW is the read/write line.

I assume E is the enable line.

D0-D7 are the data lines.

I don't know what A or K are.

Given that the sketch is Able to turn the backlight on, and with some sketches I can see the cursor moving around, and/or garbage being displayed, it seems likely that the pin assignments are correct, otherwise I don't see how the backpack would be able to send ANYTHING to the LCD.

My guess is that the register addresses on the controller are different than the defaults in the library, but I don't know enough about I2C controllers to figure it out, nor am I familiar with the Newliquidcrystal library.

Ok, I got it finally. In poking around in the Wiki for the New LiquidCrystal library, I found a section on i2C interfaces:

//this is for a unlabeled i2c LCD interface board which allows for changing its address

// addr, en,rw,rs,d4,d5,d6,d7
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // Set the LCD I2C address

Since i previously figured out that I had to set the backlight pin to pin 3, POSTIVE, I changed that to:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE)

That works. Now i'm off and running.

This is a very common problem because there are may different ways that the backpacks are wired to the LCD and the default pin mapping in the libraries is often not the same as the actual LCD.

If I may suggest that you look into the hd44780 library for I2V LCDs. That library will autodetect the I2C address and the I2C expander (backpack) to LCD pin mapping. Makes using LCDs a snap. Use the hd44780_I2Cexp class.

The library is available to install through the IDE library manager. In Library Manager choose Display for the topic and type in "hd44780" in the find box. Choose and install the hd44780 by Bill Perry.

There are many examples that come with that library and a handy diagnostic sketch to help figure out what is wrong if you have trouble.

groundFungus:
This is a very common problem because there are may different ways that the backpacks are wired to the LCD and the default pin mapping in the libraries is often not the same as the actual LCD.

If I may suggest that you look into the hd44780 library for I2V LCDs. That library will autodetect the I2C address and the I2C expander (backpack) to LCD pin mapping. Makes using LCDs a snap. Use the hd44780_I2Cexp class.

The library is available to install through the IDE library manager. In Library Manager choose Display for the topic and type in "hd44780" in the find box. Choose and install the hd44780 by Bill Perry.

There are many examples that come with that library and a handy diagnostic sketch to help figure out what is wrong if you have trouble.

Cool! Do you know how it figures out the pin mappings?

Do you know how it figures out the pin mappings?

I should, I guess, but no. It is explained in the hd44780_I2Cexp.h file, starting at line 842.