Hello,
I'm trying to read data from a file on a micro sd card. To store this data, I used the following code:
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println(temperature());
// close the file:
myFile.close();
Serial.println("done.");
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
Where temperature returns a float....
When I read my file later in my program and display it on the serial monitor trough my computer with this code, it's working, returning my floats number on the screen:
File dataFile = SD.open("test.txt");
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
Serial.println("");
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening test.txt");
}
But if want to use these datas, I change the Serial.write(dataFile.read());
as following:
File dataFile = SD.open("test.txt");
String tempweb;
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
tempweb=String(dataFile.read());
Serial.println(tempweb);
// Serial.write(dataFile.read());
}
Serial.println("");
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening test.txt");
}
It's not returning me my floats, only strange numbers... =( I guess it's a problem in variable type, I read in the documentation that datas were written as *char. I cannot check this, I've no micro sd reader...
So how can I succeed in reading my datas as float to re-use them later?
Any help would be very appreciated , I'm trying to finish my own temperature datalogger server with a graphing display webpage (via google api chart) on a client ask.
Sorry for bad english, french arduino user, by the way if there is a big grammatical mistake, do not hesitate to tell me!
Best regards
WalterW