SD-Card support for Microbit's Micropython?

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
randmor
Posts: 18
Joined: Wed May 03, 2017 1:44 am

SD-Card support for Microbit's Micropython?

Post by randmor » Sat Sep 22, 2018 5:05 pm

Has anyone tried (and succeeded) at getting the GitHub SD card "driver" working on the BBC Micro:bit board? The URL is:
https://github.com/micropython/micropyt ... /sdcard.py

Looking at the code, there are comments to show you how to use it with pyboard and ESP8266-based boards. The code
also includes comments relating to Microbit, leading me to believe someone tried to put in Microbit support, but failed to
add the comments to document how to use it. Any assistance would be appreciated.

The SPI pins on the Microbit are 13, 14, 15 and (usually) 16 for Clock, MISO, MOSI and CS, respectively. If example for
ESP8266 is close to Microbit, we might try:

My first guess wasn't getting me anywhere.

Code: Select all


    from microbit import *              # May be needed for 'os', 'pin16' and 'spi'  ??
    
    import sdcard                          # Copy 'sdcard.py' to microbit's internal filesystem in flash memory beforehand.

    # Above 'import sdcard' command generates "MemoryError: memory allocation failed, allocating 1096 bytes" errors

    sd = sdcard.SDCard("", pin16)       # Microbit has a flat filesystem. So use null string or "\" ??  And pin16 for SPI CS line.
    os.mount(sd, '/sd')                       # No 'mount' or 'unmount' functions in Microbits' 'os' module.
    os.listdir('/')

Seems support is either preliminary, in flux or just not well documented.

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

Re: SD-Card support for Microbit's Micropython?

Post by rhubarbdog » Sun Sep 23, 2018 5:30 am

The memory error is because sdcard.py is too large to import.
Edit it to remove all unused code it may import
I doubt the microbit can support an spi SD card reader. it's just too under resourced.
The flash file system only supports opening files as 'r' or 'w', 'a' and '+' aren't implemented

Post Reply