Hello folks,
I'm tearing my hair out trying to get my project to work. I have an Arduino Uno R3 clone (Freetronics 100% compatible) with a 20x4 I2C LCD from DX (part number GY-LCD-V1). I also have four pushbuttons connected via the analog pins (in digital mode.) Other than that I have nothing connected to the arduino other than power via USB to my Mac.
My problem is that the screen freezes or starts showing garbage after a couple of minutes of the sketch running. Sometimes it seems that the screen gets half way through redrawing then just stops (in which case nothing updates the screen until I disconnect/reconnect the power) or starts drawing garbage to the screen, which also takes a cold boot to fix. Either way, the sketch continues running, i.e. the buttons produce output via the serial monitor and the heartbeat LED on pin 13 continues flashing (the main loop flashes it every second). Occasionally the sketch crashes, i.e. no response to button pushes and the LED stops flashing. If I reset the unit (either via the reset button or by closing/reopening the serial monitor) the screen sometimes won't re-initialise, i.e. the last drawn screen remains and won't redraw until the power is cycled.
Initially I thought this might be a memory problem. The sketch is big (about 28KB compiled without debug/info defines) and very nearly 32Kb with them compiled in. Free RAM is about 800bytes according to the debug statements. I've been mounting the hardware (LCD + buttons so far) in an enclosure, and I had a few days of the sketch running flawlessly, but now it's back to the normal problems.
I'd greatly appreciate any pointers on how to troubleshoot this.
I've attached the sketch - it's in a few files. It's too big to to put into this post in code tags.
Cheers,
Jon
BreweryController_V2.ino (8.53 KB)
SetupFunctions.ino (7.6 KB)
MainFunctions.ino (8.99 KB)
MenuFunctions.ino (18 KB)