Hi.
I’ve been trying to figure out this device with miropython.
Trying to read a .wav file off an SD card.
I’ve been following this gitlab page
Here is my attempt.
import os
from machine import SDCard, Pin
sd = SDCard(slot=1, sck=Pin(6), mosi=Pin(3), miso=Pin(4), cs=Pin(29))
os.mount(sd, "/sd")
And the interpreter is telling me
ImportError: can’t import name SDCard
And as usual the interpreter is correct.
You can see below machine does not contain such a library. (OR maybe I don’t have the right version of the module installed)
From what I can tell from the code used in this link they are using a big if/else statement to determine what board is being used before they import the required library.
Looking at the documentation for SD card use in MicroPython I think this library call method is incorrect. I think it should be
import os import machine import sdcard
With ‘sdcard’ being called in lowercase and as a separate library.
The documentation at the below link made sense to me, hopefully you can make use of it:
Ah! Progress.
Installed; no Import-Errors!
I did some reasearch and the tutorial i was following used an older version of this lib when it was a submodule of machine. Now it’s a standalone.
There was something that worried me I want to flash by someone.
Have a look at the pinout for the Audio BFF I’m working with.
It has four pins.
Default SD Card Pins
The SD Card is connected to the default SPI pins on the QT Py. SDCS is connected to pin A0.
MO - This is the SPI MOSI (M icrocontroller O ut / S erial I n) pin. It is used to send data from the microcontroller to the SD card. It is connected to the default MOSI pin on the QT Py.
MI - This is the SPI MISO (Microcontroller In / Serial Out) pin. It’s used for sending data from the SD card to the microcontroller. It is connected to the default MISO pin on the QT Py.
SCK - This is the SPI clock input pin. It is connected to the default SCK pin on the QT Py.
A0 - This is the SD chip select pin (SDCS).
But the constructor of sdcard is only asking for 2 pins: Data and Chip-Select.
It’s not asking me for a clock or or an MOSI.
def __init__(self, spi, cs, baudrate=1320000):
That gave me pause because I really don’t feel like corrupting a bunch of SD cards debugging this.
Check this page out, it’s constructor looks totally different.
Hmmm, no suggestions coming to mind for a time out error. The sdcard.py source code has multiple loops that run until that error is produced so it could be any number of things.
To large of an SD card seems like a decent thing to check. The only other thing that comes to mind is maybe some conflict with how the card is formatted?
I’ve had a look at the RP2 port of the machine library (are you using an RP2040?)
The SPI section looks like it defaults to 10MHz which might be a bit intense for a breadboarded circuit. If the speed is too high the signal integrity will be compromised (the transitions become mushy).
Try something lower eg.
spi = SPI(0, 100_000) # Default assignment for SPI0, 100kHz
It might still be helpful to be explicit with your pins, just in case. Leave nothing to chance