This SD card is connected to SparkFun's SD card breakout through a breadboard. For the most part it works well, but randomly it gives me this error "[ 41310][E][vfs_api.cpp:332] VFSFileImpl(): fopen(/sd/text3.txt) failed". In 50 lines, it gives me this error in 13 of them, but successfully saves the remaining ones. This is the code pertaining to this error. The SPI.begin and SD.begin are done in the main.cpp folder, and are not part of the issue.
- [/char str[70];
- std::string txt="";
- char* fileName = "/text3.txt";
- openFilew(fileName);
- writeFile("Test1");
- closeFile();
- for(int i=1;i<51;i++){
- openFilea(fileName);
- txt="\nDistance=";
- Dist.whatif(down);
- delay(500);
- c[i]=Dist.dist();
- txt += std::to_string(c[i]);
- ;
- txt+="; Conductivity =";
- //c[i] = cond.voltage(num5);
- d[i] = cond.voltage(num5*4);
- txt+=std::to_string(d[i]); //num5
- txt+="; ";
- txt+=std::to_string(i);
- strcpy(str,txt.c_str());
- Serial.println(str);
- maxi = max(c[i-1],c[i]);
- maxi2=max(d[i-1],d[i]);
- writeFile(str);
- closeFile();]