Merge pull request #3061 from adafruit/metro-rp2350-CP10x-SD

Metro RP2350 demo code for CircuitPython 10.x SD card list and write. The 9.x examples are not compatible.
This commit is contained in:
Mikey Sklar 2025-06-13 09:34:15 -07:00 committed by GitHub
commit 736bedf957
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,37 @@
# 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,7 @@
"""
CircuitPython Essentials SD Card Read Demo
* Not compatible with CircuitPython 10.x
"""
import os

View file

@ -0,0 +1,23 @@
# 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

@ -8,6 +8,8 @@ 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