Pi pico SD card

 This worked from code and wire-up from 2 years ago. Surprised. Pleased.

Used this code:

<script src="https://pastebin.com/embed_js/W0CWw2rx"></script> <--pastebi

https://www.digikey.co.nz/en/maker/projects/raspberry-pi-pico-rp2040-sd-card-example-with-micropython-and-cc/e472c7f578734bfd96d437e68e670050

From


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





  


Comments

Popular posts from this blog

Reading LittleFS file into buffer for sending

ESP32 buttons and bouncing