Pages: [1]   Go Down
Author Topic: Help Writing to SD card file in Ethernet Shield  (Read 630 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8687
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are NOT using the Ethernet functionality you have to disable it by setting Pin 10 to HIGH:
Code:
void setup() {
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: