How to read csv file in sd card

Hai all.
i new in arduino and don't know too much in programming
i have (.csv) file. the (.csv) file format like this
row1 | clock1| clock2
row2 | clock1| clock2

how i can seperates row and column
the code just reading a file.

  while (file.available()) {
    fileRead = file.read();
    Serial.print(fileRead);
    //Serial.print(hari);
  }

anyone can help me
Thanks

after reading each line, consider using strtok()

thank for you respon

now my code like this, but in Serial monitor not show any value;

  while (file.available()) {
    fileRead = file.read();
    char value = strtok(fileRead, ",");
    while(value != NULL){
      Serial.print(value);
      value = strtok(NULL, ",");
    }
  }
  file.close();

can you write example? please

i typically do something like

char s [80];

#define MaxTok  10
char *toks [MaxTok];
int   vals [MaxTok];

// -----------------------------------------------------------------------------
int
tokenize (
    char       *s,
    const char *sep )
{
    unsigned n = 0;
    toks [n] = strtok (s, sep);
    vals [n] = atoi (toks [n]);

    for (n = 1; (toks [n] = strtok (NULL, sep)); n++)
        vals [n] = atoi (toks [n]);

    return n;
}

// -----------------------------------------------------------------------------
void dispToks (
    char * toks [])
{
    char s [40];
    for (unsigned n = 0; toks [n]; n++)  {
        sprintf (s, " %6d  %s", vals [n], toks [n]);
        Serial.println (s);
    }
}

// -----------------------------------------------------------------------------
void loop ()
{
    if (Serial.available ())  {
        int n = Serial. readBytesUntil ('\n', s, sizeof(s));
        s [n] = 0;      // terminate string

        tokenize (s, ",");
        dispToks (toks);
    }
}

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);
}
1 Like

thank you very much for your advice. i want to try to write your code. I hope this can solve my problem

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.