File tree Expand file tree Collapse file tree
CircuitPython_SDCard_ListFiles
CircuitPython_SDCard_Write Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616# The SD_CS pin is the chip select line.
1717SD_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
2835def print_directory (path , tabs = 0 ):
2936 for file in os .listdir (path ):
Original file line number Diff line number Diff line change 2121# The SD_CS pin is the chip select line.
2222SD_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
You can’t perform that action at this time.
0 commit comments