Page 3 of 3

Re: I can't access microSD cards with Pyboard 1.1

Posted: Wed Aug 18, 2021 6:06 am
by pythoncoder
It's difficult to support clone boards we don't possess because we can't replicate your test conditions.

All I can say is that on official Pyboards both built-in and external SD card adaptors work fine.

Re: I can't access microSD cards with Pyboard 1.1

Posted: Wed Aug 18, 2021 7:36 pm
by scruss
adumbname wrote:
Tue Aug 17, 2021 10:49 pm
This Pyboard was bought on Amazon ( https://www.amazon.com/Homyl-Piece-Micr ... 975&sr=8-1 ).
Looks like a knock-off. I'd return it, if they take returns.
The SD card is a 4 GB Kingston micro SD HC and has been formatted to "loop" and FAT32.
Best formatted with the SD Association formatter (not a Linux thing) or in a digital camera. There may even be a routine in MicroPython to format.
Communication to the PyBoard is via Linux/Mint/Cinnamon: having better luck using screen /dev/ttyACM0 than rshell --port /dev/ttyACM0.
Try thonny. It's a solid IDE.
(Though it'd be great if all of the relevant suggestion, such as which SD Card to buy, how to format it, listings of boot & main on both /flash and /sd were all in one place ;) )
They're different for all the boards, so that's why there isn't one location for this info.

Personally, for my definition of "just workingness + SD card support", the MCUDev Black STM32F407VET6 does it. You do have to build MicroPython from source, but mcauser's MCUDev Black STM32F407VET6 makes that not too hard. Any decent µSD card should do: we're not pushing the boundaries of writing speed. I like this board because it has a battery-backed RTC and the MicroPython firmware exports the SD filesystem as USB storage. If you copy boot.py and main.py to the root of the SD card and create /lib there too, you've got a system you can develop on without relying entirely on a serial connection.

My only suggestion for datalogging: make sure you write/flush/open as append then close the logging file (pick one). write() doesn't seem to hit the SD card immediately.

Re: I can't access microSD cards with Pyboard 1.1

Posted: Wed Aug 18, 2021 8:33 pm
by adumbname
Scruss: thanks for the very helpful and timely advice!

I will post a note on Amazon, so others don't blindly stumble into this time sink!

my datalogger needs to run at >= 10k sps on 4 ADC channels. Thus, the PyBoard looked like a perfect fit - but your suggestion may be better. sampling, data storage and pwm motor control x2 are all the hardware that's required. which would you choose?

Re: I can't access microSD cards with Pyboard 1.1

Posted: Thu Aug 19, 2021 2:01 pm
by scruss
adumbname wrote:
Wed Aug 18, 2021 8:33 pm
my datalogger needs to run at >= 10k sps on 4 ADC channels.
That might be a stretch for MicroPython. I've never tried sampling that fast, so I don't know if the chip can do it.

Re: I can't access microSD cards with Pyboard 1.1

Posted: Thu Sep 16, 2021 9:18 am
by vinz-uts
Hi, I also have problem to mount a SDCard on a NUCLEO-L476RG board. I've tried to follow all the steps reported on this discussion but without results. I'm using an external SDCard Reader connected with SDMMC peripheral and without detect pin. I try to add this lines on mpconfigboard.h file:

Code: Select all

#define MICROPY_HW_ENABLE_SDCARD    (1)
#define MICROPY_HW_SDCARD_SDMMC	   (1)

// SD card detect switch
#define MICROPY_HW_SDCARD_DETECT_PIN        (pin_A8)
#define MICROPY_HW_SDCARD_DETECT_PULL       (GPIO_PULLUP)
#define MICROPY_HW_SDCARD_DETECT_PRESENT    (GPIO_PIN_RESET)

#define MICROPY_HW_SDCARD_D0                 (pin_C8)
#define MICROPY_HW_SDCARD_D1                 (pin_C9)
#define MICROPY_HW_SDCARD_D2                 (pin_C10)
#define MICROPY_HW_SDCARD_D3                 (pin_C11)
#define MICROPY_HW_SDCARD_CK                 (pin_C12)
#define MICROPY_HW_SDCARD_CMD                (pin_D2)
and forcing the detect pin to 0. When I call sd.present() the result was True, but when I try to mount the sd, it don't works

Code: Select all

>>> os.mount(sd,'/sd')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV

Re: I can't access microSD cards with Pyboard 1.1

Posted: Fri Sep 17, 2021 8:37 pm
by rkompass
@vinz-uts has possibly found a solution.
I also had the problem that some SDCards work, i.e. are mounted, others (older, smaller ones) not.
It seems that by default the faster 4-bit transfer mode is used for accessing them.
Setting a #define in mpconfigboard.h changes that.
That define is missing in my sources freshly checked out for Pyboard 1.1 .
See viewtopic.php?f=12&t=11098.
I will try this option as soon as I'm home and report.

Re: I can't access microSD cards with Pyboard 1.1

Posted: Sat Sep 18, 2021 8:52 pm
by rkompass
Including

Code: Select all

#define MICROPY_HW_SDCARD_BUS_WIDTH (1)
in mpconfigoard.h (and compiling, uploading)
changed the situation with regard to my old 64MB SDCards only slightly.
before:

Code: Select all

>>> import os
>>> os.listdir('/')
['flash']
>>> sd = pyb.SDCard()
>>> sd.present()
True
>>> os.mount(sd,'/sd')
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  OSError: 16
after:

Code: Select all

>>> import os
>>> os.listdir('/')
['flash']
>>> sd = pyb.SDCard()
>>> sd.present()
True
>>> os.mount(sd,'/sd')
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  OSError: [Errno 19] ENODEV
Still no possibility to access these old SDCards.?

Re: I can't access microSD cards with Pyboard 1.1

Posted: Sun Sep 19, 2021 11:35 am
by rkompass
There is a python-only SD-Card driver in the micropython github repository under /drivers/sdcard.
Using it with soft-spi made it possible to access my older SD-Card.

Code: Select all

# Starts SDCard with SoftSPI and mounts it to '/sd'.
# Should work with older SDCards on the Pyboard
# Code adapted from Peter Hinch's sdtest.py

import os, sdcard, machine

spi = machine.SoftSPI(baudrate=400000, sck=pyb.Pin('C12'), mosi=pyb.Pin('D2'), miso=pyb.Pin('C8'))
spi.init()                               # Ensure right baudrate
sd = sdcard.SDCard(spi, pyb.Pin('C11'))
os.mount(sd, "/sd")
Apparently the python driver has more intelligence built in. The costs are 5 KB memory.

Re: I can't access microSD cards with Pyboard 1.1

Posted: Sun Sep 19, 2021 5:47 pm
by scruss
rkompass wrote:
Sun Sep 19, 2021 11:35 am
There is a python-only SD-Card driver in the micropython github repository under /drivers/sdcard.
This is the same sdcard.py that I've used with every MicroPython board I own. It changed a few months ago to be more compatible with slower cards.