Saving data on sd card with high speed

Hi
I have a question about logging data on MicroSD card. I read some related topics in the forums and saw very high data logging speeds but I couldn't understand how to reach there. I have an Arduino Leonardo and I want to read and save two analog data in one file with at least 1500 data per second. I use the following code, but when I use the timestamps in the serial monitor, I count an average of 50 data per second :(I am just logging one data in this code just to figure out the speed)

void loop()
{
float x = (float) analogRead (A0)*5/1024 ;
dataa = SD.open("data.txt", FILE_WRITE);
dataa.println(x);
dataa.close();
Serial.println(String (x) + " ; " + String (i));

}

I use the Serial.print code just for counting the data and it's not necessary.

Is there a problem with serial monitor, or just the speed of my code is that low?
I should mention that the board will work for 10 minutes or more (like 15 min) straight and I cant use EEPROM as it wouldn't be enough space(i think I can save data on EEPROM and then save them to sd card from there instead of saving to sd card directly but I don't know if that's faster).
Also If the opening and closing of the .txt file are too slow, maybe I can just delete them and open the file at "void setup" and just analog.read and save at "void loop" part.

As you can easily tell, I just started working with Arduino and just know the basics, So Can you help me with the idea or the code, please?

Do you really need to keep opening and closing the file, and don’t forget that printing takes time. What have you got the baud rate set to ?

Please post a complete sketch following the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.