Pages: [1]   Go Down
Author Topic: Help Writing to SD card file in Ethernet Shield  (Read 675 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:

if ( Serial.available () > 0 )
    if ( == '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 (, 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?

Massachusetts, USA
Offline Offline
Tesla Member
Karma: 212
Posts: 8958
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:
void setup() {
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);

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

Pages: [1]   Go Up
Jump to: