LoginSignup
0
0

More than 5 years have passed since last update.

wemos d1でsd-card

Posted at

概要

wemosでsd-cardやってみた。

写真

CIMG2651.JPG

回路図

sdc.JPG

結果

sd.JPG

サンプルコード

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

//sdi - pin 11
//sdo - pin 12
//clk - pin 13
//cs  - pin 4

Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup()
{
    Serial.begin(115200);
    while (!Serial)
    {
        ;
    }
    Serial.print("\nInitializing SD card...");
    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.");
    }
    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");
    }
    if (!volume.init(card))
    {
        Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
        return;
    }
    uint32_t volumesize;
    Serial.print("\nVolume type is FAT");
    Serial.println(volume.fatType(), DEC);
    Serial.println();
    volumesize = volume.blocksPerCluster();
    volumesize *= volume.clusterCount();
    volumesize *= 512;
    Serial.print("Volume size (bytes): ");
    Serial.println(volumesize);
    Serial.print("Volume size (Kbytes): ");
    volumesize /= 1024;
    Serial.println(volumesize);
    Serial.print("Volume size (Mbytes): ");
    volumesize /= 1024;
    Serial.println(volumesize);
    Serial.println("\nFiles found on the card (name, date and size in bytes): ");
    root.openRoot(volume);
    root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void)
{
}



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0