Experimentalist
Well-known member
Hi, can anyone give me some guidance on how I may redirect the output from the SdFat library (https://github.com/greiman/SdFat.git) to the hardware serial output?
Some code to list the files on the SD card, using the standard Serial object:
Using the HardwareSerial object:
The problem I have is that the output from the line
is still directed to the software serial rather than the hardware serial. I presume I have to redirect the standard output stream some how but I am unsure how to achieve this.
Anybody?
Ex.
Some code to list the files on the SD card, using the standard Serial object:
Code:
#include <SdFat.h>
// SD card chip select pin.
const uint8_t SD_CHIP_SELECT = 6;
// File system object.
SdFat sd;
// Create a Serial output stream.
ArduinoOutStream cout(Serial);
// Buffer for Serial input.
char cinBuf[40];
// Create a serial input stream.
ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));
// Error messages stored in flash.
#define error(msg) error_P(PSTR(msg))
//------------------------------------------------------------------------------
void error_P(const char* msg) {
sd.errorHalt_P(msg);
}
void setup() {
Serial.begin(9600);
while (!Serial) {} // wait for Leonardo
delay(1000);
cout << pstr("Type any character to start\n");
// Wait for input line and discard.
cin.readline();
if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED)) sd.initErrorHalt();
cout << pstr("List of files on the SD.\n");
sd.ls("/", LS_R);
}
void loop(){
}
Using the HardwareSerial object:
Code:
#include <SdFat.h>
// SD card chip select pin.
const uint8_t SD_CHIP_SELECT = 6;
// File system object.
SdFat sd;
HardwareSerial Uart = HardwareSerial();
// Serial output stream
ArduinoOutStream cout(Uart);
// input buffer for line
char cinBuf[40];
ArduinoInStream cin(Uart, cinBuf, sizeof(cinBuf));
// Error messages stored in flash.
#define error(msg) error_P(PSTR(msg))
//------------------------------------------------------------------------------
void error_P(const char* msg) {
sd.errorHalt_P(msg);
}
void setup() {
Uart.begin(38400);
Serial.begin(9600);
while (!Serial) {} // wait for Leonardo
delay(1000);
cout << pstr("Type any character to start\n");
// Wait for input line and discard.
cin.readline();
if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED)) sd.initErrorHalt();
cout << pstr("List of files on the SD.\n");
sd.ls("/", LS_R);
}
void loop(){
}
The problem I have is that the output from the line
Code:
sd.ls("/", LS_R);
Anybody?
Ex.