LCD library confusion (I2C)

Am attempting to get LCD display working under I2C with diy adapter using PCF8574.

However, there seem to be so many libraries kicking around that it is not at all clear what is the present state of play. What and where is the latest and greatest?

I am trying to clear out the libraries I have downloaded at present - for example NewLiquidCrystal where I found there were posts referring to it in 2011!

I have removed the one that comes with the Arduino IDE install as it relies on 4 data bits + control directly into the LCD. and have read that the compiler can become confused if more than one exists using the same functions.

The trouble with the internet is that no one is clearing up the mess we leave behind.

waljoh:
Am attempting to get LCD display working under I2C with diy adapter using PCF8574.

However, there seem to be so many libraries kicking around that it is not at all clear what is the present state of play. What and where is the latest and greatest?

Ask the expert - bperrybap.

See this recent post.

waljoh:
The trouble with the internet is that no one is clearing up the mess we leave behind.

The Internet reflects society. Need I say more?

I use this library and the following codes to check my I2CLCD.

#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);  //if 0x27 does not work; try with 0x3F or run address scanner

void setup()
{
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello..!");
}

void loop()
{

}

Yes there are many libraries out there for a PCF8574 backpack with a LiquidCrystal_I2C class and several of them are named LiquidCrystal_I2C but they work differently which makes things quite confusing.

A bit on a few of them:

  • NewLiquidCrystal can be made to work with any PCF8574 based backpack if you fill in its LiquidCrystal_I2C object parameters correctly. It must be manually installed properly which can be tricky since it is designed to replace the bundled IDE LiquidCrystal library.

  • The LiquidCrystal_I2C library is available in the IDE library mananger so it is easy to install, but it may or may not work with your backpack even if you get the i2c address parameter correct as there are several different pin wirings and that library hard codes the pin wiring and it may not match the wiring used on your backpack.

  • I would avoid GolamMostafa's recommendation as it is just a snapshot of the LiquidCrystal_I2C library and who knows if it is ever maintained.

I would recommend the hd44780 library and use the hd44780_I2Cexp i/o class.
It is much easier to use than the others. It can be installed using the library manager and will auto detect all the needed configuration parameters including the i2c address. It does not conflict with other LCD libraries.
It includes documentation that can be viewed from the IDE once the library is installed.
You can also read more about it on the github page and wiki:

Once installed you should run the I2CexpDIag sketch first to verify that the library and lcd device are properly working.

--- bill

waljoh:
The trouble with the internet is that no one is clearing up the mess we leave behind.

But unlike in the physical world, you can use google to filter search results to ignore all old "garbage".
i.e. do a search like this:
site:arduino.cc ic2 lcd

Then use the "Tools" menu under the search bar to select your date range.
In this case "Past year" will get you lots of useful results.

--- bill

Hi Bill,

Soon after posting my post, I found one of yours referring to the hd44780, and have gone down that route. I have to congratulate you on delivering something that is structured and documented extremely well. Thank you for your efforts.

Unfortunately for me, it has rapidly shown that I have a problem: I am getting error codes flashing on the led, and the terminal is telling me that although the expander is there, there is no working LCD attached. It also tells me I need some pullups.

The only issue I have is that the status() returns differing flash numbers in different contexts, I have seen 2, 3, and 4 (I think as they are rapid), and I haven't found any documentation yet on their possible signifcance.

So I have on order another LCD, and a properly built (I hope) expander backpack. That way I hope to discover whether it is my circuitry or the LCD at fault.

My circuitry provides for control of the backlight, that my current display does not support, but I cannot imagine that this is preventing the device from responding. In fact the 'LCD' is an OLED display (Midas MCOB21605G1V-EGP), but the interface appears to be identical.

Briefly yesterday I had heiroglyphics displayed on the OLED, the first two or three of which were responding to the sketch, but otherwise it has been stubbornly dark. At that time I had at least three different libraries loaded, (thoroughly confuusing to me and to the compiler) after which I embarked on a purge.

Thanks very much again,

John

waljoh:
. . .
I am trying to clear out the libraries I have downloaded at present - for example NewLiquidCrystal where I found there were posts referring to it in 2011!
. . .

I remember asking the author (FM) about what he was going to name any follow-up program. I don't recall his response.

Don

Don, I read that.. it is still the New one

Bill,

Where can I get some info to shed light on the mapping of PCF8574 to the LCD? In my naivety I thought these would be conistent and pre-ordained.

I have spent a happy two or three hours downloading libraries to try. At one time I was repetitively writing to the LCD and getting strange characters appearing on the screen. I used our friend aboves code as a basis, but having moved on have been unable to reproduce that.

hmario's libraries (he has a new one and an old one) which were invoked in the 'Instructable' on which I based my wiring did nothing for me.

But I now understand that there are a lot of variables.. hence the value of your code. However, I did find one library/example that claimed to have found the LCD.

Maybe all is not yet lost!

John

waljoh:
Where can I get some info to shed light on the mapping of PCF8574 to the LCD?
In my naivety I thought these would be conistent and pre-ordained.

I've seen around a half a dozen ways that the PCF8574 pins on i2c backpacks are wired up to the LCD.
There are two ways that the data pins are typically wired up but if you look at all the combinations of data and control pin wiring and backlight control circuitry, you get around 6 different ways that I've seen used on backpacks available on ebay.

To know which you have, you have to look at the backpack to see how the PCF8574 pins are wired up to the LCD pins.
You may have to use an ohm meter in some cases as the PCB traces may go underneath the PCF8574.
And then look at the backlight circuity to see if it uses a NPN or PNP transistor and how it is wired up to the A and K LCD pins.

