LCD display 16x2 showing gibberish - how to reset? [SOLVED]

Hi, I am new to Arduino - so please excuse my level of ignorance :) . I have a standard 16x2 LCD display on an UNO, being addressed by the LiquidCrystal() library. It has been wired as per the example provided in the IDE. The system is in a very noisy electromagnetic environment and I should be shielding it, but can't do that until I get it running and tested. Problem is after about 5 minutes I lose the display when some motor or heavy duty switch gets excited. The display gets filled with random junk. But the UNO keeps on humming along and has never quit or reset and continues doing its job.

I have tried grounding / +5V the E pin and the RS pin on the display or turning +5V off and on, but the display continues showing the same junk, and does not reset. If I reset the UNO, then I get my display back -- but just for a short time until some equipment switches on or off. Is it possible to reset just the display? How does the UNO reset the display?

Is it possible to save the data collected by the UNO so if the UNO is reset to fix the display, I don't lose the data?

All comments are appreciated. protoVTOL

protovtol: The display gets filled with random junk.

Does lcd.clear() clear the LCD?

In 4 bit mode, the host and the LCD must remain in nibble sync. If they lose nibble sync with each other, it will never recover so the LCD will start to see garbage commands.
The only way to recover is to re-initalize the LCD using a special 3 command sequence to get back into sync.
This is done in the code in begin()

If you power cycle the LCD but not the Arduino that won’t help since the default power up mode for the LCD is 8 bit mode.
So if the library is in 4 bit mode and you power cycle only the LCD, the host (arduino) and the LCD will not be in the same mode (LCD in 8 bit mode, host in 4 bit mode) and the LCD will see garbage commands.

Nibble sync is lost if there is ever a glitch on the E signal.
You can help reduce this from happening by keeping the wires as short as possible, ensure all grounds and power signals have good connections.
Sometimes adding a .1uf cap directly to the LCD power and ground connections on the LCD module can help.

You could also try running the LCD in 8 bit mode which uses more pins but is supported by the LiquidCrystal library.
In 8 bit mode, it is still possible to get glitches on the display, but since things are done byte at a time there is no nibble synchronization issue so any effects of noise should be short lived and future commands to the LCD should continue to work.

— bill

First try a 220 µF capacitor directly across pins 1 and 2 of the LCD. Correct polarity of course.

Also please remember that all wires must be bundled closely together from one part to another. Jumper wires may work on a breadboard for a prototype, but not in a working environment.

Erik_Baas: Does lcd.clear() clear the LCD?

I tried that and the display remained in garbage mode.

@bperrybap and @Paul__B -- thanks for the suggestions. I am trying them out.



Erik_Baas: Does lcd.clear() clear the LCD?

Once the host and the LCD lose nibble sync, no commands will work since the LCD is seeing the upper nibble from one command byte and the lower nibble from the next command byte.

The only way to get back in sync is to use the specially constructed function set command 3 times to get into 8 bit mode, then another one to set 4 bit mode.

--- bill

Problem solved! Thanks to @bperrybap for his detailed explanation. lcd.begin() resynchs the communication, and the display comes alive. I call it every 10 seconds.

I will also be connecting a capacitor to the display power leads, at the display. This may obviate the need to call lcd.begin().

Thanks to all.


A 180 uF capacitor was connected to pins 1 & 2 at the display. This reduced the frequency of the display going haywire. But it eventually did. So calling lcd.begin() is still necessary (about once every few minutes).

The wiring layout will be the problem.

Well, it turned out that one reason the LCD display went bonkers was because I failed to physically ground the Arduino ground! Thus the whole circuit was floating in that noisy environment. So now I have physically grounded the circuit to the electrical ground and with the 180 uF display capacitor in place, the LCD has never failed. Thus no need to continuously call lcd.begin(). ;D