Go Down

Topic: Help Writing to SD card file in Ethernet Shield (Read 763 times) previous topic - next topic

blastboot

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:

Code: [Select]
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?

johnwasser

If you are NOT using the Ethernet functionality you have to disable it by setting Pin 10 to HIGH:
Code: [Select]

void setup() {
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy