I2C LCD display works... most of the time

I’ve got a real strange I2C LCD problem, that I haven’t been able to find already discussed.

Most of the time, when I execute the setup function:

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setupLcd() {
 //20 x 4 LCD being used.
 lcd.begin(20, 4);

 // Flash the backlight to indicate LCD is ready for action.
 for (int i = 0; i< 3; i++) {

 // Now turn the backlight on.

everything works as expected. The backlight flashes several times and then stays on. Followed by the information sent in another part of the sketch.

However sometimes, usually after uploading the sketch, the LCD doesn’t do anything. No flashing, no text, nothing. Sometimes, pressing the RESET button on the UNO will cause what ever is “confusing the LCD” to be cleared and everything proceeds fine. Other times. I need to disconnect the LCD (SCL, SDA, and VCC), power down the UNO, reconnect the LCD and power up the UNO to get the LCD to respond correctly.

Any ideas?

Thanks in advance.

  • Mark

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Put a 10µF capacitor across pins 1 and 2 of the LCD. (Pin 1 is negative.)

Thanks for the suggestion. I tried adding the cap, and while the behavior seems to be a little reduced, the LCD still gets into a state where it will not respond to any command sent. A complete power cycle and reset usually brings it back.

BTW, the LCD, is powered by a separate HP variable lab supply, so there shouldn't be any issues with ripple or other typical inexpensive power supply issues.

I may try some ferrite beads on the leads to see if there is anything being coupled that way.

  • Mark

Do the i2c lines have the required pullups on them?

Do the i2c lines have the required pullups on them?

Other than the internal pullup resistors, no. However, with your clue, I went looking around and it appears one can encounter all manner of strange behaviors without external pullup resistors.

I added 4K7 resistors and the I2C pulse train went from looking like "saw teeth" to nice square wave pulses.

I guess I just happened to look at several "marginal" examples; all without external pullup resistors. I learned something new today. (Never having worked with I2C before :-)

Thank you very much.

  • Mark

Having not to date had any problems with pull-ups, I must wonder what sort - and length - of cable you have running from your Arduino to the LCD module?

Even the capacitance of the scope probe lead may possibly cause the "sawtooth" effect.

The wire connecting the two is 26 gauge hookup wire, about 10 inches (25 cm) in length. One end is a 4 pin header to connect to the I2C interface on the LCD and the other are single pin for connecting to the Arduino.

This is mainly a breadboard setup, while I work at getting all the various sub-assemblies working. I have the Arduino, the I2C LCD, a one wire keypad, an AD9851 DDS board, and an optical encoder. Eventually I expect to go to shorter wires and even possibly a PCB.

The scope is a Tektronix 7904 (500 MHz analog) with 10x probes.

I wonder if it may be related to the loading of the LCD/interface. I was having other strange problems until I put everything on a separate HP Lab supply I have.

  • Mark