ESP32 devKitC v4: Can't open SD card arbitrarily

RodrigoRyter
Posts: 1
Joined: Mon May 06, 2024 1:55 pm

ESP32 devKitC v4: Can't open SD card arbitrarily

Postby RodrigoRyter » Mon May 06, 2024 2:07 pm

I'm currently doing a project that involves receiving an analog input from an IR distance sensor and a "conductivity sensor" everytime I move a step motor a few steps and saving those values on a line of my SD card.
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.
  1. [/char str[70];
  2.         std::string txt="";
  3.         char* fileName = "/text3.txt";
  4.         openFilew(fileName);
  5.         writeFile("Test1");
  6.         closeFile();
  7.        
  8.         for(int i=1;i<51;i++){
  9.             openFilea(fileName);
  10.             txt="\nDistance=";
  11.             Dist.whatif(down);
  12.             delay(500);
  13.             c[i]=Dist.dist();
  14.             txt += std::to_string(c[i]);
  15.             ;
  16.             txt+="; Conductivity =";
  17.             //c[i] = cond.voltage(num5);
  18.             d[i] = cond.voltage(num5*4);
  19.             txt+=std::to_string(d[i]); //num5
  20.             txt+="; ";
  21.             txt+=std::to_string(i);
  22.             strcpy(str,txt.c_str());
  23.             Serial.println(str);
  24.             maxi = max(c[i-1],c[i]);
  25.             maxi2=max(d[i-1],d[i]);
  26.             writeFile(str);
  27.             closeFile();]

Who is online

Users browsing this forum: No registered users and 54 guests