Go Down

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


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);

 liters = (percent*700000)/100;        
 Serial.print("Quantity of water in Tank:");
 Serial.print(liters, 1);

 if (file.open(&root, ficheiroLog, O_CREAT | O_APPEND | O_WRITE)){
   file.print("Tank level: ");
   file.print(percent, 1);
   file.print(" , ");
   file.print("Quantity of water: ");
   file.print(liters, 1);
   // close the file:
   Serial.println("Write Successfull!");
   Serial.println("LOG opening ERROR!");

Any suggestion?


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: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

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!

via Egeo 16
Torino, 10131