Reading data from SD CARD .txt file, last byte wrong
hello trying read number sd card .txt file. used function below data last byte wrong. number 2345.
the number 234112.00.
then noticed in .txt file. after 2345 there empty line.
does empty line return w/c messed first result?
code: [select]
float test = 0.0; //global variable
//inside setup() below
file textdata = sd.open("something.txt");
if(textdata)
{
while(textdata.available())
{
float textread = textdata.read() - '0';
test = test * 10 + textread;
}
}
the number 234112.00.
then noticed in .txt file. after 2345 there empty line.
quote
2345when deleted empty line got exact number (2345.00).
<-- empty line here
does empty line return w/c messed first result?
quote
does empty line return w/c messed first result?yes; read data , includes carriage return and/or line feed.
solution: read databyte variable, check if it's not '\r' or '\n' , next add test variable (after subtracting '0').
Arduino Forum > Using Arduino > Programming Questions > Reading data from SD CARD .txt file, last byte wrong
arduino
Comments
Post a Comment