Go Down

Topic: Limiting File Size in SD card / Writing on multiple files (Read 198 times) previous topic - next topic

Beko

Hello there, I am now working on an arduino animal tracking project. To summarize, I have a code that takes information from an ublox gps sensor every 10 seconds, and writes the NMEA data to a csv file in the SD card every 60 seconds. So that's done. But there is a problem. In the upcoming stages, I will be transmitting the csv file via telemetry to a Raspberry Pi, so I need to limit the size of the csv file so that there won't be any problem when sending data. In other words, I am looking for lines of code that checks file size, closes the file when it's over a certain size, and opens a new one and continues writing data on it. I appreciate any help! Please help me understand what kind of a function I need to add there, and how to do it if possible. Thanks in advance.

The code already "opens" and "closes" the file before and after writing the data. But there is only one to write on. And it is risky if it gets really large over long time. So it is necessary to divide it into multiple files and send like that.

Below is the part where the data is written on the file:


void writeSDCard(){       // SD card writing function
  int a;
    File dataFile = SD.open("datalog.csv", FILE_WRITE);

 
  if (dataFile) {
    for (a=readByte; a<550; a++) inBuffer[a] = 0;
    dataFile.println(inBuffer);
   
    dataFile.println("\n\r");
    dataFile.flush();
    dataFile.close();
    Serial.println("Written to SD Card");
   
  }
 
  else {
    Serial.println("error opening datalog.csv");

  }





Nick_Pyner

I have a code that takes information from an ublox gps sensor every 10 seconds, and writes the NMEA data to a csv file in the SD card every 60 seconds. So that's done. But there is a problem. In the upcoming stages, I will be transmitting the csv file via telemetry to a Raspberry Pi, so I need to limit the size of the csv file so that there won't be any problem when sending data.
It is not clear why you have, or think you have, a problem. Maybe the problem is with Raspberry Pi, but I can't think what that would be.

Go Up