sd latency

Hello eneryone,
I have a small project - logging to sd 14 analog sensors sampling at 20-50ms. I have used sd library in the past (on slower sampling rates) and plan to use it for this project on a mega2560.

From what I read, there is a "latency" which may become (spec) 250ms.

Q: This latency may happen at a .write or only at a file.close ?

Thank you

You should move to the SDFat library as it’s more up to date and he wrote a Low Latency Logger as an example.

J-M-L:
You should move to the SDFat library as it’s more up to date and he wrote a Low Latency Logger as an example.

I had read the above mentioned example, but can;t say how it can be re-arranged to suit my "need". As a matter of fact I also see a "tie" with serialdata (not analog sensors) a not needed menu and so on.I understand that sdfat is faster, newer more complete but perhaps the effort to convert is much more than :

#include <Wire.h>
#include <SPI.h>
#include <SD.h>

unsigned long milold1 = 0;

const int ADCpins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13};
int SensorRead[15];

void setup(void)
{

  pinMode(13, OUTPUT);
  Wire.begin();
  Serial.begin(115200);

  delay(500);

}

void loop(void)
{

  while (millis() - milold1 < 50) {
  }

  Serial.println(millis() - milold1);
  milold1 = millis();
  adc();
  Transfer();
}
void adc(void) {
  for (int x = 0; x < 14; x++) {
    SensorRead[x] = analogRead(ADCpins[x]);
  }
}

void Transfer(void) {
  File dataFile = SD.open("datalog5.txt", FILE_WRITE);

  if (dataFile) {
    for (int x = 0; x < 14; x++) {
      dataFile.write(SensorRead[x]);
    }
    dataFile.close();
  }
}

Comments welcomed

Instead of writing to the SD every 20-50ms, use an array to store samples, and only when the array is full, write its content to the SD.

guix:
Instead of writing to the SD every 20-50ms, use an array to store samples, and only when the array is full, write its content to the SD.

ok, will do this

but an answer at the initial question would be also usefull :
Q: This latency may happen at a .write or only at a file.close ?

If I remember correctly The library uses a buffer and from time to time will write the buffer to the SD.

It will definitely write to the SD if you close the file but also if buffer is full.

So latency happens at different moment depending on what you do