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:
Adafruit MicroSD card breakout board+ (Product ID: 254)
Adafruit Assembled Data Logging shield for Arduino (Product ID: 1141)
Adafruit Feather M0 Adalogger (Product ID: 2796)
Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards (Product ID: 2922)
Software and Dependencies:
Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_sdcard.SDCard(spi: SPI, cs: DigitalInOut, baudrate: int = 1320000)[source]
Controls an SD card over SPI.
- Parameters:
spi (SPI) – The SPI bus
cs (DigitalInOut) – The chip select connected to the card
baudrate (int) – The SPI data rate to use after card setup
Example usage:
import busio import storage import adafruit_sdcard import digitalio import os import board spi = busio.SPI(SCK, MOSI, MISO) cs = digitalio.DigitalInOut(board.SD_CS) sdcard = adafruit_sdcard.SDCard(spi, cs) vfs = storage.VfsFat(sdcard) storage.mount(vfs, '/sd') os.listdir('/sd')
- count() int [source]
Returns the total number of sectors.
- Returns:
The number of 512-byte blocks
- Return type:
- readblocks(start_block: int, buf: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) int [source]
Read one or more blocks from the card
- Parameters:
start_block (int) – The block to start reading from
buf (WriteableBuffer) – The buffer to write into. Length must be multiple of 512.
- writeblocks(start_block: int, buf: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) int [source]
Write one or more blocks to the card
- Parameters:
start_block (int) – The block to start writing to
buf (ReadableBuffer) – The buffer to write into. Length must be multiple of 512.
- adafruit_sdcard.calculate_crc(message: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray) int [source]
Calculate the CRC of message[0:5], using a precomputed table in CRC_TABLE.
- Parameters:
message (bytearray) – Where each index is a byte