SD Card reading problem

Hi there

I am reading bmp files from an sd card as follows:

void setup() {
  pinMode(syncoutPin, OUTPUT);
  digitalWrite(syncoutPin, HIGH);
 
  strip.begin();
  strip.show();
  setupSDcard();

  delay(5000); 
  SendFile("test01.bmp");
  ClearStrip(0);
  delay(5000);
}


void loop() {
  SendFile("01.bmp");
  SendFile("02-01.bmp");
  SendFile("03-01.bmp");
  SendFile("04-01.bmp");

I need the file "test01.bmp" to be read just once at the beginning of the program, and the other 4 files are read in a loop afterwards.

My problem appears when I start using directories. I created in the sd card the directory "RAI", and put the files inside of this directory. Also changed the sketch to:

void setup() {
  pinMode(syncoutPin, OUTPUT);
  digitalWrite(syncoutPin, HIGH);
 
  strip.begin();
  strip.show();
  setupSDcard();

  delay(5000); 
  SendFile("RAI/test01.bmp");
  ClearStrip(0);
  delay(5000);
}


void loop() {
  SendFile("RAI/01.bmp");
  SendFile("RAI/02-01.bmp");
  SendFile("RAI/03-01.bmp");
  SendFile("RAI/04-01.bmp");

Now the file test01.bmp is not being read anymore, and the sketch simply goes forward to the next file, 01.bmp which is in the loop.

What could be happening?

What could be happening?

Probably there's an error in the code, most probably in that part that you're hiding from us.

Always post complete code! If your sketch is complex, try to reduce it to shorter sketch, that still shows the same symptoms but don't leave away parts needed for us to compile the same code.

not trying to hide anything. I simply posted what I though it would be neccesary in order to correct the mistake, but you are probably right; the mistake must be somewhere else...

here is the "sendfile" command:

void SendFile(String Filename) {
  char temp[14];
  Filename.toCharArray(temp,14);
     
  dataFile = SD.open(temp);
     
  if (dataFile) {
    ReadTheFile();
    dataFile.close();
  }  
  else {
    delay(1000);
    setupSDcard();
    return;
    }
}

Your function

void SendFile(String Filename) {
  char temp[14];
  Filename.toCharArray(temp,14);
  //...

And how long is your new filename with a directory, including the trailing nul?

You might be surprised what you get if you Serial.print(temp)

It may be better to use Filename.c_str() which returns a pointer. I don't think the SD.open() function modifies the string. Ideally, get rid of the String class in your code. It causes memory fragmentation.

will check what you said.

In the meantime (SOLVED) I found myself that the length of the buffer for "toCharArray" was to small. I put it up to 20 and started to work.

thanks for looking at it!