Code: Select all
# SPI 1 Pins
miso_sd = Pin(12) # blue - RX
mosi_sd = Pin(11) # yellow - TX
sck_sd = Pin(10) # green
cs_sd = Pin(9, Pin.OUT) # white - SD
spi_sd = SPI(
1,
baudrate=1000000,
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=sck_sd,
mosi=mosi_sd,
miso=miso_sd
)
sd = sdcard.SDCard(spi_sd, cs_sd)
# Mount file system
vfs = uos.VfsFat(sd)
uos.mount(vfs)
# Create a file and write something to it
with open("/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("/test01.txt", "r") as file:
data = file.read()
print(data)
uos.unmount()
Error Message:
Traceback (most recent call last):
File "<stdin>", line 73, in <module>
File "/lib/sdcard.py", line 54, in __init__
File "/lib/sdcard.py", line 87, in init_card
File "/lib/sdcard.py", line 135, in init_card_v2
OSError: timeout waiting for v2 card