Hello,
When I try to retrieve data from my sd card, I sometimes receive weird characters on my Serial monitor, but not all the time.
For example:
#include <SD.h>
File myFile;
#define pinCS 53 // SD-Card CS-pin
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
// SD Card Initialization
if (SD.begin(pinCS)) {
Serial.println(F("SD card is ready to use."));
}
else {
Serial.println(F("SD card initialization failed"));
return;
}
char sdString[38];
myFile = SD.open("testfile.txt");
if (myFile) {
myFile.read(sdString, sizeof(sdString) - 1);
Serial.println(sdString);
myFile.close();
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Will give this as a result on my Serial monitor:
SD card is ready to use.
18-07-05,00:00,23.00,24.00,26.00,6.15⸮"
the reversed question mark and " shouldn't be there.
When a run the whole myFile.read routine twice, I get a correct output.
#include <SD.h>
File myFile;
#define pinCS 53 // SD-Card CS-pin
void setup() {
Serial.begin(9600);
pinMode(pinCS, OUTPUT);
// SD Card Initialization
if (SD.begin(pinCS)) {
Serial.println(F("SD card is ready to use."));
}
else {
Serial.println(F("SD card initialization failed"));
return;
}
char sdString[38];
myFile = SD.open("testfile.txt");
if (myFile) {
myFile.read(sdString, sizeof(sdString) - 1);
Serial.println(sdString);
myFile.close();
}
myFile = SD.open("testfile.txt");
if (myFile) {
myFile.read(sdString, sizeof(sdString) - 1);
Serial.println(sdString);
myFile.close();
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Serial monitor:
SD card is ready to use.
18-07-05,00:00,23.00,24.00,26.00,6.15
18-07-05,00:00,23.00,24.00,26.00,6.15
I'm not sure what I'm doing wrong.
I hope someone can point me in the right direction...
I've included the testfile as attachment.
testfile.txt (28.7 KB)