Skip to main content
grammar corrections, thanks removed as per https://meta.stackexchange.com/q/2950/295232
Source Link

Arduino stopstops logging data after ~32761 secondeseconds

I made a small set up to log temperature on SD card, everything is running smoothly until it reach 9:06:01 of logging that is 32761 seconds. I know that correspondcorresponds roughly to the max number in amaximum value of an integer. But I assignedmade all mamy variables to unsigned long. Here is the code in the loop and the IFif condition to log or not. TimerThe timer is computed with currenTimecurrentTime (unsigned long) and startTime (unsigned long). soSo even if logCount*freq are both integer integers, sothey should reach maximum value after 32761 secondseconds, then the IFif condition should always be true.

void loop() { 
 String date;
 unsigned long timer;
 int freq = 60;

 sensors.requestTemperatures();
 tempC1 = printTemperature(insideThermometer, 18);
 tempC2 = printTemperature(outsideThermometer, 19);

 // start serial port
 Serial.begin(9600);

 mainMenuDraw();
 operateMainMenu();

 CurrentTime = millis();
 timer=(CurrentTime - StartTime)/1000;
 date = TimeShowFormatted(CurrentTime - StartTime);

 if (timer > logCount * freq and StopStatus == 0) {
  logCount += 1;
  LastLoggedDate=date;
  DataLogg(date);

 }
}

I thank you all for your help,

cheers

Arduino stop logging data after ~32761 seconde

I made a small set up to log temperature on SD card, everything is running smoothly until it reach 9:06:01 of logging that is 32761 seconds. I know that correspond roughly to the max number in a integer. But I assigned all ma variables to unsigned long. Here is the code in the loop and the IF condition to log or not. Timer is computed with currenTime (unsigned long) and startTime (unsigned long). so even if logCount*freq are both integer , so should reach maximum value after 32761 second, then the IF condition should always be true.

void loop() { 
 String date;
 unsigned long timer;
 int freq = 60;

 sensors.requestTemperatures();
 tempC1 = printTemperature(insideThermometer, 18);
 tempC2 = printTemperature(outsideThermometer, 19);

 // start serial port
 Serial.begin(9600);

 mainMenuDraw();
 operateMainMenu();

 CurrentTime = millis();
 timer=(CurrentTime - StartTime)/1000;
 date = TimeShowFormatted(CurrentTime - StartTime);

 if (timer > logCount * freq and StopStatus == 0) {
  logCount += 1;
  LastLoggedDate=date;
  DataLogg(date);

 }
}

I thank you all for your help,

cheers

Arduino stops logging data after ~32761 seconds

I made a small set up to log temperature on SD card, everything is running smoothly until it reach 9:06:01 of logging that is 32761 seconds. I know that corresponds roughly to the maximum value of an integer. But I made all my variables unsigned long. Here is the code in the loop and the if condition to log or not. The timer is computed with currentTime (unsigned long) and startTime (unsigned long). So even if logCount*freq are both integers, they should reach maximum value after 32761 seconds, then the if condition should always be true.

void loop() { 
 String date;
 unsigned long timer;
 int freq = 60;

 sensors.requestTemperatures();
 tempC1 = printTemperature(insideThermometer, 18);
 tempC2 = printTemperature(outsideThermometer, 19);

 // start serial port
 Serial.begin(9600);

 mainMenuDraw();
 operateMainMenu();

 CurrentTime = millis();
 timer=(CurrentTime - StartTime)/1000;
 date = TimeShowFormatted(CurrentTime - StartTime);

 if (timer > logCount * freq and StopStatus == 0) {
  logCount += 1;
  LastLoggedDate=date;
  DataLogg(date);

 }
}
Source Link

Arduino stop logging data after ~32761 seconde

I made a small set up to log temperature on SD card, everything is running smoothly until it reach 9:06:01 of logging that is 32761 seconds. I know that correspond roughly to the max number in a integer. But I assigned all ma variables to unsigned long. Here is the code in the loop and the IF condition to log or not. Timer is computed with currenTime (unsigned long) and startTime (unsigned long). so even if logCount*freq are both integer , so should reach maximum value after 32761 second, then the IF condition should always be true.

void loop() { 
 String date;
 unsigned long timer;
 int freq = 60;

 sensors.requestTemperatures();
 tempC1 = printTemperature(insideThermometer, 18);
 tempC2 = printTemperature(outsideThermometer, 19);

 // start serial port
 Serial.begin(9600);

 mainMenuDraw();
 operateMainMenu();

 CurrentTime = millis();
 timer=(CurrentTime - StartTime)/1000;
 date = TimeShowFormatted(CurrentTime - StartTime);

 if (timer > logCount * freq and StopStatus == 0) {
  logCount += 1;
  LastLoggedDate=date;
  DataLogg(date);

 }
}

I thank you all for your help,

cheers