how to reinitialize LCD, after cycling its power?

I'm using the 4-bit LCD library that comes with version 0018. I can get the LCD working fine. But every once in a while it gets a glitch and the display becomes scrambled. So I want to regenerate LCD module after it suffers this event. A power cycle on the LCD alone doesn't help, because the LCD boots up in 8bit mode again. It needs the magic 4-bit initialization sent to it that the LCD library does.

The goal is to keep the Arduino running. The program has a lot of state and context that is way more important than the display.. I need to keep it running and it continues to function fine as the LCD does its burp. So no, I don't want to power cycle the whole Arduino to "solve" this problem.

It's easy to control power to the LCD using an I/O pin. It draws so little, setting the pin HIGH is enough to power its Vcc. I tried that, works fine. Or alternatively, I could use a LOW to ground its GND pin. But the way things sit now, the LCD module is being powered by the 5volt and GND lines on the Arduino board.

I had to give it constant power because I learned the instance creation of an LCD variable done by this line of code, I guess...

LiquidCrystal(rs, enable, d4, d5, d6, d7);

is actually executed in Arduinoland before any setup() code runs, so it happens sooner than I can turn on an I/O pin to control power to the LCD module !? Lovely. The only "solution" is powering up the LCD with the Arduino (at the same time), or well before the Arduino. And it's impossible to cycle power on just the LCD module anytime after the starts up.

I want the ability to re-boot the LCD module, with bringing down the ATmega chip. So a button, when pressed, reboots the LCD by cycling its power, pausing, then re-sending the LCD library initialization code to it again. I might just regenerate the LCD every minute or so just as preventative maintenance and save the user from pressing a button labeled "if screen is garbled press this button".

Question: Can I just put the line of code

LiquidCrystal(rs, enable, d4, d5, d6, d7);

inline anywhere in setup() or loop() (again) and will it generate code that compiles and runs in that spot to re-initialize the LCD again, after taking a power cycle?

Or how else can I get the initialization string out to the LCD whenever I want?

thanks!

Scott:

Your analysis of the problem is correct but I am afraid that I cannot answer the key question "Can I just put the line of code ... inline anywhere in setup() or loop()". Perhaps someone else can.

Or how else can I get the initialization string out to the LCD whenever I want?

You could easily write some code to accomplish this for one LCD configuration, but integrating it with the LiquidCrystal library, which can be used with several LCD configurations, would be more than trivial.

Instead of using the library you could write your own LCD code that would permit the re-initializing of your LCD controller. The LiquidCrystal library is complex because it can handle several different LCD configurations. Your code could be much simpler because it would only have to deal with your specific configuration. You could 'borrow' most, if not all, of the code from LiquidCrystal.cpp.

Of course you could also try to track down and eliminate the glitch that is causing the problem in the first place.

Don

I think this is more of a software question than hardware interfacing. The hardware works. The LCD library works. (The LCD module itself is a bit flaky sometimes.. but that's not Arduino's issue).

My situation has more to do with the way Arduino compiles and inserts code related to libraries and the instantiation of variables, and scope. I'm stretching the limits of LCD library code structure from within setup() and loop()... so I've moved the discussion over to software interfacing.

Reading it quickly, this is what I do ALL the time. The begin command runs init over again. so after you bring up power, set RW to ground or whatever, then call lcd.begin. At that point the LCD finally boots. I routinely plug the LCDs into the long double row of sockets on the mega and boot them in just this way. The LCDtest sketch that is zipped with every version of enhanced LiquidCrystal illustrates this but it works fine with the standard LiquidCrystal library routine as well

I never knew that lcd.begin() reinit's the LCD module.

I will try cycling power on it, and just using lcd.begin to see if I can reestablish a healthy display.

I can't seem to find the LCDtest sketch example you talk about, there's
Autoscroll
Blink
Cursor
Display
HelloWorld
Scroll
SerialDisplay
setCursor
TextDirection

I've got the LCD library that comes with 0018.

Is this just a suckie version? What version of library should I be using? jrraines I see you are active in LCD land and an improver of libraries... need a recommendation.

http://healthriskappraisal.org/LiquidCrystal440.zip is probably a good version for most people.

jrraines thanks, I just solved the problem by putting an extra lcd.begin() in the code for the version of library Ive got. It works fine. Whereas I thought I might have to cycle power on the LCD when it garbles, turns out I don't - it can stay powered all the time. Just sending another lcd.begin() to it clears it up, repaint the display and continue life.