need help with reading string from sd card

hi,

i’m doing a project with Arduino DUE and i got a problem.

when i’m trying to read the variable from a txt file in the sd card, i dont get the right variable.

i tried to substract the ‘0’ in ASCII but its no use.

the odd thing is that I have 3 text file that read in my function, IR00, IR01 and IR02

the result that I get from the first two is incorrect and the result from the last one is right.

in the IR00 there are a value of 2, in the IR01 there are a value of 12 and in the IR02 there are a value of 2704.

here is the function that I’m using to get the value from the text files.

for example:

in sd card i have a file name IR00.txt, in it i have the number 2.

this is the part of the program that handles the IR00 part.

void RestoreCodetoMem(){

Serial.flush();

File IR01 = SD.open(“IR01.txt”);

if (IR01)

{

Serial.println(“Reading IR01 File”);

float decade = pow(10, (IR01.available() - 1));

while(IR01.available())

{

float temp = (IR01.read() - ‘0’);

codestorage[0][1] = temp*decade+codestorage[0][1];

decade = decade/10;

}

Serial.print("Code Lengh codestorage[0][1] = ");

Serial.println(codestorage[0][1]);

}

else

{

Serial.println(“Could not read IR01 file.”);

return;

}

IR01.close();

Serial.flush();

File IR02 = SD.open(“IR02.txt”);

if (IR02)

{

Serial.println(“Reading IR02 File”);

float decade = pow(10, (IR02.available() - 1));

while(IR02.available())

{

float temp = (IR02.read() - ‘0’);

codestorage[0][2] = temp*decade+codestorage[0][2];

decade = decade/10;

}

Serial.print("Code codestorage[0][2] = ");

Serial.println(codestorage[0][2]);

}

else

{

Serial.println(“Could not read IR02 file.”);

return;

}

IR02.close();

Serial.flush();

File IR03 = SD.open(“IR03.txt”);

if (IR03)

{

Serial.println(“Reading IR03 File”);

float decade = pow(10, (IR03.available() - 1));

while(IR03.available())

{

float temp = (IR03.read() - ‘0’);

codestorage[0][0] = temp*decade+codestorage[0][0];

decade = decade/10;

}

Serial.print("Code Type codestorage[0][0] = ");

Serial.println(codestorage[0][0]);

}

else

{

Serial.println(“Could not read IR00 file.”);

return;

}

IR03.close();

}

this function is called in the setup and put the value in my global array codestorage

i dont see what is the difference between the text file .

if I just read the value from the text file by using the Serial.wrtite() function I got the right value but when i want put them to the array something goes wrong.

what can i do to take/use and not just read the data from the sd card ?

please help !!!

note: codestorage = {0}; is a global array in the main program .

Don’t be scarce with your code. Post everything, or at least a link to a place where we can read it online if it is too much. As you don’t know where the problem is, you cannot be sure it is in the code part you did disclose to us.

You DO state that you do not get the right value, but you DIDN’T state what that should be. What are you expecting as a result? And what DID you get as a value result anyway? That might hint at locations in the code where things go wrong compared to as expected. You need leads to trace this problem back to it’s source. (pun intended :stuck_out_tongue: ) Make sure you understand and can perform the functions that the code has to do yourself. Follow the code in your mind. While testing the code, make extensive use of serial.print statements to tell what your code is doing at that moment. And so it reports it’s intermediate results of calculations or whatever it retrieves from those files. If it doesn’t match what you came up with then you have something.

And do upload the 3 files as attachment to your next message. Numbers in files can be defined in different ways, like ascii, binary, BCD. And separated in even more ways. My magic orb is suffering from a nervous breakdown trying to find out.

https://www.youtube.com/watch?v=Pj-qBUWOYfE