Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MicroPython SD Card Examole #4

Closed
PeteHollyer opened this issue Sep 18, 2021 · 5 comments
Closed

MicroPython SD Card Examole #4

PeteHollyer opened this issue Sep 18, 2021 · 5 comments

Comments

@PeteHollyer
Copy link

PeteHollyer commented Sep 18, 2021

I NEED a MICROPYTHON SD Card example for the Maker-Pi-Pico.
I have tried all the "current" examples on the internet I can find and NONE of them Work.
All of the Die on the "VfsFat" command

My SDCard and the Reader Work perfectly using CircuitPython, just NOT with MicroPython. I've tried formatting block size 512 & 1024 FS Fat32, Win 10 Formatter; Same error both times.

Code

import machine
import sdcard
import uos


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


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 card
sd = sdcard.SDCard(spi, cs)


vfs = vos.VfsFat(sd)                                          #<====   DIES HERE
uos.mount(vfs, "/sd")

with open("/sd/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("/sd/test01.txt", "r") as file:
    data = file.read()
    print(data)

with following error

Traceback (most recent call last):
File "", line 23, in
File "sdcard.py", line 238, in readblocks
OSError: [Errno 5] EIO

Thx
Pete

@PeteHollyer
Copy link
Author

PeteHollyer commented Sep 19, 2021

I Tracked into the problem,

Micropython was NOT liking my SD card. Even though Circuitpython liked it.
I changed cards to a 32 GB card ( was a 2 BG Card) and it read.

from machine import Pin, SPI
import sdcard
import os
    
def OpenSD():
    sd_spi = SPI(1, sck = Pin(10, Pin.OUT), mosi = Pin(11, Pin.OUT), miso = Pin(12, Pin.OUT))
    # Create SDCard object
    sd = sdcard.SDCard(sd_spi, Pin(15, Pin.OUT))
    os.mount(sd, "/sd")
    os.listdir("/sd")
    print("Mounted")

def CloseSD():
    os.umount("/sd")
    print("UMount")

Problem was ALL mine! Sorry.
Please Close Issue

@designdevy
Copy link

hi can you share the circuitpython example that works with make pi pico? @PeteHollyer

@sgbaird
Copy link

sgbaird commented Nov 3, 2022

I think you have a typo:
vfs = vos.VfsFat(sd) --> vfs = uos.VfsFat(sd)

Also, the script seems to be based mostly on https://www.digikey.com/en/maker/projects/raspberry-pi-pico-rp2040-sd-card-example-with-micropython-and-cc/e472c7f578734bfd96d437e68e670050.

@sgbaird
Copy link

sgbaird commented Nov 3, 2022

@PeteHollyer did you ever figure out the formatting with your other card that wasn't working?

@PeteHollyer
Copy link
Author

PeteHollyer commented Nov 3, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants