expand SD comments, remove leftover comment section, remove 10x specific files

This commit is contained in:
foamyguy 2025-06-13 11:54:11 -05:00
parent d40ddef917
commit 748f988a52
4 changed files with 19 additions and 71 deletions

View file

@ -1,37 +0,0 @@
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython 10.x SD Card Directory Listing Demo
Assumes the SD card is auto-mounted at /sd by the runtime.
"""
import os
def print_directory(path, tabs=0):
for name in os.listdir(path):
full_path = f"{path}/{name}"
stats = os.stat(full_path)
filesize = stats[6]
isdir = bool(stats[0] & 0x4000)
# human-readable size
if filesize < 1_000:
sizestr = f"{filesize} bytes"
elif filesize < 1_000_000:
sizestr = f"{filesize/1_000:.1f} KB"
else:
sizestr = f"{filesize/1_000_000:.1f} MB"
indent = " " * tabs
display_name = indent + name + ("/" if isdir else "")
# <40 pads or truncates to 40 chars, then we append the size
print(f"{display_name:<40} Size: {sizestr}")
if isdir:
print_directory(full_path, tabs + 1)
print("Files on /sd:")
print("====================")
print_directory("/sd")

View file

@ -3,7 +3,6 @@
""" """
CircuitPython Essentials SD Card Read Demo CircuitPython Essentials SD Card Read Demo
* Not compatible with CircuitPython 10.x
""" """
import os import os
@ -16,16 +15,23 @@ import adafruit_sdcard
# The SD_CS pin is the chip select line. # The SD_CS pin is the chip select line.
SD_CS = board.SD_CS SD_CS = board.SD_CS
# For CircuitPython 9.x we must initialize and mount the SD card manually.
# On CircuitPython 10.x the core will automatically initialize and mount the SD.
# This try/except block can be removed with 10.x has a stable release.
try: try:
# Connect to the card and mount the filesystem. # Initialize the Chip Select pin for the SD card
cs = digitalio.DigitalInOut(SD_CS) cs = digitalio.DigitalInOut(SD_CS)
# Initialize the SD card
sdcard = adafruit_sdcard.SDCard( sdcard = adafruit_sdcard.SDCard(
busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs
) )
# Mount the SD card
vfs = storage.VfsFat(sdcard) vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd") storage.mount(vfs, "/sd")
except ValueError: except ValueError:
# SD_CS in use error happens if CircuitPython core initialized the SD automatically # "ValueError SD_CS in use" error happen on CircuitPython 10.x
# because the core initialized the SD automatically. The error
# can be ignored on 10.x.
pass pass
# Use the filesystem as normal! Our files are under /sd # Use the filesystem as normal! Our files are under /sd

View file

@ -1,23 +0,0 @@
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
CircuitPython 10.x SD Write Demo
Assumes /sd is auto-mounted by the runtime
Just open and append no mount or SD driver code needed
Not compatible with CircuitPython 9.x
Uses SDIO
"""
import time
import microcontroller
print("Logging temperature to /sd/temperature.txt")
while True:
t = microcontroller.cpu.temperature
print("T = %0.1f °C" % t)
with open("/sd/temperature.txt", "a") as f:
f.write("%0.1f\n" % t)
time.sleep(1)

View file

@ -4,12 +4,6 @@
""" """
CircuitPython Essentials SD Card Write Demo CircuitPython Essentials SD Card Write Demo
REMOVE THIS LINE AND ALL BELOW IT BEFORE SUBMITTING TO LEARN
Update CHIP_SELECT_PIN to match the CS pin on your board.
For example, for the Metro ESP32-S3, you would use: board.SD_CS.
This code stops working with CircuitPython 10.x which automounts /sd
""" """
import time import time
@ -23,16 +17,24 @@ import storage
# The SD_CS pin is the chip select line. # The SD_CS pin is the chip select line.
SD_CS = board.SD_CS SD_CS = board.SD_CS
# For CircuitPython 9.x we must initialize and mount the SD card manually.
# On CircuitPython 10.x the core will automatically initialize and mount the SD.
# This try/except block can be removed with 10.x has a stable release.
try: try:
# Connect to the card and mount the filesystem. # Initialize the Chip Select pin for the SD card
cs = digitalio.DigitalInOut(SD_CS) cs = digitalio.DigitalInOut(SD_CS)
# Initialize the SD card
sdcard = adafruit_sdcard.SDCard( sdcard = adafruit_sdcard.SDCard(
busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO), cs
) )
# Mount the SD card
vfs = storage.VfsFat(sdcard) vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd") storage.mount(vfs, "/sd")
except ValueError: except ValueError:
# SD_CS in use error happens if CircuitPython core initialized the SD automatically # "ValueError SD_CS in use" error happen on CircuitPython 10.x
# because the core initialized the SD automatically. The error
# can be ignored on 10.x.
pass pass
# Use the filesystem as normal! Our files are under /sd # Use the filesystem as normal! Our files are under /sd