importmachine,os,sdcard# Assign chip select (CS) pin (and start it high)cs=machine.Pin(15,machine.Pin.OUT)# Intialize SPI peripheral (start with 1 MHz)spi=machine.SPI(1,baudrate=1000000,polarity=0,phase=0,bits=8,firstbit=machine.SPI.MSB,sck=machine.Pin(10),mosi=machine.Pin(11),miso=machine.Pin(12))# Initialize SD cardsd=sdcard.SDCard(spi,cs)# OR this simpler initialization code should works on Maker Pi Pico too...#sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))os.mount(sd,'/sd')# check the contentos.listdir('/sd')# try some standard file operationsfile=open('/sd/test.txt','w')file.write('Testing SD card on Maker Pi Pico')file.close()file=open('/sd/test.txt','r')data=file.read()print(data)file.close()
Results:
1
Testing SD card on Maker Pi Pico
References
MicroPython sdcard.py driver - note there is no documentation on use with the RP2040 although there is example code for the pyboard and the ESP8266