[SOLVED] All LCDs stoppet working

Hello,
Seems like I have got a software issue. All my LCDs has stopped working and I suspect that there is a software issue that cause this.

Uploaded the same sketch to a controller with a working LCD - after upload the LCD behaved strange.

The LCDs backlight is blinking and only garbage is printed on the screen.

Suggestions how to solve this?

Test code:

#include <MyLcd_I2C.h>

// Variables used by interrupt functions.
// Set to 1 for 2004 display and 0 to 1602 display.
#define LCD2004     0
#define LCD_ADDR    0x27

MyLcd_I2C lcd1(LCD_ADDR, 16, 2);

/*
 * Setup function.
 */
void setup()
{
  Serial.begin(9600);

  // Activate LCD module.
#if LCD2004 == 1
  Serial.println("Initializing 2004");
  lcd1.begin(20, 4);
#else
  Serial.println("Initializing 1602");
  lcd1.begin(16, 2);
#endif
  //lcd1.setBacklight(HIGH);

#if LCD2004 == 1
  lcd1.print("LCD TESTER 2004");
#else
  lcd1.print("LCD TESTER 1602");
#endif
  delay(2000);
}

/*
 * Main loop function.
 */
void loop()
{
  static unsigned long int  loopCnt = 0, mSec = 0, lastSec= 0, uptime = 0;
  static unsigned int       h = 0, m = 0, s = 0, n;
  static char               buffer[32];
  static bool               light = true;

  ++loopCnt;
  sprintf(buffer, "Loop %ld", loopCnt);
  Serial.println(buffer);

  // Uptime.
  mSec = millis();
  uptime += (mSec - lastSec) / 1000;
  lastSec = mSec;

  // Calculate hours, minutes and seconds uptime.
  s = uptime % 60;
  h = uptime / 3600;
  m = (uptime - (unsigned long int)(h) * 3600) / 60;

  // Go to start of 2nd line and show uptime.
  sprintf(buffer, "Up: %3d:%02d:%02d", h, m, s);
  lcd1.clearLine(0);
  lcd1.print(buffer);

#if LCD2004 == 1
  lcd1.clearLine(1);
  lcd1.print("Random #1: ");
  lcd1.print(random(0, 1000));

  lcd1.clearLine(2);
  lcd1.print("Random #2: ");
  lcd1.print(random(0, 1000));

  lcd1.clearLine(3);
  lcd1.print("Random #3: ");
  lcd1.print(random(0, 1000));
#else  
  lcd1.clearLine(1);
  lcd1.print("Random: ");
  lcd1.print(random(0, 1000));
#endif

  delay(1000);
}

MyLcd_I2C class code:

MyLcd_I2C::MyLcd_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows)
  : LiquidCrystal_I2C(lcd_addr)
{
  m_cols = lcd_cols;
  m_rows = lcd_rows;
}

void MyLcd_I2C::clearLine(const int lineNumber, const bool firstPos)
{
  if (lineNumber < m_rows) {
    setCursor(0, lineNumber);
    for (int i = 0; m_cols > i; i++) {
      write(' ');
    }
    if (firstPos) {
      setCursor(0, lineNumber);
    }
  }
}

size_t MyLcd_I2C::writeLine(const int lineNumber, const char *string)
{
  if (lineNumber < m_rows) {
    clearLine(lineNumber);
    return print(string);
  }
  
  return 0;
}

size_t MyLcd_I2C::writeLine(const int lineNumber, const __FlashStringHelper* string)
{
  size_t n = 0;

  if (lineNumber < m_rows) {
    clearLine(lineNumber);
    
    PGM_P p = reinterpret_cast<PGM_P>(string);
    while (true) {
      unsigned char c = pgm_read_byte(p++);
      if (0 == c) {
        break;
      }
      if (!write(c)) {
        break;
      }
      ++n;
    }
  }
  
  return n;
}

void MyLcd_I2C::at(const int lineNumber, const int cursorPosition, const char *string)
{
  if (lineNumber < m_rows) {
    setCursor(cursorPosition, lineNumber);
    print(string);
  }
}

