I want to put rows from a CSV file into an array. The CSV is full of milliseconds and looks like this.
1111,2222,3333
4444,5555,6666
7777,8888,9999
0000,1111,2222
3333,4444,5555
So far I can read from the CSV with a whole row at a time and get this in the serial monitor.
111122223333
444455556666
777788889999
000011112222
333344445555
My code is this.
#include <SPI.h>
#include <SdFat.h>
const int SD_CS = 8;
SdFat SD;
File logFile;
void setup()
{
Serial.begin(9600);
pinMode (SD_CS, OUTPUT);
while(!SD.begin(SD_CS));
csvToArray();
}
void loop()
{
}
void csvToArray()
{
static String csvRow = "";
logFile = SD.open("test_SdA.csv");
while (logFile.available())
{
int csvChar = logFile.read();
if (isDigit(csvChar)) csvRow = csvRow + (char)csvChar;
if (csvChar == '\\n')
{
Serial.println(csvRow.toInt());
csvRow = "";
}
}
Serial.println("---- End of CSV");
logFile.close();
}
I want to split the CSV with something like this so I can put the values into an array.
csvCell1 = strtok(csvRow, ",");
csvCell2 = strtok(NULL, ",");
csvCell3 = strtok(NULL, ",");
I've tried to define csvCell1 as a String or a char but the sketch doesn't compile because it's the wrong variable type.
What am I getting wrong?