I have a moderately complex program driving an LCD (Using the GLCD library, v3)and a few basic peripheral devices via shift registers, running on a Nano. up until yesterday everything had been working perfectly. The setup is pretty straightforward, a few LCD menus and various operations on the peripherals. Yesterday during testing however I found a strange issue, on the main run, if repeated 24 times without restarting the board, one of various strange bugs will occur:
Everything will freeze, on-screen timer shows up but doesn't count, no input will be accepted.
Certain text elements will corrupt, and instead fill the entire character area with full-block characters, no input will be accepted.
Timer will freeze, input will still be accepted but certain portions of the screen will never show text again (Possibly related to textareas with the GLCD library, I'm still trying to determine if this is the case)
Timer will fail to count and timer text will corrupt, showing only full-blocks where numbers should be. Input still works.
The program will entirely reset, and return to its splash screen.
With the exception of the last on that list, neither reseting the board manually nor power cycling it will fix anything. The programs will either fail to work at all or one of many various LCD display bugs will occur. The only way to fix any of them is to upload the program again.
This is all being done via the Arduino IDE, and everything else seems to be working perfectly fine. This is definitely stranger than anything I have encountered, and despite scouring the code I cannot find anything that would cause these bugs. I'm not even convinced that it's the code causing the issue, though, seeing as the bug only pops up after 24 perfectly normal and successful operations. The only thing I can think of at this point is that the code is somehow getting corrupted, but I don't know how that would happen nor how to fix it if it were.
Due to confidentiality reasons I can't post the entire program, but here is the portion where the bug occurs:
void startrun() { ///
int sec = 0;
int min = 0;
int totalruntime;
int flowcheckint = 500;
int clocktime;
long flowcheckprev = 500;
boolean flow;
long flowtimerprevious = millis();
long runtime = millis();
shiftwrite(pump, HIGH);
Title.CursorToXY(34, 4);
Title.print("Running...");
// Check for button press, if button is pressed, end run.
while(1) {
buttons();
if (select == 1) {
shiftwrite(pump, LOW);
totalruntime = ((millis() - runtime) / 1000);
runminutes = totalruntime / 60;
runseconds = totalruntime % 60;
GLCD.ClearScreen();
runcanceledscreen();
}
// Clock
gText ClockArea;
ClockArea.DefineArea(20, 0, 6, 1, fixednums15x31);
ClockArea.CursorToXY(2,20);
int lastsec;
clocktime = (millis() - runtime) / 1000;
sec = clocktime % 60;
min = clocktime / 60;
if(sec != lastsec) {
ClockArea.Printf("%02d:%02d", min, sec);
lastsec = sec;
}
// Flow buffer check
if (flow == 1 && millis() - flowtimerprevious >= flowbuff && millis() - runtime >= 20000) {
break;}
// Check sensor, print debug, set sensor buffer timer
if (millis() - flowcheckprev >= flowcheckint) {
flow = flowcheck();
flowcheckprev = millis();
if (flow == 0) {
flowtimerprevious = millis();
}
}
}
totalruntime = ((millis() - runtime) / 1000);
runminutes = totalruntime / 60;
runseconds = totalruntime % 60;
shiftwrite(pump, LOW);
GLCD.ClearScreen();
runcompletescreen();}
//\
One idea that I had, but am unsure how to test, is that I may be overfilling the RAM. Is there any way to check that? The sketch size as it currently is is 21KB.
Any ideas?