Skip to content

Commit 736bedf

Browse files
authored
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.
2 parents 57a70ad + 112721f commit 736bedf

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
CircuitPython 10.x SD Card Directory Listing Demo
6+
Assumes the SD card is auto-mounted at /sd by the runtime.
7+
"""
8+
9+
import os
10+
11+
def print_directory(path, tabs=0):
12+
for name in os.listdir(path):
13+
full_path = f"{path}/{name}"
14+
stats = os.stat(full_path)
15+
filesize = stats[6]
16+
isdir = bool(stats[0] & 0x4000)
17+
18+
# human-readable size
19+
if filesize < 1_000:
20+
sizestr = f"{filesize} bytes"
21+
elif filesize < 1_000_000:
22+
sizestr = f"{filesize/1_000:.1f} KB"
23+
else:
24+
sizestr = f"{filesize/1_000_000:.1f} MB"
25+
26+
indent = " " * tabs
27+
display_name = indent + name + ("/" if isdir else "")
28+
29+
# <40 pads or truncates to 40 chars, then we append the size
30+
print(f"{display_name:<40} Size: {sizestr}")
31+
32+
if isdir:
33+
print_directory(full_path, tabs + 1)
34+
35+
print("Files on /sd:")
36+
print("====================")
37+
print_directory("/sd")

Metro_RP2350_Examples/CircuitPython_SDCard_ListFiles/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""
55
CircuitPython Essentials SD Card Read Demo
6-
6+
* Not compatible with CircuitPython 10.x
77
"""
88

99
import os
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
CircuitPython 10.x SD Write Demo
7+
• Assumes /sd is auto-mounted by the runtime
8+
• Just open and append — no mount or SD driver code needed
9+
• Not compatible with CircuitPython 9.x
10+
• Uses SDIO
11+
"""
12+
13+
import time
14+
import microcontroller
15+
16+
print("Logging temperature to /sd/temperature.txt")
17+
18+
while True:
19+
t = microcontroller.cpu.temperature
20+
print("T = %0.1f °C" % t)
21+
with open("/sd/temperature.txt", "a") as f:
22+
f.write("%0.1f\n" % t)
23+
time.sleep(1)

Metro_RP2350_Examples/CircuitPython_SDCard_Write/code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Update CHIP_SELECT_PIN to match the CS pin on your board.
99
1010
For example, for the Metro ESP32-S3, you would use: board.SD_CS.
11+
12+
This code stops working with CircuitPython 10.x which automounts /sd
1113
"""
1214

1315
import time

0 commit comments

Comments
 (0)