# \[SOLVED\] Changing LiquidCrystal I2C address at runtime

**URL:** <https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916>\
**Category:** Networking, Protocols, and Devices\
**Created:** [May 8, 2018, 1:24pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916 "2018-05-08T13:24:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lozonta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lozonta/32/1161315_2.png) [@lozonta](https://forum.arduino.cc/u/lozonta)\
**Post date:** [May 8, 2018, 1:24pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/1 "2018-05-08T13:24:24Z")

</div>

Hello everyone, please can you tell me if it's possible to set the address of the lcd display at runtime?

I have two display with different adress (0x3F, 0x27) and I would like to set the address in the setup, not in the initialization

LiquidCrystal\_I2C lcd(0x3F, 20, 4);  
LiquidCrystal\_I2C lcd(0x27, 20, 4);

In this way I can read the address from a configuration file and I don't have to change it manually before sending the sketch to arduino.

I've searched in Arduino-LiquidCrystal-I2C-library-master and Newliquidcrystal\_1.3.5 but I haven't found the way to do this.

Thanks, Paolo.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 8, 2018, 1:33pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/2 "2018-05-08T13:33:04Z")

</div>

```cpp
LiquidCrystl_I2C *pLCD = NULL;

void setup()
{
  // Find the desired address, and store it in a byte variable names addr

  pLCD = new LiquidCrystal_I2C(addr, 20, 4);
}

```

Then, wherever you were using "lcd.", use "pLCD=\>" insread.

---

<div class="post-metadata">

**Author:** ![lozonta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lozonta/32/1161315_2.png) [@lozonta](https://forum.arduino.cc/u/lozonta)\
**Post date:** [May 8, 2018, 7:23pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/3 "2018-05-08T19:23:08Z")

</div>

> PaulS:
> 
> ```arduino
> LiquidCrystl_I2C *pLCD = NULL;
> 
> ```

void setup()  
{  
&nbsp; // Find the desired address, and store it in a byte variable names addr

pLCD = new LiquidCrystal\_I2C(addr, 20, 4);  
}

> ```arduino
> 
> Then, wherever you were using "lcd.", use "pLCD=>" insread.
> 
> ```

Thanks, I'm no good with pointers, I've tried this sketch

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

LiquidCrystal_I2C *pLCD = NULL;
byte lcdAddress = 39;

void setup()
{
  // initialize the LCD
  pLCD = new LiquidCrystal_I2C(lcdAddress, 20, 4);
  pLCD => begin();

  // Turn on the blacklight and print a message.
  pLCD => backlight();
  pLCD => print("Hello, world!");
}

void loop()
{
  // Do nothing here...
}

```

and I get this errors

Arduino:1.8.5 (Windows 10), Scheda:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Maneat\AppData\Local\Temp\arduino\_modified\_sketch\_19280\HelloWorld2.ino: In function 'void setup()':

HelloWorld2:11: error: expected primary-expression before '\>' token

pLCD =\> begin();

^

HelloWorld2:11: error: 'begin' was not declared in this scope

pLCD =\> begin();

^

HelloWorld2:14: error: expected primary-expression before '\>' token

pLCD =\> backlight();

^

HelloWorld2:14: error: 'backlight' was not declared in this scope

pLCD =\> backlight();

^

HelloWorld2:15: error: expected primary-expression before '\>' token

pLCD =\> print("Hello, world!");

^

HelloWorld2:15: error: 'print' was not declared in this scope

pLCD =\> print("Hello, world!");

^

exit status 1  
expected primary-expression before '\>' token

Questo report potrebbe essere più ricco di informazioni abilitando l'opzione  
"Mostra un output dettagliato durante la compilazione"  
in "File -\> Impostazioni"

---

<div class="post-metadata">

**Author:** ![lozonta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lozonta/32/1161315_2.png) [@lozonta](https://forum.arduino.cc/u/lozonta)\
**Post date:** [May 8, 2018, 7:28pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/4 "2018-05-08T19:28:47Z")

</div>

Ok simple not =\> but -\>

Sketch tested ok!

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

LiquidCrystal_I2C *pLCD = NULL;
byte lcdAddress = 39;

void setup()
{
  // initialize the LCD
  pLCD = new LiquidCrystal_I2C(lcdAddress, 20, 4);
  pLCD -> begin();

  // Turn on the blacklight and print a message.
  pLCD -> backlight();
  pLCD -> print("Hello, world!");
}

void loop()
{
  // Do nothing here...
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 9, 2018, 10:18am UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/5 "2018-05-09T10:18:20Z")

</div>

> Ok simple not =\> but -\>

What fat-fingered idiot suggested =\>? 8)

---

<div class="post-metadata">

**Author:** ![floresta](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/floresta/32/213547_2.png) [@floresta](https://forum.arduino.cc/u/floresta)\
**Post date:** [May 9, 2018, 1:18pm UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/6 "2018-05-09T13:18:29Z")

</div>

> PaulS:  
> What fat-fingered idiot suggested =\>? 8)

Now you should probably report yourself to the moderator!

Don

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 11:10am UTC](https://forum.arduino.cc/t/solved-changing-liquidcrystal-i2c-address-at-runtime/524916/7 "2021-05-06T11:10:47Z")

</div>


