Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Amazing. This worked 2 yeas later
- print("Simple SD card testDigiKey1.1 ") #Tue Jun 28 17:09:24 NZST 2022
- print("Pi Pico and Code with Thonny.")
- import machine
- import sdcard
- import os #why not uos?
- # Assign chip select (CS) pin (and start it high)
- cs = machine.Pin(9, machine.Pin.OUT) #does this really start high?
- # Intialize SPI peripheral (start with 1 MHz) Check it IS 1000000
- spi = machine.SPI(1,
- baudrate=100000,
- polarity=0,
- phase=0,
- bits=8,
- firstbit=machine.SPI.MSB,
- sck=machine.Pin(10),
- mosi=machine.Pin(11),
- miso=machine.Pin(8))
- # Initialize SD card
- sd = sdcard.SDCard(spi, cs)
- vfs = os.VfsFat(sd)
- os.mount(vfs, "/sd")
- # Create a file and write something to it
- with open("/sd/test03.txt", "w") as file:
- file.write("Hello, WWWWORX22345 67!! SD World!\r\n")
- file.write("This is a test and seems to work@@022 ABCDEfg\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)
Advertisement