hi,I am totally a newer of arduino , I want to log data to SDcard. After several days' study ,I know that the SdFat library may be a good choice. then I copied some codes from website and modified them and begin my work. these codes modified are as below:
#include <TimerOne.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SdFat.h>
SdFat SD;
SdFile myFile;
void setup() {
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
Serial.println("Initializing SD card...");
if (!SD.begin(10, SPI_HALF_SPEED)) { Serial.println("initialization failed!");return; }
Serial.println("initialization done.");
}
void loop() {
int ts = 2000;
Serial.println("wolaile,wolaile--1234567812345678---1234567812345678---");
sprintf(filename2, "%0d", fileindex);
strcat(filename2, ".txt");
fileindex = fileindex + 1;
Serial.println(filename2);
Serial.println(xiestring);
filerecord();
delay(10000);
}
void filerecord()
{
Serial.println("filename2");
Serial.println(filename2);
myFile = SD.open(filename2, O_WRITE | O_CREAT | O_AT_END);
if (!myFile) { Serial.print("file open error!");}
Serial.print("Writing to test.txt...");
myFile.println("test,test,test,I just want to do test,GOD help me!");
myFile.close();
Serial.println("done.");
}
//////////////////////////////////////////////////////////////////////
these above are the SD operation parts of my code ,it does not work , even worse ,it stopped other parts of my codes from working ,I donot know why .
I am not really know the usage of "SdFat SD;" or "SdFile myFile;", I donot know much about the difference between "SdFile myFile;" and "File myFile;", it seems both of them are OK in VS2017, no warning ,no error ,compling succeed, but neither of them work.
I once succeed , i.e. the SD file creation operation had experienced some success(otherwise I may giveup , wonot come to the forum for help), after my stupid modification , it turned bad. I can not find where I badly modified .
These codes are parts of my codes ,I carefully copied to here , to ensure offering enough information to everyone to help me . Were the whole codes necessary , I will post all of them here . thank you !