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
}