Go Down

Topic: Problem with limited amount of data stored at once. (Read 485 times) previous topic - next topic

Snofoxx

I am using an Arduino Uno and would like to be able to store large amounts of data (for example, five minutes worth of continuous data) to an SD card. When I use the following script to try to log data to the SD card for a certain amount of time, I cannot successfully log more than 32 seconds of data at once. If I try to log 33 seconds of data, the data is never logged and I don't get either the "GPS logged." or "Failed to log new GPS data." messages. The script just seems to stop working.

I seem to be limited to 32 seconds of data no matter how much I am logging to the SD card. For example, I tried this same script, but instead of just logging A0 to the SD, I logged all six analog pins and still could log 32 seconds of data. Also, I can continue to add 32 seconds of data to the end of the same file, so the issue also doesn't appear to be with the size of the file.

This leads me to believe the problem isn't with how much data I want to store, but the length of time the file remains open. Is there a limit to how long the file can be open at once? Or is there a better way to log large amounts of continuous data?

Code: [Select]
#include <SPI.h>
#include <SD.h>
#define ARDUINO_USD_CS 10

void setup() {
  Serial.begin(9600);
  Serial.println("Setting up SD card.");
  if (!SD.begin(ARDUINO_USD_CS)) {
    Serial.println("Error initializing SD card.");
  }
}

void loop() {
  if (logGPSData()) {
    Serial.println("GPS logged.");
  }
  else {
    Serial.println("Failed to log new GPS data.");
  }
}

byte logGPSData() {
  File logFile = SD.open("log1.csv", FILE_WRITE);
  if (logFile) {
    int t = 0;
    int now = millis();
    while (t < 32000) {
      logFile.print(millis());
      logFile.print(',');
      logFile.println(analogRead(A0));
      t = millis() - now;
    }
    logFile.close();
    return 1;
  }
  return 0;
}

cattledog

Code: [Select]
int t = 0;
 int now = millis();


Make these variables unsigned long and you won't be limited to the 32 second chunks in the while loop.

Snofoxx


Go Up