Author Options:

Reading 12 rows of data from an SD card every minute and storing the data into Arrays using Gboard pro Arduino Answered

Hi, I am working on a project that measures temperature and current, store it on an SD card (csv file) and send them to a website. I decided to sample the signals every 5 seconds and store the data to the SD card using time interrupt (TimerOne). My plan is to sample and store data for 1 minute and then read the sampled data from the SD card and store them into 2 Arrays i.e Array1 for temperature and Array2 for the current and send the data to the website.

Thus far I have managed to sample and store the data using the time interrupt. I also included a count variable in the interrupt subroutine so as to know how many times the interrupt has occurred. Since I am sampling and storing the data every 5 seconds and I want to read the data stored in the SD card every minute, so when count = 12 I would like to read  the last 12 readings (24 since its current and temperature ) and store them into 2 Arrays.   The problem I have is that I do not know how to read the data from the SD card and store them into two Arrays and would like your help.

Note: the Reading of the SD card will not be in the Interrupt subroutine

Any help or suggestions will be highly appreciated.




The forums are retiring in 2021 and are now closed for new topics and comments.

5 years ago

How did you write the data TO the SD card in the first place ?


Reply 5 years ago

Hi steveastrouk,

Thank you very much for the reply.

I stored the data into two columns in each row in the CSV file.


and so on


Reply 5 years ago

no, what CODE did you use to write your file to the card ?


Reply 5 years ago

this is how i initialized the timer1 to occure every 5 seconds

//initialize timer one interrupt

Timer1.initialize(5000000); //interrupt every 5 seconds

Timer1.attachInterrupt(Logger); // logg data n every 5 seconds

this is the function i call every 5 seconds ( reads the sensor values and write to the SD cards)

void Logger(void)


blinkCount = blinkCount + 1;

//Record temperature

float Temperatures = analogRead(0) * 0.33; // Temperature

float probe_Factor = (Temperatures * 0.0001 );


float GIC = (3.3/1023.)*analogRead(1);

float GICs= (GIC-1.5)*(3./1.5); //GICS

float GIC_Reading = (GICs/0.1);

// Serial.println(GIC_Reading);

dd= GIC_Reading;

String dataString = String(Temperatures )+","+ String(GIC_Reading);//convert to datastring for csv file

//*****************************log to sd card****************************

// open the file. note that only one file can be open at a time,

// so you have to close this one before opening another.

File dataFile = SD.open("datalog.csv", FILE_WRITE);

// if the file is available, write to it:

if (dataFile) {



// print to the serial port too:

// Serial.println(dataString);


// if the file isn't open, pop up an error:

else {

Serial.println("error opening datalog.txt");




Reply 5 years ago

Then you need to look at the instructions for your file system

File dataFile = SD.open("datalog.csv", FILE_WRITE);

I expect there to be a corrolating function

File dataFile = SD.open("datalog.csv");

and then char=dataFile.read()

You'll have to assemble the chars into a buffer and then use atoi probably to turn the buffer contents into numbers for storage. Since your file has lines in it, look for the ',' character to find the end of the first number, and then final <enter> character to finish the line.