Skip to content

Commit 3d3d29c

Browse files
committed
update sd examples for 10.x behavior
1 parent 57a70ad commit 3d3d29c

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

  • Metro_RP2350_Examples
    • CircuitPython_SDCard_ListFiles
    • CircuitPython_SDCard_Write

Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
# The SD_CS pin is the chip select line.
1717
SD_CS = board.SD_CS
1818

19-
# Connect to the card and mount the filesystem.
20-
cs = digitalio.DigitalInOut(SD_CS)
21-
sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs)
22-
vfs = storage.VfsFat(sdcard)
23-
storage.mount(vfs, "/sd")
19+
try:
20+
# Connect to the card and mount the filesystem.
21+
cs = digitalio.DigitalInOut(SD_CS)
22+
sdcard = adafruit_sdcard.SDCard(
23+
busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs
24+
)
25+
vfs = storage.VfsFat(sdcard)
26+
storage.mount(vfs, "/sd")
27+
except ValueError:
28+
# SD_CS in use error happens if CircuitPython core initialized the SD automatically
29+
pass
2430

2531
# Use the filesystem as normal! Our files are under /sd
2632

33+
2734
# This helper function will print the contents of the SD
2835
def print_directory(path, tabs=0):
2936
for file in os.listdir(path):

Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121
# The SD_CS pin is the chip select line.
2222
SD_CS = board.SD_CS
2323

24-
# Connect to the card and mount the filesystem.
25-
cs = digitalio.DigitalInOut(SD_CS)
26-
sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs)
27-
vfs = storage.VfsFat(sdcard)
28-
storage.mount(vfs, "/sd")
24+
try:
25+
# Connect to the card and mount the filesystem.
26+
cs = digitalio.DigitalInOut(SD_CS)
27+
sdcard = adafruit_sdcard.SDCard(
28+
busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs
29+
)
30+
vfs = storage.VfsFat(sdcard)
31+
storage.mount(vfs, "/sd")
32+
except ValueError:
33+
# SD_CS in use error happens if CircuitPython core initialized the SD automatically
34+
pass
2935

3036
# Use the filesystem as normal! Our files are under /sd
3137

0 commit comments

Comments
 (0)