I have spent a happy two or three hours downloading libraries to try.

No point in trying anything else until the diagnostics in I2CexpDiag pass.
What did the diagnostic sketch report?

--- bill

wait....
I just noticed that it sounds like you may be using/building a DIY i2c backpack/adapter.
If you are wiring up the pins yourself, here is how you want to wire up the pins for best compatibility:
P0 RS
P1 RW
P2 EN
P4 DB4
P5 DB5
P6 DB6
P7 DB7
P3 Backlight circuitry (HIGH signal enables backlight using a simple NPN transistor)

This will give you a wiring that can be autodetected by hd44780_I2Cexp and will work with the LiquidCrystal_I2C library available in the IDE library manager.

PCF8574 P3 pin should connect to the based of a NPN transistor.
No current limiting resistor is needed between the P3 pin and the base of the transistor as the PCF8574 does not have drive capability and uses an internal pullup for the HIGH signals.
Collector will sink the current from the Cathode of the LED backlight.

I'd use a i2c backpack rather than make something. They are about $1USD shipped from various ebay vendors.

--- bill

waljoh:
My circuitry provides for control of the backlight, that my current display does not support, but I cannot imagine that this is preventing the device from responding. In fact the 'LCD' is an OLED display (Midas MCOB21605G1V-EGP), but the interface appears to be identical.

Is this of relevance, Bill?

Paul__B:
Is this of relevance, Bill?

Relevant, yes, but should it shouldn't keep things from working.
From looking at the data sheet for the OLED lcd, the typical hd44780 pins vo, A, and K are not connected.

The PCF8574 BL pin would try to control the backlight circuit which would try to control a backlight but would do nothing.
The other pins appear to work the same (other than there is contrast control).

hd44780_I2Cexp would auto detect a backlight polarity and try to control the backlight but since there is no backlight control, nothing would happen.

I think the most useful information at this point would be the output from the I2CexpDiag, and a photo of diy adapter to see how it is wired up to the LCD.

--- bill

Hi Bill, and others

Thanks very much for all the time taken, advice and support. Much appreciated. I think I am now out of the wood, although I think my stripboard PCB is not engineered to the most reliable standard.

I found today on Wikispaces (before reading your more recent posts above) a circuit diagram that was a lot clearer than the fuzzy printout from the Instructables web page I was working to. As a result, I reconfigured RS and EN and in the process found that I had somehow got the collector of the backlight control transistor tied up with EN, explaining my previous problems.

I had not appreciated that the mapping was fairly arbitrary, giving rise to different backpacks and configuration difficulties.

My final mapping is I think completely different to the one you suggested above, but according to Wickispaces is compatible with NewLiquidCrystal. Anyway, your autodetection has worked admirably, and I have a working OLED display.

There was a document on the PCF8574 that I have not had time to absorb, but which may prove useful to others, along with the circuit diagram. This includes the pull up resistors, and the backlight control (I changed the resistor values as I thought the base feed was a bit low), although with the OLED neither this nor the contrast have any bearing. I have attached these.

The Wickspaces page seems a useful contribution, but their service is being withdrawn imminently.

Thank you again,

John

Ic2-BackPackSchematic-1.jpg

PCF8574_PCF8574A-842013.pdf (816 KB)

waljoh:
My final mapping is I think completely different to the one you suggested above, but according to Wickispaces is compatible with NewLiquidCrystal. Anyway, your autodetection has worked admirably, and I have a working OLED display.

The wiring you show in the schematic is another of the more popular backpack wirings that is used.
It uses the lower nibble for the LCD data pins vs the upper nibble.
NewLiquidCrystal can work with any mapping/wiring as long as the constructor matches the wiring.
hd44780 can figure out the wiring of all the backpacks i’ve seen used on pre-made backpacks.
The wiring I recommend is what the LiquidCrystal_I2C library expects which means that wiring can work with all 3 libraries which is why I recommend that wiring.

There was a document on the PCF8574 that I have not had time to absorb, but which may prove useful to others, along with the circuit diagram. This includes the pull up resistors, and the backlight control (I changed the resistor values as I thought the base feed was a bit low), although with the OLED neither this nor the contrast have any bearing. I have attached these.

You will want to carefully look at how the Quasi-bidirectional I/Os actually work.
The datasheet really doesn’t properly describe it but you can tell how it really works by looking at table 9 “Static characteristics”
Compare VOL to VOH. note how low VOH is vs VOL. (ma vs ua)
What this really means is that the part never drives the pin HIGH.
i.e. It can sink current but cannot source it.

When you set the bit in the port register to a 1 it connects the pin to an internal pullup vs driving it high.
For low it connects the pin to an internal ground.

The practical implications means you can not drive any thing like an LED with the HIGH output signal, but you can turn on LED (up to 3ma) with a low signal that sinks current from the cathode.

So when driving a transistor, you need a current limiting resistor when using a PNP transistor but you don’t need the resistor between the PCF8574 pin and the base of an NPN transistor as the high signal from the PCF8574 is already extremely currently limited since it is just a pullup.

If using a NPN transistor the transistor will be on when the PCF8574 powers up as the pin will be in input mode which is really a pullup resistor to vcc.
If using a PNP transistor the transistor will off when the PCF8574 powers up as the PNP transistor needs a low signal to activate.

This means that if using a PNP transistor the library has to be correctly initialized correctly before the backlight will be turned on.

But it seems pretty difficult to build a DIY adapter cheaper than the cost you can get a premade one shipped to your door.

— bill