# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/093/587/medium800/adafruit_products_4682-01.jpg?1595961694)

Micro SD cards and microcontrollers go together like micro-peanutbutter-and-jelly: SD cards are inexpensive, durable, easy to find at any shop, come in many sizes and can plug into any computer using a common SD card reader. That makes them perfect for microcontroller storage and retrieval - whether it's images, fonts, GIFs, audio files, or sensor logs.

Wiring up SD cards when you're starting out is super easy - you just [pick up one of Adafruit's SPI-to-SD breakout boards](https://www.adafruit.com/product/254), [wire it to an SPI port and a chip select pin and with a little library work you're reading and writing files](https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial). That's all good and great but you may eventually find that your SD card project is a little...slow. **Even with fast SPI ports, there's only one data pin, which can make it hard to stream large files fast.**

If you've hit that limit, [this new breakout](https://www.adafruit.com/product/4682) is designed to help. Unlike previous adapters, it is not fixed for SPI usage, and can be used with SDIO hardware support. SDIO is a multi-pin data protocol (up to 4 data pins at once!) SDIO also tends to be able to be clocked faster than SPI. Of course, your speeds will vary depending on what microcontroller you hook it up to. When we used SDIO instead of SPI on CircuitPython with the [SAMD51 Grand Central](https://www.adafruit.com/product/4064), we got a speed increase of about 200% when reading data off the card

![](https://cdn-learn.adafruit.com/assets/assets/000/093/588/medium800/adafruit_products_4682-00.jpg?1595961732)

 **You will need to verify that your microcontroller has SDIO support and you have SDIO firmware/library support as wel** l. SDIO is usually available on higher end chips, and you may need to use some specific pins. You can _still_ use this for SPI mode, but it does not have level shifters, so it's not for use with 5V microcontrollers.

**For use with 3V power and logic microcontrollers only!** The SDIO pins are bi-directional, and we've never seen a 5V microcontroller with SDIO, so there's no level shifting or power regulator.

The breakout comes with a bit of header so you can use in a breadboard. It doesn't come with the micro SD card itself!

![](https://cdn-learn.adafruit.com/assets/assets/000/093/601/medium800/adafruit_products_4682-03.jpg?1596049568)

[Secure Digital](https://en.wikipedia.org/wiki/Secure_Digital), or SD, cards and tiny microSD cards are an inexpensive and ubiquituous means of adding lots of storage to devices. For a few dollars you can have gigabytes of storage at your fingertips (smaller than your fingertips actually!). With CircuitPython boards you typically have a very limited amount of flash memory to store code and data.

Wouldn't it be nice if you could connect a microSD card to a Python board and expand its storage? &nbsp;It turns you can use microSD cards with CircuitPython! In fact some boards like the Metro M4 Grand Central come with microSD card support built-in, and for other boards like the Feather M4 Express family they can easily be connected to a microSD card that expands their storage.

![](https://cdn-learn.adafruit.com/assets/assets/000/093/602/medium800/adafruit_products_4682-02.jpg?1596049600)

WIth the Adafruit MicroSD SPI or SDIO Card Breakout Board, you can add an SD card to your project using the common SPI interface or the higher performance SDIO interface.

This guide also shows how to use a microSD card to store files for a CircuitPython board. Specifically using&nbsp; a microSD card with CircuitPython boards like Feather M0 Adalogger, Grand Central M4, ItsyBitsy M4, and others will be covered in this guide. You'll learn how to connect a microSD card to the board and mount it as a new filesystem that store code & data.

Starting with CircuitPython 6, there are two new modules to improve the performance of SD cards using SDIO.

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/093/589/medium800/adafruit_products_4682-04-crop.jpg?1595962579)

 **Power Pins**

- **3V** - This is the power pin. MicroSD cards must use 3.3V, so take care to only hook 3.3V to this pin. Hooking 5V or VBAT to this pin will damage your microSD card.
- **GND** - common ground for power and logic.

**Common Logic Pins**

- **DET** - Detect whether a microSD card is inserted.&nbsp; This pin is connected to **GND** internally when there's no card, but when one is inserted it is pulled up to **3V** with a 4.7kΩ resistor.&nbsp; That means that when the pin's logic level is **False** there's no card and when it's **True** there is.

**SPI Logic Pins**

If you're using SPI to connect to your SD cards, the pins have the following functions:

- **CLK** - This is the SPI **Cl** oc **k** pin / **SCK S** erial **C** loc **k** , and is an input to the SD card.
- **SO** - this is the **S** erial **O** ut / **M** icrocontroller **I** n **S** erial **O** ut pin, for data sent from the SD card to your processor.
- **SI** - this is the **S** erial **I** n / **M** icrocontroller **O** ut **S** erial **I** n pin, for data sent from your processor to the SD card. Its an input to the chip and can use 3V logic only.
- **CS** - this is the **C** hip **S** elect pin, drop it low to start an SPI transaction. Its an input to the chip and can use 3V logic only.

Pull ups are provided on all SPI logic pins.

**SDIO Logic Pins**

If you're using SDIO to connect to your SD cards, the pins have the following functions:

- **CLK** - The SDIO clock pin. A clock signal is sent by the microcontroller to the SD card on this pin.
- **CMD** - A bidirectional pin for communication between the microcontroller and the SD card, used for commands and information.
- **4 Data pins** - Four bidirectional pins for communication between the microcontroller and the SD card, used for transferring bulk data. Take care to wire these in the correct order!&nbsp; The silk screen legends read:&nbsp; **D0** , **D1** , **DAT2** , **D3**.

Pull ups are provided on all SDIO logic pins.

Note that when inserted, the SD card extends slightly beyond the edge of the PCB.&nbsp; Check out the mechanical drawing on the [Downloads page](https://learn.adafruit.com/adafruit-microsd-spi-sdio/downloads).

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## CircuitPython

Warning: 

[Follow these steps to create the /sd directory](https://learn.adafruit.com/adafruit-memento-camera-board/circuitpython-memento-starter-projects)
Are you new to using CircuitPython? No worries, [there is a full getting started guide here](https://learn.adafruit.com/welcome-to-circuitpython "Welcome to CircuitPython").

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython.&nbsp;[You can learn about Mu and installation in this tutorial](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor "Mu tutorial").

# Preparing your SD card

If you bought an SD card, chances are it's already pre-formatted with a FAT filesystem. However you may have problems with how the factory formats the card, or if it's an old card it needs to be reformatted. CircuitPython supports both **FAT16** and **FAT32** filesystems.

It's **always** good idea to format the card before using, even if it's new! Note that formatting will erase the card, so save anything you want first.

Warning: 

[Download the official SD Formatter software](https://www.sdcard.org/downloads/formatter/)
The official SD formatter is available from [https://www.sdcard.org/downloads/formatter/](https://www.sdcard.org/downloads/formatter/)

Download it and run it on your computer, there's also a manual linked from that page for additional instructions.

# General Steps for Accessing SD Cards

The following pages will show all the steps to set up an SD card, including wiring information if applicable. They all follow the same general structure:

1. If necessary, create an `SPI` bus object connecting to the card (cards attached by SDIO do not have a separate bus object)
2. Construct an `SDCard` object
3. Create a `vfs` (virtual filesystem) object
4. "Mount" the `vfs` object to make the SD card's files appear so they can be accessed by functions like `open()`

## Tip: Create a **mount\_sd.py** file

If you put the exact lines necessary to mount the sd card in a separate Python file in **CIRCUITPY** as **mount\_sd.py** , you can easily call it from the REPL or from **code.py** with `import`:

```python
import mount_sd
```

In the examples, we'll assume you have already created a **mount\_sd.py** file.

Warning: 

# sdcardio: For SD cards on SPI interfaces

`sdcardio` is the module for SD cards that use an SPI interface. Unless otherwise noted, it's a good bet that a microcontroller SD card interface uses SPI. SPI uses 4 signal wires and can function at rates from 400kHz up to multiple MHz. Under some circumstances, multiple SPI devices can share 3 out of the 4 pins.

&nbsp;

# sdioio: For SD cards on SDIO interfaces

`sdioio` is the module for SD cards that use an SDIO interface. A few specific boards have SDIO interfaces available. SDIO uses at least 3 signal wires (CMD, CLK, and DATA0), but can use additional data wires (DATA1, DATA2, DATA3). SDIO operates at 25MHz or 50MHz, and it can transfer 1 or 4 bits at a time. However, in practice, it offers around 1.5 to 2x the speed of SPI when reading from an SD card.

The built in micro SD slot on the STM32F405 Feather is connected using SDIO. The Grand Central M4 can connect the SD card using SDIO or SPI, depending which pins are used.

&nbsp;

# adafruit\_sdcard.py: For legacy uses

`adafruit_sdcard` is covered in [its own guide](https://learn.adafruit.com/micropython-hardware-sd-cards/hardware). There are still some cases where you should use `adafruit_sdcard`:

- You're not ready to upgrade to CircuitPython 6
- Some boards without much capacity omit `sdcardio`, but you can put `adafruit_sdcard` in **CIRCUITPY**. This applies to all boards with the SAM D21 microcontroller.

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Using sdcardio

Warning: 

[Follow these steps to create the /sd directory](https://learn.adafruit.com/adafruit-memento-camera-board/circuitpython-memento-starter-projects)
Info: 

 **Use the code and wiring examples in this section if**  **these conditions are met:**

- Your SD card slot uses the SPI bus to connect to the microcontroller (If it uses SDIO, go to [the pages for `sdioio`](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/using-sdioio))
- Your CircuitPython board supports the `sdcardio` module. (If not, go to [the pages for `adafruit_sdcard`](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/using-adafruit_sdcard))
- Your CicuitPython version supports the `sdcardio` module.&nbsp; Only CircuitPython 6 and newer have sdcardio.&nbsp; (If not, go to [the pages for `adafruit_sdcard`](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/using-adafruit_sdcard))

Primary: 

The following section will show how to initialize the SD card and read & write data to it. You'll want to put the correct lines to initialize it in **mount\_sd.py** on your **CIRCUITPY** drive. For specific wiring information and exact **mount\_sd.py** files for several different boards, check out the following pages.

## Initialize & Mount SD Card Filesystem

Before you can use the microSD card you need to initialize its SPI connection and mount its filesystem. First import all the modules we'll need:

```python
import board
import busio
import sdcardio
import storage
```

Next create the SPI bus and a digital output for the microSD card's chip select line (be sure to select the right pin names for your wiring):

```python
# Use the board's primary SPI bus
spi = board.SPI()
# Or, use an SPI bus on specific pins:
#spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)

# For breakout boards, you can choose any GPIO pin that's convenient:
cs = board.D10
# Boards with built in SPI SD card slots will generally have a
# pin called SD_CS:
#cs = board.SD_CS
```

Note that when you use `sdcardio`, `cs` is a `Pin` object, not a `DigitalInOut` object. If you change your code to use `adafruit_sdcard`, you need to use a `DigitalInOut` object instead.

At this point you're ready to create the microSD card object and the filesystem object:

```python
sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
```

Notice the `sdcardio` module has a `SDCard` class which contains all the logic for talking to the microSD card at a low level. This class needs to be told the SPI bus and chip select pin in its constructor.

After a `SDCard` instance is created it can be passed to the `storage` module's `VfsFat` class. This class has all the logic for translating CircuitPython filesystem calls into low level microSD card access. Both the&nbsp;`SDCard` and&nbsp;`VfsFat` class instances are required to mount the card as a new filesystem.

Finally you can mount the microSD card's filesystem into the CircuitPython filesystem. For example to make the path **/sd** on the CircuitPython filesystem read and write from the card run this command:

```python
storage.mount(vfs, "/sd")
```

At this point, you can read and write to the SD card using common Python functions like `open`, `read`, and `write`. The filenames will all begin with `"/sd/"` to differentiate them from the files on the **CIRCUITPY** drive. If you're not familiar, here's an overview.

## Reading & Writing Data

Once the microSD card is mounted inside CircuitPython's filesystem you're ready to read and write data from it&nbsp; Reading and writing data is simple using Python's file operations like [open](https://docs.python.org/3/library/functions.html#open), [close](https://docs.python.org/3/library/io.html#io.IOBase.close), [read](https://docs.python.org/3/library/io.html#io.RawIOBase.read), and [write](https://docs.python.org/3/library/io.html#io.RawIOBase.write). The beauty of CircuitPython and MicroPython is that they try to be as similar to desktop Python as possible, including access to files.

For example to create a file and write a line of text to it you can run:

```python
with open("/sd/test.txt", "w") as f:
    f.write("Hello world!\r\n")
```

Notice the `with` statement is used to create a context manager that opens and automatically closes the file. This is handy because with file access you Python you **must** close the file when you're done or else all the data you thought was written might be lost! &nbsp;

The `open` function is used to open the file by telling it the path to it, and the mode (w for writing). Notice the path is under **/sd** , **/sd/test.txt**. This means the file will be created on the microSD card that was mounted as that path.

Inside the context manager you can access the `f` variable to operate on the file while it's open. The `write` function is called to write a line of text to the file. Notice that unlike a `print` statement you need to end the string passed to write with explicit carriage returns and new lines.

You can also open a file and read a line from it with similar code:

```python
with open("/sd/test.txt", "r") as f:
    print("Read line from file:")
    print(f.readline(), end='')
```

When reading a line from a file with `readline`, the newline character `'\n'` at the end of the line is included. By printing with `end=''`, the newline normally added by print is skipped. Otherwise, when reading back the file, it would appear that there were extra blank lines after every line of the file.

If you wanted to read and print all of the lines from a file you could call `readline` in a loop. Once `readline` reaches the end of the file it will return an empty string&nbsp;so you know when to stop:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    line = f.readline()
    while line != '':
        print(line, end='')
        line = f.readline()
```

You can also just use the open file object in a `for` loop. Each time the loop runs, the loop variable will be assigned the content of the next line of the file:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    for line in f:
        print(line, end='')
```

Finally one other very common file scenario is opening a file to add new data at the end, or append data. This works exactly the same as in Python and the `open` function can be told you'd like to append instead of erase and write new data (what normally happens with the `w` option for `open`). For example to add a line to the file:

```python
with open("/sd/test.txt", "a") as f:
    f.write("This is another line!\r\n")
```

Notice the `a` option in the open function--this tells Python to add data at the end of the file instead of erasing it and starting over at the top. Try reading the file with the code above to see the new line that was added!

Those are the basics to manipulating files on microSD cards with CircuitPython!&nbsp; Once you have it working, put the correct lines in **mount\_sd.py** in **CIRCUITPY** , then continue learning by checking out the example pages to print directory listings, log sensor data, play MP3 files and display bitmap graphics.

# Example complete **mount\_sd.py**

This example works on the ItsyBitsy M4 Express together with the Adafruit MicroSD Breakout Board:

```python
import board
import busio
import sdcardio
import storage

spi = board.SPI()
cs = board.D10

sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

 **Your board may be different**. Refer to the following pages for more details.

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## ItsyBitsy M4 Express + Breakout

Info: 

Ready to do a little wiring?&nbsp; Almost any Adafruit CircuitPython board will connect to the MicroSD Breakout Board using SPI. The following is an example using the Itsy BItsy M4 express.

- **Board 3V** to **breakout 3V via supply rail**
- **Board GND** to **breakout GND via supply rail**
- **Board MI (**or **MISO)** to **breakout SO**
- **Board MO (**or **MOSI)** to **breakout SI**
- **Board SCK** to **breakout CLK**
- **Board D10** to **breakout CS**

The example below uses D10, but you can use any available digital pin instead. Change the **mount\_sd.py** code below to use the pin you selected instead of `board.D10`.

![adafruit_products_itsy-sd_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/093/581/medium640/adafruit_products_itsy-sd_bb.png?1595962247)

The ItsyBitsy and the MicroSD breakout are a great way to have SD card storage in a small footprint, but these instructions will work with just about any Adafruit Feather too. Just follow the fritzing diagram and then put the following in **mount\_sd.py** :

```python
import board
import busio
import sdcardio
import storage

spi = board.SPI()
cs = board.D10     # Use the pin you wired to the breakout CS

sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

The default communication rate is 8MHz, which works with most SD cards. A higher or lower rate can be supplied with `sdcardio.SDCard(spi, cs, baudrate=...)` but the limitation depends on

- the specific microcontroller's SPI interface
- the specific SD card's operating characteristics
- the wiring, especially if a breadboard or jumper wires are involved

### Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!

[Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!](https://www.adafruit.com/product/4682)
Micro SD cards and microcontrollers go together like micro-peanutbutter-and-jelly: SD cards are inexpensive, durable, easy to find at any shop, come in many sizes and can plug into any computer using a common SD card reader. That makes them perfect for microcontroller storage and retrieval -...

In Stock
[Buy Now](https://www.adafruit.com/product/4682)
[Related Guides to the Product](https://learn.adafruit.com/products/4682/guides)
![Angled Shot of the Adafruit Micro SD SPI or SDIO Card Breakout Board](https://cdn-shop.adafruit.com/640x480/4682-05.jpeg)

### Adafruit ItsyBitsy M4 Express featuring ATSAMD51

[Adafruit ItsyBitsy M4 Express featuring ATSAMD51](https://www.adafruit.com/product/3800)
What's smaller than a Feather but larger than a Trinket? It's an **Adafruit ItsyBitsy M4 Express** featuring the **Microchip ATSAMD51**! Small, powerful, with a ultra fast ATSAMD51 Cortex M4 processor running at 120 MHz - this microcontroller board is perfect...

In Stock
[Buy Now](https://www.adafruit.com/product/3800)
[Related Guides to the Product](https://learn.adafruit.com/products/3800/guides)
![Adafruit ItsyBitsy M4 Express featuring ATSAMD51 connected to a small breadboard. ](https://cdn-shop.adafruit.com/product-videos/640x480/3800-04.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Grand Central M4 Express

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/093/483/medium800/circuitpython_IMG_20200724_094803.jpg?1595602165)

The Adafruit Grand Central M4 Express has a built-in SD card connected to the SPI bus, so no wiring or soldering is needed!

To mount the SD card, use the following code. Remember to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with `import mount_sd`.

```python
import board
import busio
import sdcardio
import storage

spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
cs = board.SD_CS

sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

### Adafruit Grand Central M4 Express featuring the SAMD51

[Adafruit Grand Central M4 Express featuring the SAMD51](https://www.adafruit.com/product/4064)
Are you ready? Really ready? Cause here comes the **Adafruit Grand Central** featuring the **Microchip ATSAMD51**. This dev board is so big, it's not named after a Metro train, it's a whole freakin' _station_!

This board is like a freight...

In Stock
[Buy Now](https://www.adafruit.com/product/4064)
[Related Guides to the Product](https://learn.adafruit.com/products/4064/guides)
![Angled Shot of the Adafruit Grand Central M4 Express featuring the SAMD51.](https://cdn-shop.adafruit.com/640x480/4064-05.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## PyGamer

Info: 

The PyGamer has a built-in SD card connected to a SPI bus, so no wiring or soldering is needed!

To mount the SD card, use the following code.&nbsp; Remember, to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with `import mount_sd`.

```python
import board
import sdcardio
import storage

spi = board.SPI()
cs = board.SD_CS

sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

### Adafruit PyGamer Starter Kit

[Adafruit PyGamer Starter Kit](https://www.adafruit.com/product/4277)
**Please note: you may get a royal blue _or_ purple case with your starter kit (they're both lovely colors)**

What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4277)
[Related Guides to the Product](https://learn.adafruit.com/products/4277/guides)
![Adafruit PyGamer Starter Kit with PCB, enclosure, buttons, and storage bag](https://cdn-shop.adafruit.com/640x480/4277-08.jpg)

### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the **Adafruit PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
![Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.](https://cdn-shop.adafruit.com/640x480/4242-00.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Feather Sense + Adalogger FeatherWing

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/093/484/medium800/circuitpython_IMG_20200724_103307.jpg?1595604903)

With all its built-in sensors and battery power, the Feather M4 Sense is great for data-logging projects. Stacking headers or FeatherWing Doublers need a little soldering but no custom wiring.

- Plug the FeatherWing into the Feather.

You can also place them side by side on a FeatherWing Doubler.

![adafruit_products_stack-sense-wing_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/093/591/medium640/adafruit_products_stack-sense-wing_bb.png?1595965126)

Don't forget that the Adalogger FeatherWing has a [Real Time Clock (RTC)](https://learn.adafruit.com/adafruit-pcf8523-real-time-clock/rtc-with-circuitpython) so you can even timestamp your logs!

To mount the SD card, use the following code.&nbsp; Remember, to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with `import mount_sd`.

```python
import board
import busio
import sdcardio
import storage

spi = board.SPI()
cs = board.D10

sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
![Angled shot of blue, rectangular, microcontroller.](https://cdn-shop.adafruit.com/640x480/4516-06.jpg)

### Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards

[Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards](https://www.adafruit.com/product/2922)
A Feather board without ambition is a Feather board without FeatherWings! This is the **Adalogger FeatherWing** : it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board. Using our [Feather...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2922)
[Related Guides to the Product](https://learn.adafruit.com/products/2922/guides)
![Adalogger FeatherWing with Real time clock and SD card slot.](https://cdn-shop.adafruit.com/640x480/2922-11.jpg)

### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
![Double prototyping feather wing PCB with socket headers installed](https://cdn-shop.adafruit.com/640x480/2890-01.jpg)

### Stacking Headers for Feather - 12-pin and 16-pin female headers

[Stacking Headers for Feather - 12-pin and 16-pin female headers](https://www.adafruit.com/product/2830)
These two **Female Stacking Headers** alone are, well, lonely. But pair them with any of our [Feather](https://www.adafruit.com/categories/777) boards and you're in business!

What do they do? They stack. Put the headers through your Feather and then you can...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2830)
[Related Guides to the Product](https://learn.adafruit.com/products/2830/guides)
![Angled shot of a Stacking Headers for Feather - 12-pin and 16-pin female headers. ](https://cdn-shop.adafruit.com/640x480/2830-08.jpg)

### CR1220 12mm Diameter - 3V Lithium Coin Cell Battery

[CR1220 12mm Diameter - 3V Lithium Coin Cell Battery](https://www.adafruit.com/product/380)
These are the highest quality & capacity batteries, the same as shipped with the iCufflinks,&nbsp;iNecklace, Datalogging and GPS Shields, GPS HAT, etc. One battery per order (you'll want one battery per cufflink or pendant.)  
  
Brand may vary but all battery brands are verified...

In Stock
[Buy Now](https://www.adafruit.com/product/380)
[Related Guides to the Product](https://learn.adafruit.com/products/380/guides)
![Angled shot of CR1220 12mm Diameter - 3V Lithium Coin Cell Battery - CR1220.](https://cdn-shop.adafruit.com/640x480/380-01.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Python Docs

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Using sdioio

Warning: 

[Follow these steps to create the /sd directory](https://learn.adafruit.com/adafruit-memento-camera-board/circuitpython-memento-starter-projects)
Info: 

 **Use the code and wiring examples in this section if these conditions are met:**

- Your SD card slot uses the SDIO bus to connect to a 3V microcontroller (If it uses SPI, go to [the pages for `sdcardio`](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/using-sdcardio))
- Your CircuitPython board supports the `sdioio` module. (If not, you may be able to use `bitbangio` and `adafruit_sdcard`)

The following section will show how to initialize the SD card and read & write data to it.&nbsp; You'll want to put the correct lines to initialize it in **mount\_sd.py** on your **CIRCUITPY** drive. For specific wiring information and exact **mount\_sd.py** files for several different boards, check out the following pages.

## Initialize & Mount SD Card Filesystem

Before you can use the microSD card you need to initialize its SDIO connection and mount its filesystem. First import all the modules we'll need:

```python
import board
import sdioio
import storage
```

At this point you're ready to create the microSD card object and the filesystem object:

```python
sdcard = sdioio.SDCard(
    clock=board.SDIO_CLOCK,
    command=board.SDIO_COMMAND,
    data=board.SDIO_DATA,
    frequency=25000000)

vfs = storage.VfsFat(sdcard)
```

Notice the `sdioio` module has a `SDCard` class which contains all the logic for talking to the microSD card at a low level. This class needs to be told the pins to use in its constructor.&nbsp; `SDIO_DATA` is actually a tuple of up to 4 data pins.

After a `SDCard` instance is created, it can be passed to the `storage` module `VfsFat` class. This class has all the logic for translating CircuitPython filesystem calls into low level microSD card access. Both the&nbsp;`SDCard` and&nbsp;`VfsFat` class instances are required to mount the card as a new filesystem.

Finally you can mount the microSD card filesystem into the CircuitPython filesystem. For example to make the path **/sd** on the CircuitPython filesystem read and write from the card run this command:

```python
storage.mount(vfs, "/sd")
```

At this point, you can read and write to the SD card using common Python functions like `open`, `read`, and `write`.&nbsp; The filenames will all begin with `"/sd/"` to differentiate them from the files on the **CIRCUITPY** drive. If you're not familiar, here's an overview.

## Reading & Writing Data

Once the microSD card is mounted inside CircuitPython's filesystem you're ready to read and write data from it&nbsp; Reading and writing data is simple using Python's file operations like [open](https://docs.python.org/3/library/functions.html#open), [close](https://docs.python.org/3/library/io.html#io.IOBase.close), [read](https://docs.python.org/3/library/io.html#io.RawIOBase.read), and [write](https://docs.python.org/3/library/io.html#io.RawIOBase.write). The beauty of CircuitPython and MicroPython is that they try to be as similar to desktop Python as possible, including access to files.

For example to create a file and write a line of text to it you can run:

```python
with open("/sd/test.txt", "w") as f:
    f.write("Hello world!\r\n")
```

Notice the `with` statement is used to create a context manager that opens and automatically closes the file. This is handy because with file access you Python you **must** close the file when you're done or else all the data you thought was written might be lost! &nbsp;

The `open` function is used to open the file by telling it the path to it, and the mode (w for writing). Notice the path is under **/sd** , **/sd/test.txt**. This means the file will be created on the microSD card that was mounted as that path.

Inside the context manager you can access the `f` variable to operate on the file while it's open. The `write` function is called to write a line of text to the file. Notice that unlike a `print` statement you need to end the string passed to write with explicit carriage returns and new lines.

You can also open a file and read a line from it with similar code:

```python
with open("/sd/test.txt", "r") as f:
    print("Read line from file:")
    print(f.readline(), end='')
```

When reading a line from a file with `readline`, the newline character `'\n'` at the end of the line is included. By printing with `end=''`, the newline normally added by print is skipped. Otherwise, when reading back the file, it would appear that there were extra blank lines after every line of the file.

If you wanted to read and print all of the lines from a file you could call `readline` in a loop. Once `readline` reaches the end of the file it will return an empty string&nbsp;so you know when to stop:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    line = f.readline()
    while line != '':
        print(line, end='')
        line = f.readline()
```

You can also just use the open file object in a `for` loop. Each time the loop runs, the loop variable will be assigned the content of the next line of the file:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    for line in file:
        print(line, end='')
```

Finally one other very common file scenario is opening a file to add new data at the end, or append data. This works exactly the same as in Python and the `open` function can be told you'd like to append instead of erase and write new data (what normally happens with the `w` option for `open`). For example to add a line to the file:

```python
with open("/sd/test.txt", "a") as f:
    f.write("This is another line!\r\n")
```

Notice the `a` option in the open function--this tells Python to add data at the end of the file instead of erasing it and starting over at the top. Try reading the file with the code above to see the new line that was added!

Those are the basics to manipulating files on microSD cards with CircuitPython!&nbsp; Once you have it working, put the correct lines in **mount\_sd.py** in **CIRCUITPY** , then continue learning by checking out the example pages to print directory listings, log sensor data, play MP3 files and display bitmap graphics.

# Example complete **mount\_sd.py**

This example is for Grand Central M4 Express with the "SPI or SDIO Breakout", using the SDIO connection:

```python
import board
import sdioio
import storage

sdcard = sdioio.SDCard(
    clock=board.SDIO_CLOCK,
    command=board.SDIO_COMMAND,
    data=board.SDIO_DATA,
    frequency=25000000)

vfs = storage.VfsFat(sdcard)

storage.mount(vfs, "/sd")
```

Your board may be different. Refer to the following pages for more details.

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Grand Central M4 Express + SDIO Breakout

Info: 

The Adafruit Grand Central M4 Express supports SDIO mode with the SDIO Breakout Board.&nbsp; First, wire the two together as shown:

- **Board 3.3** to **breakout 3V**
- **Board GND** to **breakout GND**
- **Board D32** to **breakout CLK**  
- **Board D33** to **breakout CMD**
- **Board D8** to **breakout D0**
- **Board D29** to **breakout D1**
- **Board D20** to **breakout DAT2**
- **Board D21** to **breakout D3**

![adafruit_products_gcm4-sdio-try3_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/093/607/medium640/adafruit_products_gcm4-sdio-try3_bb.png?1596119645)

To mount the SD card, use the following code.&nbsp; Remember to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with import `mount_sd`.

```python
import board
import sdioio
import storage

sdcard = sdioio.SDCard(
    clock=board.SDIO_CLOCK,
    command=board.SDIO_COMMAND,
    # Note that board.SDIO_DATA is a tuple of four pins, not a single pin.
    data=board.SDIO_DATA,
    frequency=25000000)

vfs = storage.VfsFat(sdcard)

storage.mount(vfs, "/sd")
```

### Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!

[Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!](https://www.adafruit.com/product/4682)
Micro SD cards and microcontrollers go together like micro-peanutbutter-and-jelly: SD cards are inexpensive, durable, easy to find at any shop, come in many sizes and can plug into any computer using a common SD card reader. That makes them perfect for microcontroller storage and retrieval -...

In Stock
[Buy Now](https://www.adafruit.com/product/4682)
[Related Guides to the Product](https://learn.adafruit.com/products/4682/guides)
![Angled Shot of the Adafruit Micro SD SPI or SDIO Card Breakout Board](https://cdn-shop.adafruit.com/640x480/4682-05.jpeg)

### Adafruit Grand Central M4 Express featuring the SAMD51

[Adafruit Grand Central M4 Express featuring the SAMD51](https://www.adafruit.com/product/4064)
Are you ready? Really ready? Cause here comes the **Adafruit Grand Central** featuring the **Microchip ATSAMD51**. This dev board is so big, it's not named after a Metro train, it's a whole freakin' _station_!

This board is like a freight...

In Stock
[Buy Now](https://www.adafruit.com/product/4064)
[Related Guides to the Product](https://learn.adafruit.com/products/4064/guides)
![Angled Shot of the Adafruit Grand Central M4 Express featuring the SAMD51.](https://cdn-shop.adafruit.com/640x480/4064-05.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Feather STM32F405 Express

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/093/509/medium800/circuitpython_IMG_20200724_124634.jpg?1595612863)

The Feather STM32F405 Express uses SDIO to connect its built in micro SD card slot.&nbsp; Didn't notice it had an SD card slot?&nbsp; We hid it on the underside.

To mount the SD card, use the following code.&nbsp; Remember to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with `import mount_sd`.

```python
import board
import sdioio
import storage

sdcard = sdioio.SDCard(
    clock=board.SDIO_CLOCK,
    command=board.SDIO_COMMAND,
    # Note that board.SDIO_DATA is a tuple of four pins, not a single pin.
    data=board.SDIO_DATA,
    frequency=25000000)

vfs = storage.VfsFat(sdcard)

storage.mount(vfs, "/sd")
```

### Adafruit Feather STM32F405 Express

[Adafruit Feather STM32F405 Express](https://www.adafruit.com/product/4382)
ST takes flight in this Feather board. The new STM32F405 Feather ([video](https://youtu.be/CZ6TtvYJTeI)) that we designed runs CircuitPython at a blistering 168MHz – our fastest CircuitPython board ever! We put a STEMMA QT / Qwiic port on the end, so you can really easily plug...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4382)
[Related Guides to the Product](https://learn.adafruit.com/products/4382/guides)
![Angled shot of a blue rectangular microcontroller.](https://cdn-shop.adafruit.com/640x480/4382-16.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Python Docs

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Using adafruit_sdcard

Warning: 

[Follow these steps to create the /sd directory](https://learn.adafruit.com/adafruit-memento-camera-board/circuitpython-memento-starter-projects)
Info: 

 **Use the code and wiring examples in this section IF:**

- CIrcuitPython on your board doesn't have `sdcardio` or `sdioio`

This is the case particularly for older and lower-capacity microcontrollers like SAMD21 (M0).

The following section will show how to initialize the SD card and read & write data to it.&nbsp; You'll want to put the correct lines to initialize it in **mount\_sd.py** on your **CIRCUITPY** drive. For typical wiring information and exact **mount\_sd.py** files for several different boards, check out next page.

# Adafruit CircuitPython Module Install

You'll need to install the [Adafruit CircuitPython SD](https://github.com/adafruit/Adafruit_CircuitPython_SD) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp;

Our CircuitPython starter guide has [a great page on how to install libraries from the bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

Load the the following libraries into the **lib** folder on your **CIRCUITPY** drive:

- **adafruit\_sdcard.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's **lib** folder or root filesystem has the **adafruit\_sdcard.mpy** file and **adafruit\_bus\_device** folder **&nbsp;** copied over.

![adafruit_products_Screenshot_2020-07-28_13-34-01.png](https://cdn-learn.adafruit.com/assets/assets/000/093/586/medium640/adafruit_products_Screenshot_2020-07-28_13-34-01.png?1595961282)

## Initialize & Mount SD Card Filesystem

Before you can use the microSD card you need to initialize its SPI connection and mount its filesystem. First import all the modules we'll need:

```python
import adafruit_sdcard
import board
import busio
import digitalio
import storage
```

Next create the SPI bus and a digital output for the microSD card's chip select line (be sure to select the right pin names for your wiring):

```python
# Use the board's primary SPI bus
spi = board.SPI()
# Or, use an SPI bus on specific pins:
#spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)

# Boards with built in SPI SD card slots will generally have a
# pin called SD_CS:
cs = digitalio.DigitalInOut(board.SD_CS)
# For breakout boards, you can choose any GPIO pin that's convenient:
#cs = digitalio.DigitalInOut(board.D10)
```

 **Note that when you use `adafruit_sdcard`, `cs` is a `DigitalInOut` object, not a `microcontroller.Pin` object.** If you change your code to use `sdcardio`, you need to use a&nbsp;`Pin` object instead.

At this point you're ready to create the microSD card object and the filesystem object:

```python
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
```

Notice the `sdcardio` module has a `SDCard` class which contains all the logic for talking to the microSD card at a low level. This class needs to be told the SPI bus and chip select pin in its constructor.

After a `SDCard` instance is created it can be passed to the `storage` module's `VfsFat` class. This class has all the logic for translating CircuitPython filesystem calls into low level microSD card access. Both the&nbsp;`SDCard` and&nbsp;`VfsFat` class instances are required to mount the card as a new filesystem.

Finally you can mount the microSD card's filesystem into the CircuitPython filesystem. For example to make the path **/sd** on the CircuitPython filesystem read and write from the card run this command:

```python
storage.mount(vfs, "/sd")
```

At this point, you can read and write to the SD card using common Python functions like `open`, `read`, and `write`.&nbsp; The filenames will all begin with `"/sd/"` to differentiate them from the files on the **CIRCUITPY** drive. If you're not familiar, here's an overview.

## Reading & Writing Data

Once the microSD card is mounted inside CircuitPython's filesystem you're ready to read and write data from it&nbsp; Reading and writing data is simple using Python's file operations like [open](https://docs.python.org/3/library/functions.html#open), [close](https://docs.python.org/3/library/io.html#io.IOBase.close), [read](https://docs.python.org/3/library/io.html#io.RawIOBase.read), and [write](https://docs.python.org/3/library/io.html#io.RawIOBase.write). The beauty of CircuitPython and MicroPython is that they try to be as similar to desktop Python as possible, including access to files.

For example to create a file and write a line of text to it you can run:

```python
with open("/sd/test.txt", "w") as f:
    f.write("Hello world!\r\n")
```

Notice the `with` statement is used to create a context manager that opens and automatically closes the file. This is handy because with file access you Python you **must** close the file when you're done or else all the data you thought was written might be lost! &nbsp;

The `open` function is used to open the file by telling it the path to it, and the mode (w for writing). Notice the path is under **/sd** , **/sd/test.txt**. This means the file will be created on the microSD card that was mounted as that path.

Inside the context manager you can access the `f` variable to operate on the file while it's open. The `write` function is called to write a line of text to the file. Notice that unlike a `print` statement you need to end the string passed to write with explicit carriage returns and new lines.

You can also open a file and read a line from it with similar code:

```python
with open("/sd/test.txt", "r") as f:
    print("Read line from file:")
    print(f.readline(), end='')
```

When reading a line from a file with `readline`, the newline character `'\n'` at the end of the line is included. By printing with `end=''`, the newline normally added by print is skipped. Otherwise, when reading back the file, it would appear that there were extra blank lines after every line of the file.

If you wanted to read and print all of the lines from a file you could call `readline` in a loop. Once `readline` reaches the end of the file it will return an empty string&nbsp;so you know when to stop:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    line = f.readline()
    while line != '':
        print(line, end='')
        line = f.readline()
```

You can also just use the open file object in a `for` loop. Each time the loop runs, the loop variable will be assigned the content of the next line of the file:

```python
with open("/sd/test.txt", "r") as f:
    print("Printing lines in file:")
    for line in file:
        print(line, end='')
```

Finally one other very common file scenario is opening a file to add new data at the end, or append data. This works exactly the same as in Python and the `open` function can be told you'd like to append instead of erase and write new data (what normally happens with the `w` option for `open`). For example to add a line to the file:

```python
with open("/sd/test.txt", "a") as f:
    f.write("This is another line!\r\n")
```

Notice the `a` option in the open function--this tells Python to add data at the end of the file instead of erasing it and starting over at the top. Try reading the file with the code above to see the new line that was added!

Those are the basics to manipulating files on microSD cards with CircuitPython!&nbsp; Once you have it working, put the correct lines in **mount\_sd.py** in **CIRCUITPY** , then continue learning by checking out the example pages to print directory listings, log sensor data, play MP3 files and display bitmap graphics.

# Example complete **mount\_sd.py**

This example works on the AdaLogger M0:

```python
import adafruit_sdcard
import board
import busio
import digitalio
import storage

spi = board.SPI()
cs = digitalio.DigitalInOut(board.SD_CS)

sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

Your board may be different. Refer to the following pages for more details.

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Adalogger M0 Feather

The Feather M0 Adalogger is a classic board that doesn't have the same power as its newer siblings, but it's still good for logging.&nbsp; Best of all, no soldering is necessary to access the SD card.

To mount the SD card, use the following code.&nbsp; Remember, to put it in the file **mount\_sd.py** on **CIRCUITPY** so you can easily call it from **code.py** or the REPL with `import mount_sd`.

```python
import adafruit_sdcard
import board
import busio
import digitalio
import storage

spi = board.SPI()
cs = digitalio.DigitalInOut(board.SD_CS)

sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

### Adafruit Feather M0 Adalogger

[Adafruit Feather M0 Adalogger](https://www.adafruit.com/product/2796)
Feather is the new development board from Adafruit, and like its namesake it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather M0 Adalogger** &nbsp;- our take on an...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2796)
[Related Guides to the Product](https://learn.adafruit.com/products/2796/guides)
![Angled shot of rectangular microcontroller with a MicroSD card installed.](https://cdn-shop.adafruit.com/640x480/2796-12.jpg)

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
![Hand removing/installing micro SD card from SD adapter](https://cdn-shop.adafruit.com/640x480/1294-03.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Python Docs

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Examples

Warning: 

[Follow these steps to create the /sd directory](https://learn.adafruit.com/adafruit-memento-camera-board/circuitpython-memento-starter-projects)
The following examples assume&nbsp;sure you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6) for your board.&nbsp; If you can `import mount_sd` at the REPL without getting an error, you should be good to go.

```python
&gt;&gt;&gt; import mount_sd
&gt;&gt;&gt;
```

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Listing files on SD card

Put the code below in **code.py** on your **CIRCUITPY** drive, open up the REPL (and restart it with ^D if necessary) to get a listing of all the files an SD card contains. We recursively print out all files and also the filesize. This is a good demo to start with because you can at least tell if your files exist!

This example will work on any board where you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6)!.

The function `print_directory` works using `os.listdir` (to list files in a directory) and `os.stat` (to get information about an item, such as size or whether it's a directory).

By keeping track of the nesting of directories within directories, names are indented according to the value of `tabs` to show the directory structure.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_sdcardio_sdioio/list_files/code.py

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Benchmarking SD card access

Put the code below in **code.py** on your **CIRCUITPY** drive, open up the REPL (and restart it with ^D if necessary) to get report of how quickly CircuitPython can read and write your SD card.

This example will work on any board where you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6)!.

We saw some great speed increases going from good (`adafruit_sdcard`) to better (`sdcardio`) to best (`sdio`).&nbsp; However, every SD card is different and (especially when writing data) slow down as they "age", so your mileage may vary:

- SD card access with `adafruit_sdcard` on Grand Central:
  - Reads up to 120kB/s
  - Data logging at up to 160 of lines per second

- SD card access with `sdcardio` on Grand Central:
  - Reads up to 650kB/s
  - Data logging at up to 700 of lines per second

- SD card access with `sdioio` on Grand Central with SDIO breakout:
  - Reads up to 1100kB/s
  - Data logging at over 1000 lines per second

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_sdcardio_sdioio/benchmark/code.py

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Logging temperature to SD card

Did you know your CircuitPython-compatible microcontroller probably has a thermometer inside?&nbsp; It does!&nbsp; `microcontroller.cpu.temperature` reflects the temperature inside the microcontroller itself, which will frequently be 3-4 degrees C above the ambient temperature.&nbsp; Note that temperatures are reported in Celsius, not Fahrenheit.

This is a great example to extend with the sensor(s) of your choice, as well as with a Real Time Clock (RTC) so that you know the time that each reading was recorded.&nbsp; We chose the internal temperature to make this work with a wide range of boards, as long you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6)!

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_sdcardio_sdioio/log_temperature/code.py

### Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards

[Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards](https://www.adafruit.com/product/2922)
A Feather board without ambition is a Feather board without FeatherWings! This is the **Adalogger FeatherWing** : it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board. Using our [Feather...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2922)
[Related Guides to the Product](https://learn.adafruit.com/products/2922/guides)
![Adalogger FeatherWing with Real time clock and SD card slot.](https://cdn-shop.adafruit.com/640x480/2922-11.jpg)

### Adafruit Feather nRF52840 Sense

[Adafruit Feather nRF52840 Sense](https://www.adafruit.com/product/4516)
The **Adafruit Feather Bluefruit Sense** takes our popular [Feather nRF52840 Express](https://www.adafruit.com/product/4062) and adds a smorgasbord of sensors to make a great wireless sensor platform. This Feather microcontroller comes with Bluetooth® Low Energy and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4516)
[Related Guides to the Product](https://learn.adafruit.com/products/4516/guides)
![Angled shot of blue, rectangular, microcontroller.](https://cdn-shop.adafruit.com/640x480/4516-06.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Playing MP3 from SD Card

Primary: 

Compressed audio can be a nice alternative to uncompressed WAV files - especially when you have a small filesystem like that on many CircuitPython boards: those WAV files get pretty big fast! Thanks to the expiration of the MP3 patent pool, we can now include MP3 decoding as a core CircuitPython capability_._

CircuitPython supports any MP3 file you like. We've found that **mono and stereo** files from **32kbit** /s to **128kbit** /s work, with sample rates from **16kHz** to **44.1kHz**. The DAC output on the SAMD51 M4 is just 12-bit so there's not much point in using higher bitrates.

With this example, tailored to the PyGamer, you can loop MP3s to your heart's content (or as long as power lasts).&nbsp; Put the MP3 files in the main folder of your SD card, put the code below in **code.py** , and make sure you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6)!

This example can be adapted to a lot of SAMD51 and nRF52840 boards.&nbsp; Where there's no headphone jack or speaker connection, consider the Prop Maker Featherwing for your sound-making needs.&nbsp; For more about playing MP3s, visit [the page in the essentials guide](https://learn.adafruit.com/circuitpython-essentials/circuitpython-mp3-audio).&nbsp; For a full MP3 player for your PyGamer, see [the dedicated guide](https://learn.adafruit.com/pygamer-mp3-player-with-circuitpython).

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_sdcardio_sdioio/play_mp3s/code.py

### Adafruit PyGamer Starter Kit

[Adafruit PyGamer Starter Kit](https://www.adafruit.com/product/4277)
**Please note: you may get a royal blue _or_ purple case with your starter kit (they're both lovely colors)**

What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4277)
[Related Guides to the Product](https://learn.adafruit.com/products/4277/guides)
![Adafruit PyGamer Starter Kit with PCB, enclosure, buttons, and storage bag](https://cdn-shop.adafruit.com/640x480/4277-08.jpg)

### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the **Adafruit PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
![Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.](https://cdn-shop.adafruit.com/640x480/4242-00.jpg)

### Adafruit Prop-Maker FeatherWing

[Adafruit Prop-Maker FeatherWing](https://www.adafruit.com/product/3988)
The Adafruit Feather series gives you lots of options for a small, portable, rechargeable microcontroller board. Perfect for fitting into your next prop build! This FeatherWing will unlock the prop-maker inside all of us, with tons of stuff packed in to make sabers & swords, props, toys,...

In Stock
[Buy Now](https://www.adafruit.com/product/3988)
[Related Guides to the Product](https://learn.adafruit.com/products/3988/guides)
![Angled shot of a Adafruit Prop-Maker FeatherWing. ](https://cdn-shop.adafruit.com/640x480/3988-00.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Showing BMPs from SD card

With this example, tailored to the PyGamer, you can have a portable picture frame.&nbsp; Put the BMP files in the main folder of your SD card, put the code below in **code.py** , and make sure you've [configured **mount\_sd.py**](https://learn.adafruit.com/circuitpython-6-sd-cards-with-sdcardio-and-sdioio/circuitpython#tip-create-a-mount-sd-dot-py-file-3067892-6)!

This example can be adapted to a lot of CircuitPython boards with [support for displayio](https://learn.adafruit.com/circuitpython-display-support-using-displayio).&nbsp;

For more information on making bitmap files, [check out this guide](https://learn.adafruit.com/creating-your-first-tilemap-game-with-circuitpython/indexed-bmp-graphics).

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_sdcardio_sdioio/show_bitmaps/code.py

### Adafruit PyGamer Starter Kit

[Adafruit PyGamer Starter Kit](https://www.adafruit.com/product/4277)
**Please note: you may get a royal blue _or_ purple case with your starter kit (they're both lovely colors)**

What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4277)
[Related Guides to the Product](https://learn.adafruit.com/products/4277/guides)
![Adafruit PyGamer Starter Kit with PCB, enclosure, buttons, and storage bag](https://cdn-shop.adafruit.com/640x480/4277-08.jpg)

### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the **Adafruit PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
![Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.](https://cdn-shop.adafruit.com/640x480/4242-00.jpg)

# Adafruit MicroSD SPI or SDIO Card Breakout Board

## Downloads

## Files

- [SD card simplified specification](https://www.sdcard.org/downloads/pls/)
- [EagleCAD files on GitHub](https://github.com/adafruit/Adafruit-MicroSD-SPI-or-SDIO-card-breakout-PCB)
- [3D models on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/main/4682%20Micro%20SD%20Breakout)
- [Fritzing object in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20SDIO%20microSD%20Breakout.fzpz)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/093/596/medium800/adafruit_products_SDIO_breakout_sch.png?1595968318)

# Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/093/595/medium800/adafruit_products_SDIO_breakout_fab_print.png?1595968276)

# 3D Model
![](https://cdn-learn.adafruit.com/assets/assets/000/126/483/medium800/adafruit_products_4682_Micro_SD_Breakout.jpg?1701715060)


## Primary Products

### Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!

[Adafruit Micro SD SPI or SDIO Card Breakout Board - 3V ONLY!](https://www.adafruit.com/product/4682)
Micro SD cards and microcontrollers go together like micro-peanutbutter-and-jelly: SD cards are inexpensive, durable, easy to find at any shop, come in many sizes and can plug into any computer using a common SD card reader. That makes them perfect for microcontroller storage and retrieval -...

In Stock
[Buy Now](https://www.adafruit.com/product/4682)
[Related Guides to the Product](https://learn.adafruit.com/products/4682/guides)

## Featured Products

### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
### USB MicroSD Card Reader/Writer - microSD / microSDHC / microSDXC

[USB MicroSD Card Reader/Writer - microSD / microSDHC / microSDXC](https://www.adafruit.com/product/939)
This is the cutest little microSD card reader/writer - but don't be fooled by its adorableness! It's wicked fast and supports up to 64 GB SDXC cards! Simply slide the card into the edge and plug it into your computer. No drivers are required, it shows up as a standard 'Mass...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/939)
[Related Guides to the Product](https://learn.adafruit.com/products/939/guides)

## Related Guides

- [Video Playing 2.1" Round Ornament TFT](https://learn.adafruit.com/2-1-round-ornament-tft.md)
- [Qualia S3 Fireplace](https://learn.adafruit.com/qualia-s3-fireplace.md)
- [Adafruit ATtiny Breakouts with seesaw](https://learn.adafruit.com/adafruit-attiny817-seesaw.md)
- [Adafruit Proto Screw Shield](https://learn.adafruit.com/adafruit-proto-screw-shield.md)
- [Stand-alone programming AVRs using CircuitPython](https://learn.adafruit.com/stand-alone-programming-avrs-using-circuitpython.md)
- [Busy Box Interruption Sign](https://learn.adafruit.com/busy-box-interruption-sign.md)
- [A CLI in CircuitPython](https://learn.adafruit.com/a-cli-in-circuitpython.md)
- [Adafruit Metro M4 Express featuring ATSAMD51](https://learn.adafruit.com/adafruit-metro-m4-express-featuring-atsamd51.md)
- [Adafruit PiCowbell Camera Breakout](https://learn.adafruit.com/adafruit-picowbell-camera-breakout.md)
- [ TensorFlow Lite for EdgeBadge Quickstart](https://learn.adafruit.com/tensorflow-lite-for-edgebadge-kit-quickstart.md)
- [Adafruit LSM6DS3TR-C 6-DoF Accel + Gyro IMU](https://learn.adafruit.com/adafruit-lsm6ds3tr-c-6-dof-accel-gyro-imu.md)
- [Joy Featherwing](https://learn.adafruit.com/joy-featherwing.md)
- [Tiny Pod - BLE Rotary Encoder for iWatch](https://learn.adafruit.com/ano-pod.md)
- [Green Goblin Pumpkin CPB Ornament](https://learn.adafruit.com/green-goblin-pumpkin-cpb-ornament.md)
- [Last-Minute Halloween Accoutrements with HalloWing](https://learn.adafruit.com/last-minute-halloween-accoutrements-with-hallowing.md)
