How to reattach and I2C LCD to a running Arduino (without resetting)?

Title almost says it all.

I disconnect and reconnect the LCD to a running Arduino or connect the LCD after the Arduino is running the LCD stays blank, never displays anything (intelligible).

Can I, how can I, reattach an I2C LCD to the I2C bus after the arduino is running without resetting? What does it take, can it be done?

Up til now, disconnecting the LCD has been by accident or for a test and restarting the arduino to reconnect with the LCD hasn't been an issue. Now I'm working on a concept where it will be on purpose. The display will be for debugging only and doesn't need to/won't be attached all the time. I don't want to spend the money on the display or larger enclosure to have it attached all the time.

I'm using the hd44780 library.

Look at your program. What is done once with the LCD and not done again?

Paul

I wonder if you will not be better of using an 'active' lcd. E.g. an Arduino with a LCD that communicates with your target board via serial communication.

Paul_KD7HB: running begin multiple times won’t be an issue?

Sterretje: I thought of that, but I’m already using AltSoftSerial to make a second port. I don’t have space for a Mega, likely not even for an Uno. I’m looking at Nano, Mini, or Micro at best. The USB sends debug info out for enhanced debugging. The lcd is more for configuration and status to determine if you need to drag out a laptop to correct a bug.

A micro will provide you with the additional serial port :wink:

The LCD includes an I2C controller, so that a circuit can reset this controller when power is restored.

Otherwise try to find a response from the LCD, that indicates whether it has been initialized already.

DrDiettrich: any suggestions on how or what to detect?

Calling bperrybap...

Couldn’t you write a custom character to the cgram and read it back to confirm the device has been initialized? If the custom character changes, the display has lost power in which case you just re-initialize.

I don't have such a LCD at hand, can't find out anything :frowning:

A warning about what you are trying. Most electronic devices are designed to have the electrical connections made to ground first and then the positive voltages applied. Devices that are designed for hot replacement have connectors designed to ensure the ground is always first to be connected and last to be disconnected. If different + voltages are used, they will have a specific connection/disconnect sequence. Data connections are made last of all.

Paul

The ubiquitous USB connector in all its variants is a good example of the principles mentioned above.

That’s all good to know on the hardware requirements. What might it take on the software side. I already know (hope) there is something because the display doesn’t work if it is disconnected then reconnected without pushing the reset button.

Properly designed hardware would cause an interrupt on disconnect and reconnect, so the software can properly shut down the electronics or properly re-engage the electronics. It's all in the design, not something that can be slapped together after the fact.

At one time file servers were designed for hot switching of disk derives that were failing. The file systems were designed for redundancy so data would not be lost.

Paul

YOU are asking something unusual, so YOU have to do the experimenting.
Why don't you write a short sketch to test things out.
Arduino is a development system after all.

I would try this:

  1. declare pins etc., but don't have lcd.begin in setup.

  2. test if an LCD is connected in loop(), like they do with an I2C scanner.

  3. run lcd.begin (maybe once) if the outcome is positive, and set a 'printing ok' flag.

  4. if the outcome is negative, disable the 'printing ok' flag.

3 and 4 might need some clever coding to stop switching during connecting/disconnecting the LCD.
Not sure what calling lcd.begin() every loop() does. It might flicker a bit.
This might work (or not).
Globally declared...
boolean debug = false;

in loop()...
Wire.beginTransmission(0x27); // change to the address used
if (!Wire.endTransmission()) {
lcd.begin(16, 2);
debug = true;
} else debug = false;

Then for every print:
if(debug) Serial.print("blablabla");

Post your code. We might learn something from it.
Leo..

Your assumption about the behaviour of an uninitialized LCD looks wrong to me. If an uninitialized I2C device does not acknowledge a transmission, it cannot be addressed at all and hence cannot be initialized.

A test for the existence of the requested device (LCD) occurs with every data transmission. If the LCD is present, the transmission succeeds, otherwise the LCD is disconnected. Then every state change to "connected" must trigger an initialization of the LCD.

as a test, add a button.
connect your display,
push the button, run I2C begin......

let us know what happens.

Did you post your code ?
a link to your LCD ?
is it a parallel unit with an add-on serial board ?
what Arduino are you using ?

Are we expecting or not expecting any issues with issuing the begin command multiple times between power or reset cycles? (Memory leaks, iterative calls, similar or not)

You are correct in that this is not standard hence the thread and all the precautionary questions.

Look at the source code of the library. You don't say which library you're using so my guess is worse than yours :wink:

Try it. It won't explode. Bad code won't fry anything.
Naturally I'd move things out of setup and into loop, and then constrain what actually needs looping and what doesn't based on conditional checks.

As I knew the library being used would be important I made sure to include it in the OP. (I'm using the hd44780 library.)