MicroPython: SDCard - lvidarte/esp8266 GitHub Wiki

https://raw.githubusercontent.com/lvidarte/esp8266/master/examples/sdcard/sdcard.png

Ref: Adafruit - MicroPython Hardware: SD Cards

Download the sdcard.py module. Next use a tool like ampy to copy the sdcard.py file to the root of the board's filesystem:

$ ampy --port /dev/ttyUSB0 put sdcard.py

Mount SD Card:

>>> import machine, sdcard, os
>>> sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
>>> os.umount()
>>> os.VfsFat(sd, "")
>>> os.listdir()
['somefile']

Then write a file

>>> f = open('test', 'w')
>>> f.write('hello world')
11
>>> f.close()
>>> os.listdir()
['somefile', 'test']

Then read a file

>>> f = open('test', 'r')
>>> f.read()
'hello world'
>>> f.close()