I went ahead and tried to replace SD.h plus Streaming.h with SdFat.h in my sketch, and it required one change in addition to defining the streaming objects.
My old code for SD.h + Streaming.h:
#include <SPI.h>
#include <SD.h>
#include <Streaming.h>
File logFile;
void setup()
{
SD.begin(8);
logFile = SD.open("LOGFILE.TXT", FILE_WRITE);
logFile << "SD + Streaming";
logFile.close();
}
void loop() {}
If I try to do this:
#include <SPI.h>
// #include <SD.h>
#include <SdFat.h>
#include <Streaming.h>
SdFat SD;
File logFile;
void setup()
{
SD.begin(8);
logFile = SD.open("LOGFILE.TXT", FILE_WRITE);
logFile << "SD + Streaming";
logFile.close();
}
void loop() {}
...I get this error message from the compiler:
In file included from SD-plus-streaming.ino:4:0:
C:\Users\dweathers\Documents\Arduino\libraries\Streaming/Streaming.h:100:21: error: 'endl' redeclared as different kind of symbol
enum _EndLineCode { endl };
^
In file included from C:\Users\dweathers\Documents\Arduino\libraries\SdFat/utility/bufstream.h:27:0,
from C:\Users\dweathers\Documents\Arduino\libraries\SdFat/utility/ArduinoStream.h:29,
from C:\Users\dweathers\Documents\Arduino\libraries\SdFat/utility/FatLib.h:23,
from C:\Users\dweathers\Documents\Arduino\libraries\SdFat/SdFat.h:27,
from SD-plus-streaming.ino:3:
C:\Users\dweathers\Documents\Arduino\libraries\SdFat/utility/iostream.h:40:17: error: previous declaration of 'ostream& endl(ostream&)'
inline ostream& endl(ostream& os) {
^
Error compiling.
...which is kind of weird because I haven't even tried to use the "endl" object.
Here's how I got streaming to work with SdFat by itself:
#include <SPI.h>
#include <SdFat.h>
SdFat SD;
File logFile;
ArduinoOutStream logStream(logFile);
void setup()
{
SD.begin(8);
logFile = SD.open("LOGFILE.TXT", FILE_WRITE);
logStream << "SdFat only";
logFile.close();
}
void loop() {}
It looks like I need to keep two objects around with SdFat's streaming code, compared to SD+Streaming (which can use the SD file object both for file operations like open and close as well as streaming with the << operator).
IMO, I find this a bit clunky and confusing. It makes more sense to me to do it the way SD + Streaming does it.
And perhaps the author of SdFat also wanted it to work this way, and I have exposed a bug. If so, it might help to know I'm using Windows 7 Pro SP1, with Arduino 1.6.4.
Any feedback on this would be welcome. Thanks in advance.