SdFat.h incompatible with SD.h?


I am working on SD cards and mostly using SdFat.h library. However, I would need some functions from SD.h, I am getting some errors when compiling. Is there a solution for solving this incompatibility between these libraries.

At the moment, I need to have the available size left on SD card. I know how to do it in SD.h but not in SDFat.h



If you mean file.available(), SdFat does not provide available() since this function does not always provide the correct result in SD.h. The problem is available() is declared as an int in the Stream class. Type int is limited to 32767 bytes but files can be much larger, up to 4294967295 bytes.

You can use the following expression in SdFat:

  uint32_t bytesLeft;
  bytesLeft = file.fileSize() - file.curPosition();

Too get the correct result with SD.h use this expression instead of available():

  uint32_t bytesLeft;
  bytesLeft = file.size() - file.position();

I am having this error as well. Is there any new versions that make <SdFat.h> (Arduino DUE ver.) compatible with <SD.h>?


I am having this error as well.

This error? Would that be the unspecified errors OP was complaining about? Perhaps YOU could be more specific.

The current version of SdFat has an available() function that returns the correct unsigned 32-bit value on both AVR and ARM.

The Arduino SD.h available() returns the wrong answer for large files on both AVR and ARM.