Accessing SD cards

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Accessing SD cards

Post by deshipu » Thu Aug 11, 2016 5:20 pm

I'm wondering about the ways to access an SD card. I know that currently the MicroPython port for ESP8266 doesn't support mounting two filesystems at the same time, but I wonder if we could unmount the internal filesystem and mount the one on the SD card in its place? What other pieces would be then missing to get this working?

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Accessing SD cards

Post by markxr » Thu Aug 11, 2016 7:37 pm

Which module are you using which supports an SD card?

None of mine obviously do.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Accessing SD cards

Post by deshipu » Thu Aug 11, 2016 10:45 pm

You simply connect an SD card with SPI. There are shields both for the Adafruit HUZZAH Feather (https://www.adafruit.com/products/2922) and for the WeMos D1 Mini (http://www.wemos.cc/Products/micro_sd_shield.html). Also many TFT displays modules include an SD card socket, because it's common to need them for storing the graphics -- those can be used too.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accessing SD cards

Post by pythoncoder » Fri Aug 12, 2016 3:24 pm

I wonder where in the developers' roadmap mounting more filesystems is placed. It would be great to have this feature. I came unstuck with this when I tried porting my ferroelectric RAM driver.
Peter Hinch
Index to my micropython libraries.

mad474
Posts: 60
Joined: Sun Dec 29, 2013 7:48 pm

Re: Accessing SD cards

Post by mad474 » Fri Aug 12, 2016 7:14 pm

pythoncoder wrote:It would be great to have this feature
ACK ... and picture completes together with DB module. (viewtopic.php?f=16&t=2043)

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: Accessing SD cards

Post by markxr » Sat Aug 13, 2016 1:43 pm

Does it use the same SPI pins as the built-in SPI flash on the modules (e.g. ESP-12) ?

Is there some chip-select line or something?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Accessing SD cards

Post by deshipu » Sat Aug 13, 2016 9:57 pm

No, you need to use the second SPI or the software SPI. There is a chip select pin on the flash SPI, but using it together with running your program from flash is a bit tricky.

jms
Posts: 108
Joined: Thu May 05, 2016 8:29 pm
Contact:

Re: Accessing SD cards

Post by jms » Tue Aug 16, 2016 5:11 pm

My ever so nearly working SPIFFS code gets around the second file system problem by defining its own open method.

Once you have the filehandle it works as you'd expect. So for the time being one would use the existing (and now smaller) FAT filesystem for Python code and SPIFFS for data and logfiles.

Jon

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Accessing SD cards

Post by deshipu » Mon Aug 22, 2016 10:01 am

So, to answer my own question, yes, it is possible. I just did it.

First, you need to comment out the mounting of the filesystem in the modules/_boot.py

Then you need to import the sdcard code (from https://bitbucket.org/thesheep/micropyt ... /sdcard.py) and run the esp8266_mount function from it.

Then you can use the sd card as your storage.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accessing SD cards

Post by pythoncoder » Mon Aug 22, 2016 10:46 am

Nice one :D
Peter Hinch
Index to my micropython libraries.

Post Reply