read contents of SD with root.ls()

Hi,

I am trying to display the contents of an SD card on a TFT. Arduino nano with Adafruit_GFX, ST7735, SPI and SD libs loaded.

In the code below, everything works ok, except the list of files is not shown on the TFT, but it is shown on the serial monitor, last line of code I suspect.

Any help is appreciated.

void SDCard() {
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.print("\nInitializing SD card...");
  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }
  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }
  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  tft.setCursor(0, 0);
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
  tft.setTextSize(1);
  tft.print("\nVolume type is FAT");
  Serial.print("\nVolume type is FAT");
  tft.print(volume.fatType(), DEC);
  Serial.println(volume.fatType(), DEC);
  tft.println();
  Serial.println();
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  tft.print("Volume size (bytes): ");
  Serial.print("Volume size (bytes): ");
  tft.println(volumesize);
  Serial.println(volumesize);
  tft.println("Volume size (Kbytes): ");
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  tft.println(volumesize);
  Serial.println(volumesize);
  tft.println("Volume size (Mbytes): ");
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  tft.println(volumesize);
  Serial.println(volumesize);
  tft.println("\nFiles found on the card (name, date and size in bytes): ");
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}
Output on serial port...

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3430940672
Volume size (Kbytes): 3350528
Volume size (Mbytes): 3272
TORCH_~1.GCO  2017-07-02 18:41:12 20809989
TORCH_~1.X3G  2017-07-02 18:41:48 23425088
SYSTEM~1/     2017-08-27 01:57:44
  INDEXE~1      2017-08-27 01:57:44 76
  WPSETT~1.DAT  2017-08-27 01:57:44 12
CHERRY~1.GCO  2017-09-04 08:10:10 2577462
CHERRY~1.X3G  2017-09-04 08:10:16 2932156

root.ls(LS_R | LS_DATE | LS_SIZE);

This function hasn't a clue how to write to a tft, or that you even want it to. What that function does is dirt simple. Just implement that functionality in your code.