Go Down

Topic: Why do people still use SD.h (Read 940 times) previous topic - next topic

Mr_arduino

Jul 22, 2013, 05:08 pm Last Edit: Jul 22, 2013, 05:14 pm by Mr_arduino Reason: 1
SD.h is basically and out of date version of sdfatlib but slightly modified to ensure that it wears out the sd and write slower by flushing the buffer after every byte is written. Why not just use the latest version of sdfatlib it is now much better than SD.h. What is the point of even including SD.h when it is clear that they don't keep it in sync with the latest version of sdfatlib. While I am at it seems that non of libraries included with the arduino are really that good for an 8bit microcontroller. I have ditched the arduino ide and now just use avr-gcc.

robtillaart

Quote
Why do people still use SD.h

- backwards compatibility of old sketches
- easier interface
- they do not know other sd libs
- maybe footprint (but I do not know if it is smaller)
- ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

fat16lib

I think the main reason is that SD.h is the standard SD library included with the IDE.

So these are two reasons:
Quote

- backwards compatibility of old sketches
- they do not know other sd libs


The SdFat API has many more functions than SD.h so it is harder to understand.  Most people use the most basic functionality and don't require much performance so SD.h is fine.

For basic sketches SdFat is smaller and the complexity is about the same as SD.h.

Here is a simple SdFat sketch that writes a line to a file.  It uses 10,736 bytes of flash with the latest version of SdFat and Arduino 1.0.5.
Code: [Select]

/*
* Sketch to compare size of SdFat with Arduino SD library.
* See SD_Size.ino for Arduino SD sketch.
*
*/
#include <SdFat.h>

SdFat sd;

SdFile file;
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo

  if (!sd.begin()) {
    Serial.println("begin failed");
    return;
  }
  file.open("SIZE_TST.TXT", O_RDWR | O_CREAT | O_AT_END);

  file.println("Hello");

  file.close();
  Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {}


Here is the SD.h version of the sketch.  It uses  13,278 bytes of flash with Arduino 1.0.5.
Code: [Select]

/*
* Sketch to compare size of Arduino SD library with SdFat.
* See SdFatSize.ino for SdFat sketch.
*/
#include <SPI.h>
#include <SD.h>

File file;
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  while (!Serial) {}  // wait for Leonardo

  if (!SD.begin()) {
    Serial.println("begin failed");
    return;
  }
  file = SD.open("TEST_SD.TXT", FILE_WRITE);

  file.println("Hello");

  file.close();
  Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {}

Go Up