from machine import Pin, SPI
import sdcard, os
spi = SPI(1, sck=Pin('GP10'), mosi=Pin('GP11'), miso=Pin('GP12'))
sd = sdcard.SDCard(spi, Pin('GP13', Pin.OUT))
# Mount filesystem
vfs = os.VfsFat(sd)
os.mount(vfs, "/sd")
# Create a file and write something to it
with open("/sd/test01.txt", "w") as file:
file.write("Hello, SD World!\r\n")
file.write("This is a test\r\n")
# Open the file we just created and read from it
with open("/sd/test01.txt", "r") as file:
data = file.read()
print(data)
with open("/sd/robot.txt", "r") as file:
data = file.read()
print(data)