Hello, I'm a mechanical engineering student and I'm making a project for an exam.
I would separately use the two displays (both displays are equipped with a LCM1602 module).
I shorted-circuit the A0 pin so as to change the base address of the second LCD display.
I used the following code :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x26, 16, 2);
LiquidCrystal_I2C lcd2 (0x27, 16, 2);
void setup()
{
lcd.begin (16,2); // initializza primo LCD
lcd2.begin (16,2); // initialize secondo LCD
}
void loop()
{
lcd.setCursor(0,1);
lcd.print("1");
lcd2.setCursor(0,1);
lcd2.print("2");
delay(2000);
}
Result : the first display correctly functions, instead the second display only lights up.
Thanks for your help
It could be a couple of things.
You haven't fully describe the non working display. It could be the contrast pot not properly adjusted.
It could be that the non working device is not at the address you think it is.
Setting the jumper does change the address but it does not alter the base address.
These backpacks can use two different chips and each one has a different base address.
One has a base address of 0x20 and the other has a base address of 0x38
The 3 jumpers configure the lower 3 bits of the address.
It could be that the pin mapping of the non working device is different than the working device.
Not all backpacks use the same pin mapping between the PCF8574 chip and the LCD.
The library you are using picked one mapping and hard coded it.
If the device you have does not use that pin mapping it will not work.
If that is the case, while you go alter the code to match the mapping on the device, if you have two devices with different mappings, there is no way to use that library.
My recommendation is to use the hd44780 library and the hd44780_I2Cexp i/o class.
It works with any pin mapping and can auto detect the pin mappings.
It also includes a diagnostic sketch, I2CexpDiag to test the i2c signals and the LCD h/w.
I would recommend installing the hd44780 library and running the diagnostic sketch to test your devices.
You can run it with both devices attached. It will test them both at the same time and report the i2c addresses and pin mappings used on the LCD and serial port.
I'd also recommend switching to the hd44780 library and the hd44780_I2Cexp i/o class.
the hd44780 library is faster and some additional capabilities.
It can be installed easily directly from the IDE using the library manager.|
It provides a LiquidCrystal and LCD 1.0 API, comes with many examples, and extensive documentation.
Here is a link to the github page:
But don't install it from there using a zip file - this is noted in the installation instructions.
--- bill
Thank you so much bperrybap, I will try to do what you recommended.
Interesting ...
... I am trying the same thing, except that I am using one 16x2 and one 20x4. They both work individually but never together. Like Lorenzo I am using addresses 0x26 and 0x27 (confrmed by the address utility).
Both LCDs use the same model Backpack (an MH with the same PCF8574T chip).
When I use the following instantiations:
LiquidCrystal_I2C lcd1 (0x27, 16, 2); // MH BackPack Addr. 0x27. 16 x 2
LiquidCrystal_I2C lcd2 (0x26, 20, 4); // MH BackPack Addr. 0x26. 20 x 4
only the first ever becomes active. If I swap them around once again the first is active. Thus, as stated above, they work individually but never together.
I think it may be that the LiquidCrystal_I2C library is a "singleton" provisor - thus supporting only one LCD - I read this somewhere. I am using the johnrickman LiquidCrystal_I2C library (github). I know that there are others. I may be right in thinking that you, Bill, have actually written an LCD I2C library? Is it a singleton provider or multiple?
As an aside, if, instead of the lcd (ADDR,COLS,LINES) parameters, I decide to use an instantiation which declares the pin numbers, how can I find exectly which pins are used? Will all PCF8574T based Backpacks from a given manufacturer use the same pins?
Thanks so much!
Kenneth Spencer
if you check the examples, you will see that you miss the lcd.init() in your sketch.
This sketch works with the original library:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x3F, 20, 4);
LiquidCrystal_I2C lcd2 (0x3E, 16, 2);
void setup()
{
lcd.init (); // initializza primo LCD
lcd2.init (); // initialize secondo LCD
}
void loop()
{
lcd.setCursor(0, 3);
lcd.print("1 ");
lcd.print(millis() / 1000);
lcd2.setCursor(0, 1);
lcd2.print("2 ");
lcd2.print(millis() / 1000);
delay(2000);
}
I'm still not happy with this solution as both init() call the Wire.begin().
If you want to avoid that, use another library, e.g. my i2c lcd library with extended utf8-support
but again, see the examples, because mine will need the Wire.begin() in the setup().
The recent version(s) of LiquidCrystal_I2C added a begin() function to try make it compatible with the LiquidCrystal API.
However, it wasn't done correctly so init() still must be called.
There is no point to calling begin() with that library since the parameters were specified in the constructor and calling it without first calling init() will not work. AND.... init() calls begin()
Again, I would recommend switching over to using the hd44780 library instead.
--- bill
The "LiquidCrystal_I2C" library and i/o class is a mess. It has a long history going back nearly 10 years.
The one currently in the IDE library manager is coming from GitHub - johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays
But that repo no longer exists and is forwarded to GitHub - johnrickman/LiquidCrystal_I2C: LiquidCrystal Arduino library for the DFRobot I2C LCD displays by github.
How that happened:
Marco just grabbed the code several years back and created a github spot for it when the IDE added the library manager.
Marco was not capable of supporting it so he asked for someone else to take it over.
johnrickman offered and so Marco transfered the repository to johnrickman.
johnrickman now seems to have abandoned the github repository and has recently created a new repository on gitlab
However, he has recently illegally re-licensed the code from LGPL 2.1+ to MIT which not allowed under the LGPL licensing terms.
I've notified him of this copyright violation and asked him to change the license file back to LGPL 2.1+
https://gitlab.com/tandembyte/LCD_I2C/-/issues/39
Prior to LiquidCrystal_I2C existing in the IDE library manager, there were many copies of this library that were being hosted all over the place and many still are today.
Also, I had been working with fm on the NewLiquidCrystal library i/o classes for a couple of years including on the "LiquidCrystal_I2C" i/o class in that library. While I was fully capable of taking over and supporting the "LiquidCrystal_I2C" library, I didn't want to do it as I was looking at doing another library that would be easier to install and easier to use.
That is how the hd44780 library came into existence.
It is essentially an easier to install easier to use "NewLiquidCrystal" library. It can be installed using the IDE library manager, does not conflict with other libraries.
I also focused on making LCDs with i2c backpacks much easier to use.
For LCDs using i2c backpacks, the hd44780 library can auto discover the address and self configure the pin mappings offering a "it just works" solution.
noiasaca, many thanks. I have no idea why your code should work but it did! The only difference between yours and mine was that the first device was just lcd, and the second was lcd2. I had tried lcd + lcd1, and lcd1 + lcd2, but never lcd + lcd2.
However, I did need to add two lines to your setup, to turn the backlight on:
void setup()
{
lcd.init (); // initializza primo LCD
lcd2.init (); // initialize secondo LCD
lcd.backlight();
lcd2.backlight();
}
So problem solved! Now to go back to my project code and try it in that!
So Noiasca, if you are ever in Wiltshire (England) and Bill, I'll buy you a pint (Lockdown rules permitting!).
Best wishes,
Ken
kaspencer:
So Noiasca, if you are ever in Wiltshire (England) and Bill, I'll buy you a pint (Lockdown rules permitting!).
I appreciate that kind of offers 