How to write / read data to an SD card (memory card) micropython esp8266

Hello everyone.

I have esp8266mod nodemcu. With Micropython firmware esp8266-20191220-v1. 12.

I want to save data from the sensor to the SD card (this is the easiest way, I thought).

Crawling around the Internet, I found a video MicroPython Hardware: SD Card Storage with Tony D! @micropython in which Tony works with the SD card on the ESP8266. However, I don't have a nice adapter. What to do? Take a soldering iron and make an ugly one, google answered me. Having soldered the wires to the SDcard-microSDcard adapter, I ran into a question. What pins to connect the card to. Remembering the good word of the Chinese (and not really finding the information) I decided that I would connect to the" right side " D5 D6 D7.

Then I downloaded sdcard.py Uploaded it to the ESP. And ran the code from the example

#Example usage on ESP8266:
import machine, sdcard, os
sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
os.mount(sd, '/sd')
os.listdir('/')

To which repl replied to me

Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
OSError: [Errno 19] ENODEV

I'll do it like Tony, I thought, and ... by way of a scientific poke, I found an option that doesn't give out an error.

import machine, sdcard, os
sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
os.umount('/')
vfs = os.VfsFat(sd)

Hooray, I thought, and happily entered os. listdir().

>>> os.listdir()
[]

Mu answered me. I think ESPlorer would have answered the same way. Let's get started. My joy was boundless...

>>> f = open('text.txt', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 1] EPERM
>>> 

I guess I must have listened to something somewhere or missed it. Mostly because my English isn't as good as I'd like it to be. After reading the guide from the Adafruit website, I came to the same point and the same result. The card (Toshiba m203 16Gb) is formatted in FAT32.

Yes. I tried to throw a text file file to the map, listdir does not see it either.

Maybe there are instructions or code examples somewhere, preferably with both reading and writing.

Author: insolor, 2020-05-05