I've been working on a small project for my university. I am having issues being able to extract data from a text file.
text file looks like:
8
0
9
0
10
0
11
and the extracted file looks like with char
8
0
9
0
1
0
0
1
1
What it looks like with int
48
13
10
48
13
10
49
I'm not sure how to fix it. I'v tried using string, float, int, char. Each gives me a odd answer, that is, for float it was giving me 48, 53, etc...
my current code is
#include <SD.h>
char filename[20];
File dataFile;
int i;
char data[200];
void setup()
{
Serial.begin(9600);
Serial.println("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
File dataFile = SD.open("Test.txt");
if(dataFile)
{
Serial.println("Reading Text File");
while(dataFile.available())
{
for (i=0; i<=200; i++)
{
data[ i ] = dataFile.read();
Serial.println(data[ i ]);
}
Serial.println("File Downloaded");
dataFile.close();
}
}
else
{
Serial.println("File does not exist");
}
dataFile.close();
}
void loop()
{
int l=0;
snprintf(filename, sizeof(filename), "data%03d.txt", l); // includes a three-digit sequence number in the file name
while(SD.exists(filename))
{
l++;
snprintf(filename, sizeof(filename), "data%03d.txt", l);
}
Serial.println("New Txt File Created");
File dataFile = SD.open(filename,FILE_WRITE);
for (i=0; i<=100; i++)
{
dataFile.println(data[ i ]);
}
Serial.println("Data Uploaded to new text file");
dataFile.close();
delay(100000);
return;
}
It looks like it is somewhere here... data[ i ] = int(dataFile.read()); (i dimmed it a char above...)
Please Help