Hi there,
I have created a data logger project where I am comparing 3 different temperature sensors. The Arduino wakes up once every 4 seconds following the trigger from a DS3231 RTC and measures the three temperature sensors once before going to sleep. The code for the project is:
#include "subseaDatalogger.h"
ssDataLogger ssDL;
void setup()
{
ssDL.begin(4); //Initialise and set wake up period to 4 seconds
ssDL.newHeader("Time (s), LM35 (C), DS3231 (C), 328P (C)"); //Header for the .csv file
ssDL.newExtender("_temp"); //adds "_temp" to the end of every file
}
void loop()
{
ssDL.quickWrite(ssDL.indicatorLED, HIGH);
ssDL.readTime();
ssDL.readTemperature();
ssDL.readDS3231Temperature();
ssDL.readAVRTemperature();
ssDL.newline();
ssDL.saveToSD();
ssDL.quickWrite(ssDL.indicatorLED, LOW);
ssDL.goToSleep(); //Goes into power-down sleep mode and waits for RTC to trigger a wake-up
}
and everything works great, I end up with a file that looks like this:
However, I keep running into the issue that my datalogger will randomly sleep for much longer periods of time. Sometimes a minute, sometimes longer...
As an example, the difference in time for every datapoint should be 4 seconds, i.e., when I measure a datapoint, if the current time is 00:00:40, then the previous measurement time is 00:00:36, but, there are points in all of my files where the time is a minute or sometimes a few minutes:
and here is what the time difference looks like in the actual .csv file:

the code that I use to send the Arduino to sleep is:
void ssDataLogger::goToSleep()
{
//Set power down mode and set sleep enable
SMCR |= bit(SM1) | bit(SE);
// Set alarm to wake up from RTC
setAlarmTime();
// -------------- BOD disable - Assumes 5V supply won't fail! then sleep -----------
MCUCR |= (3 << 5);
MCUCR = (MCUCR & ~(1 << 5)) | (1 << 6);
__asm__ __volatile__("sleep");
}
where the setAlarmTime();
function is declared as:
void ssDataLogger::setAlarmTime()
{
alarm += timeStep;
if(alarm>59)
alarm -= 60;
writeDS3231(0x07, ((alarm/10) << 4)|(alarm%10)); //Write next alarm time to DS3231 alarm seconds register
writeDS3231(0x0F, 0b10001000); //Set A1F high in control register, needed to reset alarm and to write output trigger pin low
return;
}
where alarm
and timeStep
are private uint8_t variables declared in the ssDataLogger class.
Essentially, I have no idea as to what my datalogger will randomly sometimes sleep for a minute or longer when most of the time it sleeps for exactly 4 seconds as intended.
The only thing I think it could be is in how I am organising my memory, as when I compile my code I get this message:
Sketch uses 19618 bytes (60%) of program storage space. Maximum is 32256 bytes.
Global variables use 1646 bytes (80%) of dynamic memory, leaving 402 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.
As my ssDataLogger
object also uses an SD card, an ADS1115 ADC...
Do people think that this is simply an issue that is arising due to low memory?