reading data from .CSV file as byte instead of ASCII value

Hey Folks,

Experimenting with an SD card. I have found a few post that I've guided me thru my first steps, but I have a question.

The CSV file that I'm using, has a series of numbers (4 column x 3 rows). These number will never be greater than 255.

When I read inside my Arduino, it reads every number as individual digit: for example 192 is rather 1 then 9 then 2.

I can read the comma, line feed or carriage return no problem.

I have built some code to "rebuild" my individual digit as a number, but I was wondering if there is a way to read the number (byte) directly ?

#include <SPI.h>
#include <SD.h>
int c = 0;
int Buffer = 0;


File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  myFile = SD.open("Book1.csv");
  if (myFile) 
    {
    Serial.println("Book1.csv:");
    }
    // read from the file until there's nothing else in it:
    while (myFile.available()) 
      {
      //Serial.write((myFile.read())-48);
        c = myFile.read();
        if(c == 44)
          {
            Serial.print(Buffer);
            Serial.print(",");
            Buffer = 0;
          } 
        if(c == 13)
          {
            Serial.print(Buffer);
            Serial.println("");
            Buffer = 0;
          } 
        if(c > 44)
          {
            if(Buffer>0)
              {
                Buffer = Buffer*10;
                Buffer = Buffer + (c-48);
              }
            if(Buffer==0)
              {
                Buffer = (c-48);
              }              
          }
        }
    // close the file:
    myFile.close();
}
void loop() {
  // nothing happens after setup
}

jasmino:
When I read inside my Arduino, it reads every number as individual digit: for example 192 is rather 1 then 9 then 2.

If the numbers can be read as 1, 9 and 2 then they are a character representation of a number rather than a single byte holding the value 192. You need to convert those characters using the atoi() function.

Have a look at the parse example in Serial Input Basics

...R

Or use "byteVariable = myFile.parseInt();" to read the next number from the file.

johnwasser: it worked !

thanks !

will work on the rest of my code......