Merge branch 'refs/heads/main' into sd_excepts
This commit is contained in:
commit
d40ddef917
4 changed files with 63 additions and 1 deletions
|
|
@ -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")
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
CircuitPython Essentials SD Card Read Demo
|
CircuitPython Essentials SD Card Read Demo
|
||||||
|
* Not compatible with CircuitPython 10.x
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -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.
|
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.
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue