Worked best SD card with Thonny

 This code worked in Micro python with Pi Pico: (After a lot of problems.)

 print(",,,xkchgvsdckhsgDigiKey0  ")

print("core Electronics How to setgggg up Pi Pico and Code with Thonny")

import machine

import sdcard

import uos

import os


# Assign chip select (CS) pin (and start it high)

cs = machine.Pin(9, machine.Pin.OUT)


# 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)

print(cs) 

# Mount filesystem

vfs = os.VfsFat(sd)

#uos.mount(os.VfsFat(sd), "/sd")

uos.mount(vfs, "/sd")

# Create a file and write something to it

with open("/sd/test01.txt", "w") as file:

    file.write("Hello, WORX22345 67!! SD World!\r\n")

    file.write("This is a test and seems to work@@01 A \r\n")

file.close()


# Open the file we just created and read from it


with open("/sd/test01.txt", "r") as file:

    data = file.read()

    print(data)

file.close()  

&&&&&&&&&&&&&&&&&&&&
I put in the silly file.write's above as well as the file.close() statements. (Not sure if they're required.)

Comments

Popular posts from this blog

eeprom programmer

SD Card, Circuit Python via Thonny