microSD Card Example¶
The microSD Card Example demonstrates the use of a microSD memory card using the SD Card library and the FatFs file system library.
The example initializes the card and performs basic operations like mounting the FAT volume, writing and reading the example file.
The microSD Card is connected to the nRF52840 chip over a SPI bus. The table below shows the connections of each pin of the microSD Card:
|microSD Card Pin||nRF52840 Pin|
Before you start coding, the Python Interpreter should be installed on the nRF52840 M.2 module correctly:
Run the code¶
Run the microSD Card Example by performing the following steps:
Power down the board
Insert a FAT formatted microSD card into the microSD slot
Connect the Module USB port to your PC as shown in the figure below. A disk drive called CIRCUITPY should be automatically detected by the computer:
code.pyfile on your CIRCUITPY drive, then copy and paste the following code. Your code will run as soon as the file is done saving.
# SD card usage import board import digitalio import displayio import sdcard import storage displayio.release_displays() spi = board.SPI() cs = digitalio.DigitalInOut(board.P7) sd = sdcard.SDCard(spi, cs) vfs = storage.VfsFat(sd) storage.mount(vfs, "/sd") print("microSD Card mounted.") # write to sd card print("Writing to file /sd/test.txt ...") with open("/sd/test.txt", "w") as f: f.write("This is the written string.\n") # read from sd card print("Reading from file /sd/test.txt ...") with open("/sd/test.txt", "r") as f: data = f.read() print(data)
screen /dev/cu.usbmodem14102 115200
Save the code and observe the output of the terminal:
Create an Issue¶
Interested in contributing to this project? Want to report a bug? Feel free to click here: