Go Down

Topic: Appending to SD-card file (Read 9496 times) previous topic - next topic


Hello out there. My name is Joseph and i'm new here.
For my application i need to write 4 positions to a SD-file.
every ten ms there are new values that have to be appended to the file.
is there an append write for SD cards in the IDE?

thanks in advance

Jos, The Netherlands


Try something like this:
Code: [Select]
void loop()

  A = analogRead(1);
  B = analogRead(2);
  C = analogRead(3);
  C = analogRead(4);
  floatToString(a, A, 5);
  floatToString(b, B, 5);
  floatToString(c, C, 5);
  floatToString(d, D, 5);
  String dataString = String(a) + ", " + String(b) + ", " + String(c) + ", " + String(d);
  File logFile = SD.open("ABC.csv", FILE_WRITE);
  if (logFile)
    Serial.println("Couldn't open log file");


Will the hardware communicate fast enough to write to an SD card every 10 millisecs? I really have no idea. Thus asking.

Guessing that would also depend on how much data is being transferred as well. One could assume the amount of data would be small though. Otherwise, the SD card would be filled very quickly at 100 entries per second.

Just curious is all.


Code: [Select]
is there an append write for SD cards in the IDE?
Look at the source files.

The second argument to the open() method is HOW to open the file.

Code: [Select]
// use the gnu style oflag in open()
/** open() oflag for reading */
uint8_t const O_READ = 0X01;
/** open() oflag - same as O_READ */
uint8_t const O_RDONLY = O_READ;
/** open() oflag for write */
uint8_t const O_WRITE = 0X02;
/** open() oflag - same as O_WRITE */
uint8_t const O_WRONLY = O_WRITE;
/** open() oflag for reading and writing */
uint8_t const O_RDWR = (O_READ | O_WRITE);
/** open() oflag mask for access modes */
uint8_t const O_ACCMODE = (O_READ | O_WRITE);
/** The file offset shall be set to the end of the file prior to each write. */
uint8_t const O_APPEND = 0X04;
/** synchronous writes - call sync() after each write */
uint8_t const O_SYNC = 0X08;
/** create the file if nonexistent */
uint8_t const O_CREAT = 0X10;
/** If O_CREAT and O_EXCL are set, open() shall fail if the file exists */
uint8_t const O_EXCL = 0X20;
/** truncate the file to zero length */
uint8_t const O_TRUNC = 0X40;

Combine as you see fit to open the file exactly the way you want.


is there an append write for SD cards in the IDE?
The answer to your question is yes. You will see this in the SD example Datalogger included in the IDE. This pertains to the SD library included therein. The standard line for printing
Code: [Select]
myFile.print(variable);is an append command, and should be all you need. The question in reply #3 is probably valid. Assuming you are only using one file, I imagine opening it in setup, i.e. once, might help but I have no idea if you can record data that rapidly. This is something you should definitely check.


Old thread/topic, but I thought I'd add to it for anyone new looking. I am able to access the SD card for data logging consistently at 25ms.

It's a LIN bus system, if that matters, and the CSV file can get quite large in a hurry. I create a new file every 2 hours during testing.

Have not tried a faster transfer rate.

Make sure you are using the flush function before your buffer is full!

Go Up