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);
}