Microsd reader "no sd card" error on feather RP2040

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
leonllr
Posts: 2
Joined: Mon Dec 27, 2021 8:06 am

Microsd reader "no sd card" error on feather RP2040

Post by leonllr » Thu Dec 30, 2021 3:05 pm

Hey, I tried using a sd card on my adafruit feather RP2040 but it give me the error "OSError: no SD card"
my code:

Code: Select all

import os
from uos import mount
from libs.ST7735 import TFT
from libs.sysfont import sysfont
from machine import SPI, Pin
from utime import sleep_ms
import gc
import libs.sdcard as SDcard

screen_spi = SPI(0, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19), miso=Pin(20))
tft = TFT(screen_spi, 7, 8, 1)
tft.initr()
tft.fill(TFT.BLACK)
tft.rgb(True)

gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())

def mem_display():
    tft.text((0, 140), "{0}/{1} KB".format((gc.mem_alloc() / 1000), ((gc.mem_alloc() + gc.mem_free()) // 1000)),
             TFT.WHITE, sysfont, 1)
    tft.text((0, 150), "RAM USED", TFT.WHITE, sysfont, 1)


tft.fill(TFT.BLACK)
tft.text((0, 0), "Loading...", TFT.WHITE, sysfont, 2)
gc.collect()
mem_display()
sleep_ms(1000)

try:
    gc.collect()
    sd_spi = SPI(1, baudrate=1000000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB,
                 sck=Pin(10), mosi=Pin(11), miso=Pin(12))
    print(sd_spi)
    sd = SDcard.SDCard(sd_spi, Pin(9))
    print(sd)
    vfs = os.VfsFat(sd)
    print(vfs)
    mount(vfs, "/sd")  # os.mount
    tft.fill(TFT.BLACK)
    with open('/sd/test.txt', 'r') as test:
        tft.text((0, 0), test.read(),
                 TFT.WHITE, sysfont, 2)
except Exception as e:
    tft.fill(TFT.BLACK)
    tft.text((0, 0), str(e), TFT.RED, sysfont, 1)
    mem_display()
    sleep_ms(1000)
    raise e


Post Reply