Read LCD address from eeprom

Hello guys,

i would like to ave a 16x2 LCD i2c address in eeprom, and then on the next boot read it and delcare the LCD according to it.

if i declare:
LiquidCrystal_I2C lcd(0x28, 16, 2);

and then later reed eeprom "address" and redeclare LCD in the setup:
LiquidCrystal_I2C lcd(address, 16, 2);

the main loop lcd.print() commands respond to address 0x28 and not to "address".
any tips how to fix this?

if i declare "LiquidCrystal_I2C lcd(address, 16, 2)" in every cycle of the main loop the LCD works, but it keeps flashing as declearation needs a backlight switch on after it.

thank you.

My crying ball is in for repairs so I can't see your code.

Please post your code using code tags; if you don't know how, read the "how to use this forum" sticky.

Here is an exmaple code.
my LCD address is 0x27.
i purposely init the LCD on 0x3F, and then i want to read address from EEPROM (0x27) and re-init the LCD to 0x27.

but it appears that since i have already initied the object lcd, it stays on address 0x3f.

Test code:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f, 16, 2); // wrong LCD address
#include <EEPROM.h>

int arm = 0;

void setup()
{
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print ("Setup");
  delay(500);
}

void loop()
{
  if (arm == 0)
  {
    // read correct LCD address from EEPROM here
    LiquidCrystal_I2C lcd(0x27, 16, 2);
    lcd.init();  
    lcd.backlight();
    arm = 1;
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print ("  Loop test ");
  delay(500);
}

This code does not print anything on LCD with address 0x27, but if i change the top init to 0x27, it works.
the problem is that my final version Ardu wont know the LCD address its attached to until it scans and finds it, and this is after the LCD init phase.

Have a look at the hd44780 library, it can automatically locate the I2C address of the display at run-time.

david_2018:
Have a look at the hd44780 library, it can automatically locate the I2C address of the display at run-time.

interesting. i don't see it in the API though?

do you have an example maybe?

If you look at the HelloWorld example the comments mention not needing to specify the I2C address, but I don't see it mentioned explicitly in the API for some reason.

HelloWorld.ino

david_2018:
If you look at the HelloWorld example the comments mention not needing to specify the I2C address, but I don't see it mentioned explicitly in the API for some reason.

HelloWorld.ino

ill test the example and see.

david_2018:
If you look at the HelloWorld example the comments mention not needing to specify the I2C address, but I don't see it mentioned explicitly in the API for some reason.

HelloWorld.ino

works like a charm!
thank you.