Capturing Data off an SD Card

Le Mon 11 November 2013

The following is a small section of a sketch that works to read the first two characters from the SD Card and put them into a new variable that will determine the size of the array to hold data. The example below uses "22" which is unclear whether it worked properly. A test with another file with 14 at the front indicated that it was able to function correctly. Note that it may fail if the number of initial digits is not two. The OpenOffice file used for issuing the times.csv file is set up so that the figure used includes two leading zeros in the format. This will ensure the right number of digits are available. This snippet is successfully used in this sketch and ultimately this sketch.

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

// In order to correctly size the array the first two digits
// off the file will be read as the Number of Fields to use. 

char ch = dataFile.read();  // Read the first entry - tens
int NoF = 10 * (ch-'0');    //Change ASCII digit to a tens digit
ch = dataFile.read();    // Read the second entry
NoF = NoF + ch-'0';    // Add the ones digit to the tens digit
ch = dataFile.read(); // read the next figure which will be a comma, but ignore it.
unsigned long values[NoF];  //This is the array to hold the values.
Serial.println(NoF);

...and so on...

Input

22,1386347400,1386563400,1387548000,1389155400,1389967200,1390278600,1397743200,1398141000,1398348000,1398832200,1401458400,1405398600,1414159200,1414470600,1415714400,1416457800,1417615200,1418016000,1418657400,1419297600,1421338800,1422507660

Output

Initializing SD card...card initialized.
22

Par Hamish Trolove, Cat├ęgorie : Tech Projects

Tags : Arduino / CSV /