Detect Files on a Micro-SD Card with a Seeeduino Xiao

Description: A Micro-SD Card Module connected to a Seeeduino Xiao detects any files on the micro-sd card and displays them on the Serial Monitor.

Detect Files on a Micro-SD Card with Seeeduino Xiao

Note: D3 is the CS Pin for the Seeeduino Xiao. Not all Micro-SD cards may work, especially the older ones, so try out a few different brands. Also, make sure to open the Serial Monitor and set the Baud Rate to 9600 in order to see the incoming data as in the picture below:

Detect Files with Micro-SD Card Module on Serial Monitor

Supplies:

1 –  Breadboard 400 Points
1 – Seeeduino Xiao
1 – Micro-SD Card Module   >> Link <<

Arduino Code:

#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

void setup() {
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
  ; // wait for serial port to connect.

}

  Serial.println("\nInitializing SD card_");

  if (!card.init()) {
    Serial.println("Initialization failed.");
  while (1);
  
}
else
{
  
  Serial.println();
  Serial.println("Micro-SD Card detected!");
  
}

  Serial.println();
  Serial.print("Card 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");
}

  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  while (1);
}

  uint32_t volumesize;
  Serial.print("Volume type is: FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB)
  volumesize /= 1024;
  Serial.print("Volume size (GB): ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card: ");
  root.openRoot(volume);

  // list all files in the card
  root.ls(LS_R);

}

void loop() {

}

Leave a Comment

− 3 = 7