lt1609 ADC to SDcard datalogger

Hi!
I want to make a vibration sensor with sdcard datalogger, using lt1609 adc.
Made a small program, to test the adc, it's works fine, can make 10000-15000 readings per second

#include<SPI.h>
int  rcPin    =  7;
int  adcPin   =  9; 
int  sdPin    =  10;
int  busy     =  2;
int ledPin = 3;
unsigned long i=0;
byte  LowByte,HighByte;
unsigned int  adcValue =  0;



void setup(){
  pinMode(ledPin,OUTPUT);
  pinMode(adcPin,OUTPUT);
  pinMode(sdPin, OUTPUT);
  pinMode(rcPin, OUTPUT);
  pinMode(busy,INPUT);
  digitalWrite(adcPin,HIGH);
  digitalWrite(sdPin,HIGH);
  Serial.begin(115200);
  SPI.begin();
  //SPI.setBitOrder(MSBFIRST);
  //SPI.setClockDivider(SPI_CLOCK_DIV4);
  //SPI.setDataMode(SPI_MODE0);
  delay(100);
  digitalWrite(adcPin,LOW);
  digitalWrite(rcPin,HIGH);
  delay(100);
  Serial.println("start");
}

void loop(){
  digitalWrite(adcPin,LOW);
  digitalWrite(rcPin,LOW);
  digitalWrite(rcPin,HIGH);

  while(!digitalRead(busy)){}
  
  LowByte = SPI.transfer(0xFF);
  HighByte = SPI.transfer(0xFF);
  adcValue = HighByte * 256 + LowByte;
  Serial.println(adcValue);
  digitalWrite(adcPin,HIGH);
  
}

After this, modified the sd card example, to read the adc, and write the data to the sdcard, but now it's only make 2000-2500 readings per second. The sdcard is a 8Gb sandisk class10 card. What can I do, to make it faster?

#include <SPI.h>
#include <SdFat.h>
const uint8_t chipSelect = 10;
const uint32_t SAMPLE_INTERVAL_MS = 200;
#define FILE_BASE_NAME "Data"
SdFat sd;
SdFile file;
uint32_t logTime;
const uint8_t ANALOG_COUNT = 4;
void writeHeader() {
  file.print(F("micros"));
  for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    file.print(F(",adc"));
    file.print(i, DEC);
  }
  file.println();
}
#define error(msg) sd.errorHalt(F(msg))



unsigned long timer=0;
int  rcPin    =  7;
int  adcPin   =  9; 
int  sdPin    =  10;
int  busy     =  2;
int ledPin = 3;
unsigned long i=0;
byte  LowByte,HighByte;
unsigned int  adcValue =  0;



void setup() {
  const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
  char fileName[13] = FILE_BASE_NAME ".txt";

  Serial.begin(9600);
  
   pinMode(ledPin,OUTPUT);
  pinMode(adcPin,OUTPUT);
  pinMode(sdPin, OUTPUT);
  pinMode(rcPin, OUTPUT);
  pinMode(busy,INPUT);
  digitalWrite(adcPin,HIGH);
  digitalWrite(sdPin,HIGH);
  SPI.begin();
  //SPI.setBitOrder(MSBFIRST);
  //SPI.setClockDivider(SPI_CLOCK_DIV4);
  //SPI.setDataMode(SPI_MODE0);
  delay(100);
  digitalWrite(adcPin,LOW);
  digitalWrite(rcPin,HIGH);
  delay(100);
  
  
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }
  if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
  }
  while (sd.exists(fileName)) {
    if (fileName[BASE_NAME_SIZE + 1] != '9') {
      fileName[BASE_NAME_SIZE + 1]++;
    } else if (fileName[BASE_NAME_SIZE] != '9') {
      fileName[BASE_NAME_SIZE + 1] = '0';
      fileName[BASE_NAME_SIZE]++;
    } else {
      error("Can't create file name");
    }
  }
  if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
    error("file.open");
  }
 

Serial.println("start");
timer=millis();
}

void loop() {
  
  digitalWrite(adcPin,LOW);
  digitalWrite(rcPin,LOW);
  digitalWrite(rcPin,HIGH);

  while(!digitalRead(busy)){
  }
 
  
  LowByte = SPI.transfer(0xFF);
  HighByte = SPI.transfer(0xFF);
  adcValue = HighByte * 256 + LowByte;
  digitalWrite(adcPin,HIGH);
  file.println(adcValue);


if(millis()>timer+10000){

  file.sync();
  timer=millis();
}

  
}
if(millis()>timer+10000){

Wrong. This should be:

if(millis() - timer >= 10000){

(except that timer is a stupid name for an event time).

It's hard to believe that you get 15000 reading per second while Serial.print()ing the data.

Writing to the SD card is buffered. When the buffer gets full, it has to be committed to the card. That takes time.

There is a thread in this section of the forum dealing with a fast data logger. Hunt that up.

On the first, wrong code, commented out the serialprint, and made a counter, which is measure the readings, that's how I know the number of readings

Connecting an ADC and an SD to hardware SPI will not work at high sampling rates.

SD cards require an entire 512 byte block to be written in a single SPI transfer.

Even worse, the SD card can have occasional write latencies of up to 250 ms.

You may be able to achieve 500 samples per second if you use the trick in the LowLatencyLogger example.

The LowLatencyLogger example buffers data when the SD card is busy.

To go faster, you will need to use software SPI and read your ADC in an ISR. I use this method in the SdFat AnalogBinLogger example.

I have used ADCs like yours to log data at 10,000 samples per second. You probably will need a Mega for sufficient buffer. Your ADC is fast so you don't need all the code I wrote for the slow AVR internal ADC. Just use timer1 to generate interrupts and read the ADC in the timer ISR.