diff --git a/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py b/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py index be5386756..e20a3c396 100644 --- a/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py +++ b/Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py @@ -16,14 +16,21 @@ import adafruit_sdcard # The SD_CS pin is the chip select line. SD_CS = board.SD_CS -# Connect to the card and mount the filesystem. -cs = digitalio.DigitalInOut(SD_CS) -sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs) -vfs = storage.VfsFat(sdcard) -storage.mount(vfs, "/sd") +try: + # Connect to the card and mount the filesystem. + cs = digitalio.DigitalInOut(SD_CS) + sdcard = adafruit_sdcard.SDCard( + busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs + ) + vfs = storage.VfsFat(sdcard) + storage.mount(vfs, "/sd") +except ValueError: + # SD_CS in use error happens if CircuitPython core initialized the SD automatically + pass # Use the filesystem as normal! Our files are under /sd + # This helper function will print the contents of the SD def print_directory(path, tabs=0): for file in os.listdir(path): diff --git a/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py b/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py index 596c2b75f..92fe215d2 100644 --- a/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py +++ b/Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py @@ -21,11 +21,17 @@ import storage # The SD_CS pin is the chip select line. SD_CS = board.SD_CS -# Connect to the card and mount the filesystem. -cs = digitalio.DigitalInOut(SD_CS) -sdcard = adafruit_sdcard.SDCard(busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs) -vfs = storage.VfsFat(sdcard) -storage.mount(vfs, "/sd") +try: + # Connect to the card and mount the filesystem. + cs = digitalio.DigitalInOut(SD_CS) + sdcard = adafruit_sdcard.SDCard( + busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs + ) + vfs = storage.VfsFat(sdcard) + storage.mount(vfs, "/sd") +except ValueError: + # SD_CS in use error happens if CircuitPython core initialized the SD automatically + pass # Use the filesystem as normal! Our files are under /sd