adafruit_sdcard - SD card over SPI driver

CircuitPython driver for SD cards using SPI bus.

Requires an SPI bus and a CS pin. Provides readblocks and writeblocks methods so the device can be mounted as a filesystem.

  • Author(s): Scott Shawcroft

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_sdcard.SDCard(spi, cs)[source]

Controls an SD card over SPI.

Parameters:
  • spi (SPI) – The SPI bus
  • cs (DigitalInOut) – The chip select connected to the card

Example usage:

import busio
import storage
import adafruit_sdcard
import os
import board

spi = busio.SPI(SCK, MOSI, MISO)
sd = adafruit_sdcard.SDCard(spi, board.SD_CS)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')
os.listdir('/')
count()[source]

Returns the total number of sectors.

Returns:The number of 512-byte blocks
Return type:int
readblocks(start_block, buf)[source]

Read one or more blocks from the card

Parameters:
  • start_block (int) – The block to start reading from
  • buf (bytearray) – The buffer to write into. Length must be multiple of 512.
writeblocks(start_block, buf)[source]

Write one or more blocks to the card

Parameters:
  • start_block (int) – The block to start writing to
  • buf (bytearray) – The buffer to write into. Length must be multiple of 512.