Go Down

Topic: Read LCD address from eeprom (Read 147 times) previous topic - next topic

i3dm

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.

sterretje

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

i3dm

#2
Oct 09, 2019, 08:23 pm Last Edit: Oct 09, 2019, 08:24 pm by i3dm
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:

Code: [Select]
#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.

david_2018

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

i3dm

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?
https://github.com/duinoWitchery/hd44780/blob/master/README.md

do you have an example maybe?

david_2018

#5
Oct 10, 2019, 01:11 pm Last Edit: Oct 10, 2019, 01:11 pm by 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

i3dm

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.

i3dm

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.

Go Up