File tree Expand file tree Collapse file tree 4 files changed +63
-1
lines changed
CircuitPython_SDCard_ListFiles
CircuitPython_SDCard_Write Expand file tree Collapse file tree 4 files changed +63
-1
lines changed Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change 3
3
4
4
"""
5
5
CircuitPython Essentials SD Card Read Demo
6
-
6
+ * Not compatible with CircuitPython 10.x
7
7
"""
8
8
9
9
import os
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 8
8
Update CHIP_SELECT_PIN to match the CS pin on your board.
9
9
10
10
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
11
13
"""
12
14
13
15
import time
You can’t perform that action at this time.
0 commit comments