void MyLcd_I2C::at(const int lineNumber, const int cursorPosition, const __FlashStringHelper *string)
{
  if (lineNumber < m_rows) {
    setCursor(cursorPosition, lineNumber);
    print(string);
  }
}

do you still have the older other version?

How about a textfile compare to see the differencies?
If you post a complete sketch others users will have less work to get your code running.

If you don't have the older version you might consider developing a habit to make backups.
As long as I develop a program the versions have a suffix -001, .002, -003 in it. Whenever I want to add something substantial I save the file as it is working, then I do a "save as..." with increased suffix-number.

best regards Stefan

I have older versions and they all fails. I suspect a library problem. Still working on it.

as you inherit from LiquidCrystal_I2C.
First test: try Hello World sketch from the lib you are using and check if the display is working.

if HelloWorld is ok and your sketch still fails double/tripple check the compiler output if you’re REALLY using the proper library. Compare the compiler outputs carefully!

Finally figured out what was wrong.

I have been using the LiquidCrystal_I2C library for a long time without any problems.
While looking at old backup of the user library area I noticed a new library: Arduino-LiquidCrystal-I2C-library-master

The output from the IDE when checking the code was:

Detecting libraries used...
"C:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10812 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\dahls\\AppData\\Local\\Temp\\arduino_build_697079\\sketch\\test-lcd-display.ino.cpp" -o nul
Alternatives for MyLcd_I2C.h: [myLcd_I2C]
ResolveLibrary(MyLcd_I2C.h)
  -> candidates: [myLcd_I2C]
"C:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10812 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\dahls\\Documents\\Arduino\\libraries\\myLcd_I2C" "C:\\Users\\dahls\\AppData\\Local\\Temp\\arduino_build_697079\\sketch\\test-lcd-display.ino.cpp" -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
  -> candidates: [Wire@1.0]
"C:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10812 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "-IC:\\Users\\dahls\\Documents\\Arduino\\libraries\\myLcd_I2C" "-IC:\\Users\\dahls\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "C:\\Users\\dahls\\AppData\\Local\\Temp\\arduino_build_697079\\sketch\\test-lcd-display.ino.cpp" -o nul
Alternatives for LiquidCrystal_I2C.h: [Arduino-LiquidCrystal-I2C-library-master LiquidCrystal_v1.2.1]
ResolveLibrary(LiquidCrystal_I2C.h)
  -> candidates: [Arduino-LiquidCrystal-I2C-library-master LiquidCrystal_v1.2.1]

...

Compiling library "LiquidCrystal_v1.2.1"

I then removed the LiquidCrystal_v1.2.1 library and tried again. This time I got a compilation error since the other library has a slightly different interface.

After changing my code everything worked OK.

When I first encountered this problem I had two thoughts - either broken LCD display (static electricity) or a library problem. It turned out that it was a library problem.

So beware when installing/updating libraries.

The hd44780 library is an alternative to the various LiquidCrystal libraries.

The hd44780 library is faster and will auto detect I2C address and I2C expander to LCD pin assignment. The hd44780 library is available through the library manager.

I got it, but haven't used it yet.
If it is faster, I consider rewriting my own libraries.

Thanks for the info.

groundFungus:
The hd44780 library is an alternative to the various LiquidCrystal libraries.

The hd44780 library is faster and will auto detect I2C address and I2C expander to LCD pin assignment. The hd44780 library is available through the library manager.

Hi GroundFungus,
can you write more information which hd44780-library do you mean. If I use the search-function in the library-manager with hd44780 lists up about ten libraries.
What's the name of the author of this library
or qoute the full description text or post a link to the github repository or the link that is behind the "more info" below the lib-description
best regards Stefan

Bill Perry's one.

Yes, that is the library. As far as I know it is the only LCD library that is named hd44780.

OK I understand. Thanks for clearing it up. Yes there is indeed only one library named "hd44780" This abbrevation is used in so many places that I doubted that this is the exact name of the library ,

best regards Stefan