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.

