Hello! I'm trying to write to a file in sd card to log the values that arduino gets from serial rx but i can't get it work. I've tried many ways and searching for some explanation about the commands to do this but i got nothing.
I'm using SPI.h , SdFat.h , SdFatUtil.h , Ethernet.h , Flash.h libraries. The code i'm trying is the above:
if ( Serial.available () > 0 )
{
if (Serial.read() == 'R')
{
Serial.readBytesUntil ( '\r', &buffer[0], 3 );
read = atoi(buffer);
percent = (read*100)/465;
Serial.print("Tank level:");
Serial.print(percent, 1);
Serial.println("%");
liters = (percent*700000)/100;
Serial.print("Quantity of water in Tank:");
Serial.print(liters, 1);
Serial.println("liters");
if (file.open(&root, ficheiroLog, O_CREAT | O_APPEND | O_WRITE)){
file.print("Tank level: ");
file.print(percent, 1);
file.print("%");
file.print(" , ");
file.print("Quantity of water: ");
file.print(liters, 1);
file.print("liters");
// close the file:
file.close();
Serial.println("Write Successfull!");
}else{
Serial.println("LOG opening ERROR!");
}
}
}
Any suggestion?