SDCard
Example
- SDCard file read and write operations
from m5stack import *
from m5ui import *
from uiflow import *
from hardware import sdcard
setScreenColor(0x222222)
sdcard.SDCard(20000000)
with open('/sd/test.txt', 'w+') as fs:
fs.write('Hello World')
with open('/sd/test.txt', 'r') as fs:
print(fs.read())
API
sdcard.SDCard(20000000)
- Setting the SDCard bus clock frequency
with open('/sd/test.txt', 'w+') as fs:
pass
- Opens the specified file and performs read or write operations inside it. r and r+ modes must exist or an error will occur. a, w, and w+ modes automatically create the file if it does not exist.
fs.write('Hello World')
fs.seek(0)
- Manipulate the file cursor movement position
fs.seek(0)
os.remove('/sd/filename')
- Deleting a file with a specified path
os.rmdir('/sd/folder')
- Delete a specified path folder
os.rename('/sd/old', '/sd/new')
fs.read()
fs.read(1024)
- Read data of specified length
fs.readline()
fs.tell()
- Read the current file cursor position
os.listdir('/sd/')
os.stat('/sd/')[0] == 0x8000
- Check if the path is a file
os.stat('/sd/')[0] == 0x4000
- Check if the path is a directory
'' in os.listdir('/sd/')
- Check if a file is included in the path