Hi All,
I'm facing a difficult bug which has developed from appearing sometime to almost always.
I've build an automation system for a camper which controls almost everything like light, charging, watermanagement, etc. The problem that i'm facing is that the Mega 2560 mostly doesn't execute code after getting power.
In the beginning this happens sometimes. Now this happens always. Sometimes it was fixable by pressing the resetbutton or just wait. Sometimes it was starting at couple of minutes, sometimes it take several hours. I've changed the board with a second one and this didn't fix the issue.
The question is where to look...
I've started with debugging the code by sending data to Serial and monitor that with Putty. It looks like the code isn't entering the setup() function or hangs after calling Serial.begin(). When it does enter, the rest is also working. I Also tryed to load another test project with just a serial message and this works perfectly..
Could it be that the controller is waiting on someting? Or could it be that there goes someting wrong in the object, constant and variable declarations which causes a memory issue?
void setup()
{
//debugger
if (SHOW_DEBUG)
{
Serial.begin(115200);
Serial.setTimeout(100);
Serial.availableForWrite();
}
debug("Start initialising...");
debug("Init Serial 1 - Display");
//Serial data LCD
Serial1.begin(115200);
Serial1.setTimeout(200);
Serial1.availableForWrite();
debug("Init Serial 2 - Lightcontroller");
// Arduino Nano lightcontroller
Serial2.begin(115200);
Serial2.setTimeout(200);
Serial2.availableForWrite();
debug("Init temperature sensor");
temperatureSensorInside.begin();
temperatureSensorOutside.begin();
//Set sensor resolution to 0.125
temperatureSensorInside.setResolution(sensorTemperatureInside, 11);
temperatureSensorOutside.setResolution(sensorTemperatureOutside, 11);
debug("Init SD card");
//Read config data from SD
config.readSdData("config.txt");
debug("Set HMI brightnesslevels to default");
//Fill HMI Brightness to 100 to start at max brightness
for (size_t i = 0; i < SAMPLES_BRIGHTNESS; i++)
{
HMIBrightnessLevel[i] = 100;
}
debug("Init pins");
pinMode(BTN_BED_Pin, INPUT_PULLUP);
pinMode(PIN_WALSTROOM, INPUT_PULLUP);
pinMode(BTN_BED_Feedback, OUTPUT);
debug("Done");
}
void debug(String text)
{
if (SHOW_DEBUG && Serial.availableForWrite())
Serial.println(text);
}