How to save data in a buffer in Arduino

Hi!

I have a problem! I need to save data in a buffer. Once done it I have to save them in a MicroSD. My problem is on saving data on a buffer. Have you got any advice? Thanks in advance!

Maybe the Serial Input Basics thread can give you some ideas.

Although it's written for Serial communication, the principles can be applied to basically anything (file read, network read, ...).

Why do you want / need to save to buffer first before writing to SD?

I need to acquire data every 20 milliseconds. I have synchronized two sensors and their output must be detected and saved on a txt file. To synchronize everything I used interrupts but once introduced micro SD I was not able to detect every 20 milliseconds but at maximum every 60 milliseconds, so I thought to save that data in a buffer and then save them on Micro SD. Can be a good idea?

A buffer is simply an array and you save data to each array element using the = operation.

int inputValues [16];

for(i=0; i<16; i++){
value = // what ever you have to do to read the value
inputValues[i] = value;
}

If you have an interrupt that is used to count frequency, how would suggest one do the buffer for higher frequencies?

How high?