SparkFun Forums 

Where electronics enthusiasts find answers.

By Juli
#195723
Hello,

I am working on a HAB project (High Altitude Balloon) and it's my first time with Arduino and also with Razor IMU. Because of that I'm having some problems.
I have to read a .txt with the configuration from the SD card that you can plug on the Razor IMU but I have tried different things and it isn't working. I've managed to make it write to the SD card and it works but not reading.

It would be very nice if someone know if I'm doing something wrong.

void SDconfig(String cFile)
{
File configFile = SD.open("config3.txt", FILE_WRITE);

if(configFile)
{
configFile.print("Prueba escritura");
configFile.close();
}

File configFile2 = SD.open("config3.txt", FILE_READ);

if(configFile2)
{
while (configFile2.available());
{
Serial1.print("1" + configFile2.read());
LOG_PORT.print("2" + configFile2.read());
}

configFile2.close();
}
else
{
LOG_PORT.print("1 Error opening: " + cFile);
Serial1.print("2 Error opening: " + cFile);
}
}


File configFile = SD.open("myConfig3.txt", FILE_WRITE);
if (configFile)
{
configFile.println("Writting Test");
configFile.close();
}

File configFile2 = SD.open("myConfig3.txt");
char c;
String s = "";
if (configFile2)
{
// read from the file until there's nothing else in it:
while (configFile2.available())
{
//Serial1.println(configFile.read());
//LOG_PORT.println(configFile.read());
//LOG_PORT.println(">> " + num);
s = s + c;
}

// close the file:
configFile2.close();
} else {
// if the file didn't open, print an error:
//Serial1.println("error opening " + cFile);
LOG_PORT.println("error opening " + cFile);
}
LOG_PORT.println(s);

}



I've tried those 2 ways, I thought that the 2nd one should work because it's only a String to print but the Serial Monitor it's showing nothing. The baudrate it's setted at 9600 at other pint on the code, this is only a little part.

Thank you very much