I'm trying to make a simple data logger with an Uno as my first arduino project. I just want to write the values of a sensor to a SD card 10 times per second. The problem is that the time it takes to write to the SD card seems impossible to determinate. I created 3 experiments: First, I use an interruption (using timerOne) to set a flag. On the main loop, when that flag is on I write the current value of millis() through the serial port. The graph shows the difference between each consecutive value written: It seems to work! But now on the second experiment, I repeat the same thing except I use the SD library to write the value of micros() to a file. The results differ greatly: On a third experiment, I just write on the main loop 100 values of micros() to the SD card, no interruptions involved, and the variance is even bigger:
Inspecting the source of the SD libraries, I see that when Sd2Card::writeData() is called and there's no hardware SPI (that's the case of Uno, isn't it?) interruptions are blocked, but does that explain the great variance of the results?? and more importantly: is there a solution?