Mega and LiquidCrystal_I2C, only works with a single display unless I call setClock

Why did my 4th I2C build failed (and why setClock fixed it)?

Controller: Arduino Mega 2560 (Elegoo revision).

Peripherals: Dual 20x4 LCDs with I2C backpacks.

The Issue: I2C scanner would find both addresses, but the second display would be all square blocks text.

The "Magic Fix":

I dropped the I2C clock speed from the default 100 kHz to 10 kHz using Wire.setClock(10000);. Instantly, the "missing" display became stable and started rendering text perfectly.

The Theory:

We suspect the newer Mega boards or different batches of LCD backpacks have different electrical tolerances?

Questions for the Experts:

1. Which Library? I am currently using LiquidCrystal_I2C. Is there a more robust library (like hd44780 by Bill Perry) that handles bus errors or timing more gracefully?

2. Why the 4th build? My first three builds worked at the default speed. Just the luck of the draw with component tolerances?

3. The "Correct" Path: Is running at 10 kHz a valid long-term solution, or am I just masking a hardware failure that will bite me?

I heard that hd44780 Library wastes memory, is that true??

You may try my library if you have time.

wrt to your questions, my answers

  1. hd44780 is a super library which has also some debug facilities. I would definitely advise to try it at least as tool to analyze the problem.
  2. unknown until better analysis find the root cause.
  3. 10kHz can be a valid solution, but I would only go that low if I had real long wires.
    100kHz should just work.

other advice:

  • check wires / soldering.
  • swap the two displays and see how problem behaves.

If the "I2C backpack" has a potentiometer, adjust it.

Here is what Google says

I jumped in and changed the code to the hd library. That fixed the displays without slowing the clock. :slight_smile:

@robtillaart - What does your library take care to do right, that other libraries do not? Thank you for providing your work.

I do not claim it is better, on contrary, the HD44780 is I think the best library and
LiquidCrystal_I2C has features that the mine has not.

My lib has a different implementation (thus different timing) and if it works where LiquidCrystal_I2C failed it could point to a timing or implementation issue.

how is the wiring done and how long are the wires from Arduino - displayA - displayB ... may be you could also make some pictures.

Mine did okay with this:



#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set for 2 displays with 4 rows of 20 columns
LiquidCrystal_I2C lcd1(0x27,20,4);
LiquidCrystal_I2C lcd2(0x26,20,4);

void setup() {

lcd1.init();
lcd2.init();
lcd1.backlight();
lcd2.backlight();

lcd1.clear();
lcd1.setCursor(0,0);
lcd1.print("LCD 1");

lcd2.clear();
lcd2.setCursor(0,0);
lcd2.print("LCD 2");
}

void loop() {

}



We thought the HD44780 library fixed it but when we installed it into the case, the screens flaked out again.

This time, I knew the code couldn't be to blame. The new library is so much nicer and made the screen renders smoother.

The wires that come with those screens aren't the best, so we made our own and sure enough, the screens worked reliably now. We did about an hour of testing and perfect rendering. :slight_smile:

The cheapo wires are a common fault, this thread has the same issue: I2C LCD does not showing text - #51 by bperrybap