yet another ....... how to store sd filenames into an array

Hi,

yet another.... how to store sd filenames into an array !!! Please bear with me I am hoping that I end up with a working example that others can use as a test and basis for development. There are many fixes but all with snippets of code that are unique to topic owner.

I am attempting to build a photoviewer with a 7 inch TFT and an Arduino Due.

At the moment I have 5 off 640 x 480 pixel .RAW files stored at the root level of an SD card in my TFT card slot ( chip select = 53). The files are called PHOTO1.RAW to PHOTO5.RAW.

I can individually display them on my TFT using a 'switch' statement e.g

myFiles.load(0, 0, 640, 480, "Photo1.RAW", 1 , 0); ( acknowledge GHL )

Modifying the 'OpenNext' example in SDfat lib, I can print to serial monitor only the RAW files, and this works !!

/*
 * Print size, modify date/time, and name for all files in root.
 */
#include <SPI.h>
#include "SdFat.h"

// SD default chip select pin.
const uint8_t chipSelect = 53;    //  Works for me !!!!!!!

char myfile[20];

// file system object
SdFat sd;

SdFile file;
//------------------------------------------------------------------------------
void setup() {

  Serial.begin(9600);
  
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }
  
   // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  // Open next file in root.  The volume working directory, vwd, is root.
  // Warning, openNext starts at the current position of sd.vwd() so a
  // rewind may be neccessary in your application.
  sd.vwd()->rewind();
  
  while (file.openNext(sd.vwd(), O_READ)) {
   
    if (  !file.isDir()) {         //    ignore the system volume
      // Indicate a directory.
      // Serial.write('/');

      file.printName(&Serial);
    
    }
    Serial.println();
    file.close();
  }
  Serial.println("Done!");
}

and output is.....

Photo2.raw
Photo3.raw
Photo1.raw
Photo4.raw
Photo5.raw
Done!

using

http://forum.arduino.cc/index.php?topic=416857.0

as a basis ( and apparently this 'worked perfectly' ...... but not for me) I have created the following but get errors on compiling. Could some please help !!!

I want to create a directory (in an array) of up to 50 filenames and then print out the filenames !!!!

#define MAX_FILES         50
#define MAX_FILE_LENGTH   13      //   8 chars  plus  4 for '.RAW' plus NULL = 13

char directory[ MAX_FILES ][ MAX_FILE_LENGTH ] = {};  //{} will null terminate all data.

#include <SPI.h>
#include "SdFat.h"

// SD default chip select pin.
const uint8_t chipSelect = 53;    //  Works for me !!!!!!!

// file system object
SdFat sd;

SdFile file;
//------------------------------------------------------------------------------
void setup() {
   int fileCounter,i;

   fileCounter =0;
   Serial.begin(9600);
  
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }
  
   // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  // Open next file in root.  The volume working directory, vwd, is root.
  // Warning, openNext starts at the current position of sd.vwd() so a
  // rewind may be neccessary in your application.
  sd.vwd()->rewind();
  
  while (file.openNext(sd.vwd(), O_READ)) {     //  Have not written any test for greater than 50 files as yet
   
    if (  !file.isDir()) {         //    ignore the system volume
      // Indicate a directory.
      // Serial.write('/');

     // file.printName(&Serial);
      file.getFilename( directory[fileCounter] );
      fileCounter++;
    }
    Serial.println();
    file.close();
  }
    Serial.println("Done reading!");


    //  print out  directory

    for ( i = 0 ; i < fileCounter ; i++){
      Serial.print("file ");
      Serial.print(i);
      Serial.print(" ");
      Serial.print( directory[fileCounter] );
    }
    Serial.println("Done printing!");


 
  
}



//------------------------------------------------------------------------------
void loop() {}

As before I cannot get the above to compile beyond the char directory declaration. Please assume I struggle with more than 1 dimension of char arrays and SD calls . I have already noted the directory array is 2 dimensional and all references to it have only one parameter !!

Could someone please help correct the code. Please ignore elegance and RAM considerations, I would just like to understand why the code does not work.

Thanks

Hi,

Just moved forward a bit ... I had to manually re-type the following which was originally cut and paste from another topic

#define MAX_FILES 50
#define MAX_FILE_LENGTH 13 // 8 chars plus 4 for.RAW plus NULL

char directory[ MAX_FILES ][ MAX_FILE_LENGTH ];

was getting error 302 !! which meant I may have had some hidden characters in the cut and paste.

So compile errors now at ......

file.getFilename( directory[fileCounter] );