I want to read data into an SD that is separated by commas. But I don't quite know how to read them correctly. I have done a test with a .txt file that contains the following data:
I just tried it and no... it doesn't work. The X values keep coming out wrong and the Y values keep going right. I do not know what it could be. I've also tried putting a comma right after the Y value. But that doesn't work either.
The problem is, believe it or not, integer overflow.
The .parseFloat() function puts all of the digits into a 'long int' before applying the decimal point. The value 2774000000 is too big to fit in a 'long int' so it overflows to -1520967296. That is then converted to 'float' which truncates the mantissa to 26(?) bits. That truncated value is divided by 1000000.0 to place the decimal point. The result is -1520.967163.
You might get correct-ish values if you use:
long Xi = myFile.parseInt(); // Integer part
long Xd = myFile.parseInt(); // Decimal part
float X = Xi + (Xd / 1000000.0);
The results should be correct to 6 or 7 significant digits but you aren't going to fit 11 significant digits in a 32-bit 'float'.
I would never have considered using the function, so I looked at the Arduino reference page to see if there were any warnings about this ridiculous limitation, but there aren't any.