2004 LCD shows white boxes after a period of time working correctly

I have a Hosyond 2004 LCD I2C display module (Amazon Sign-In) connected to a MEGA 2560 R3 via the I2C connection. After a particular period of time of correctly displaying what I programmed, the whole display goes to all white boxes and does not revert back until I re-upload the sketch.
I am attempting to use a keypad to enter a value (amount in cc's) and have it displayed correctly, then correctly compute the number of stepper steps that value is equal to. This will be used in a larger program that controls a linear actuator that drives plungers in fluid cartridges.
The LCD is connected via its I2C module to the MEGA 2560 I2C pins properly.

I created a separate sketch to test this portion of the software (see below) and it did work properly, but after a few minutes, the entire screen shows up white blocks in each block.

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <Keypad.h>

//Keypad dimensions (4 x 4)
const byte ROWS_NUM = 4;
const byte COLS_NUM = 4;

//define keypad buttons
char keys[ROWS_NUM][COLS_NUM] = {
  { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' }
};

//Keypad Pin IDs
byte rowPins[ROWS_NUM] = { 34, 35, 36, 37 };  //Row pin numbers
byte colPins[COLS_NUM] = { 38, 39, 40, 41 };  //Column pin numbers

//Keypad function creation
Keypad keypad = Keypad(makeKeymap(keys), rowPins,colPins, ROWS_NUM, COLS_NUM);

//LCD function creation
hd44780_I2Cexp lcd (0x27);

//LCD dimentsions
const int LCD_COLS = 20;
const int LCD_ROWS = 4;

//Character to long integer conversion variable
String inputString = "";
long inputInt;

//Variables and constants
const int stepsCC = 16; // this is the number of steps (based upon 1000 steps per revolution) that equates to 1 cc of mixed coating
int dispenseSteps = 0;

void setup() {
  // delay for LCD
  delay(3000);
  //Serial Communications Initialization
  Serial.begin(9600);

  //String size limit
  inputString.reserve(4); //Maximum number of character digits for a number input is 4

  //Initialization of LCD and inital text
  lcd.begin(LCD_COLS, LCD_ROWS);
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Amt to Dispense: ");
  lcd.setCursor(0,1);
  lcd.print("Cart Amt: ");
  lcd.setCursor(0,2);
  lcd.print("Total Amt: ");
}

void loop() {
  // Reading of Keypad key presses and conversion to long integer
  char key = keypad.getKey();
  if(key){
    if(key >='0' && key <='9'){
      inputString += key;
    }
    else {
      if(key == '#'){
        if(inputString.length()>0){
          inputInt = inputString.toInt();  //Convert keypad entry to integer
          inputString = "";
          lcd.setCursor(16,0);
          lcd.print("");
          lcd.print(inputInt);
          calculate();
        }
        else{
          if(key == '*'){
            inputString = "";
            lcd.setCursor(16,0);
            lcd.print("");
          }
        }
      }
    }
  }
}

//Calculate function - calculate # steps equivalent of long integer input.
void calculate(){
dispenseSteps = inputInt * stepsCC;
Serial.println("Dispense Steps: ");
Serial.println(dispenseSteps);
}

Has anyone have this happen to them? If so, what is the solution.
I have tried adjusting the poteniometer on the back but it did not work.
I have looked through all the LCD topics and have found that some spoke of installing resistors between both the the SCL and SDA lines and Vcc.
Though I am using the Wire.h library, which allows me to use the internal resistors, is this the source of my problem?
Picture of my wiring is below

Wiring at board

Wiring at LCD module

Thanks ahead of time for everyone's assistance.

  • Is your LCD Dupont connector reversed ?

  • Does the I2C address come up on the serial monitor when you run the I2C scanner ?

  • Did you remove the led jumper on the I2C board ?

  • Assume you have tried a second LCD (if you have one).

  • BTW, the I2C cable colours are normally reversed to what you have, however, you have reversed both ends of the cable so all good.

As a note, these are actually individual wires, not an actual ribbon cable. I ran the I2C scanner and it gave me the correct address.
Upon closer examination, the LED jumper is not installed, should it be? What would the purpose of this jumper be for?

As for trying a second LCD, the same happens.

Do you recommend installing pullup resistors on the SCL and SDA lines to Vcc?

Thanks for responding.

I have seen that effect when the voltage changes. Connect a voltmeter to the power terminals on the display and see if that is it.

The back pack usually comes with pull-up resistors, but you could try putting a couple on the controller outputs, it won't do any harm.

Run the diag sketch I2CexpDiag that comes with the hd44780_I2Cexp i/o class.
It will test for pullups, test the interface, and test the internal RAM of the LCD and report any issues it detects.

The Arduino Mega 2560 boards have 10k pullups on the Arduino board for SDA and SCL.
But even if it didn't, the I2c module you have has external pullups on it as well so you shouldn't waste any time adding even more pullups.
Also if you run the I2CexpDiag sketch it will detect if there are pullups on the SDA and SCL lines.

When you say

after a few minutes, the entire screen shows up white blocks in each block.

Do you mean that all 4 lines of 20 characters (all 80 characters) turn to blocks?

I have tried adjusting the poteniometer on the back but it did not work.

Do you mean that when all 80 characters were blocks, that when you turned the pot that the contrast did not change?
This should not be case.
When adjusting the pot, at one end, all the pixels should turn off and the other end all the pixels should be on, regardless of what is displayed on the display.

--- bill

1 Like

Be sure all of your connections are good, loose ones can cause funny things, blocks is one of them.

Thanks for the advice. I used the sketch you recommended and it provided all the info that you stated. So, I am not adding the pullup resistors so my wiring is simpler, and I did find that I had a loose connection. Once I tighten all the connections, the issues went away.

Again, thanks for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.