very strange behavior with sd and nodemcu

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
nodepythoner
Posts: 11
Joined: Sat Apr 20, 2019 8:44 am

very strange behavior with sd and nodemcu

Post by nodepythoner » Sat Apr 20, 2019 8:59 am

i connected sd module with nodemcu board(software spi) and wrote some code:

import machine, sdcard, os
Pin = machine.Pin
cs = Pin(0)
mosi = Pin(5)
miso = Pin(16)
sck = Pin(4)
spi = machine.SPI(-1,sck = sck, mosi = mosi, miso = miso)
sd = sdcard.SDCard(spi, cs)
vfs = os.VfsFat(sd) #eio
os.mount(vfs, '/sd')
os.chdir('sd')
f = open('test', 'w')
f.write('hello world')
f.close()

with 2gb sdcard i get
OSError: [Errno 5] EIO
in vfs = os.VfsFat(sd) line

with 4 gb card i get freeze of the board in
sd = sdcard.SDCard(spi, cs) line

micropython version: esp8266-20190125-v1.10.bin
sd library i downloaded here https://learn.adafruit.com/micropython- ... icropython (green button)

User avatar
Roberthh
Posts: 1402
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: very strange behavior with sd and nodemcu

Post by Roberthh » Sat Apr 20, 2019 1:26 pm

I'm using the same driver on a WEMOS D1 Mini with its SD card daughterboard. It works, but requires sometime a second reset or power cycle before the card is detected. Please take care that the cards only contain a single FAT or FAT32 partition. Upon delivery, Micro-SD cards ofter have another hidden partition, which does not interfere the regular operation systems, but confuses the simple SD card driver.

nodepythoner
Posts: 11
Joined: Sat Apr 20, 2019 8:44 am

Re: very strange behavior with sd and nodemcu

Post by nodepythoner » Sat Apr 20, 2019 2:34 pm

with 4 gb card works well. i used 3.3v but this module working from 5 volts(it is module for arduino)
but with 2 gb card also EIO

User avatar
Roberthh
Posts: 1402
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: very strange behavior with sd and nodemcu

Post by Roberthh » Sat Apr 20, 2019 4:03 pm

I made the experience that not every card works. And a 5V module includes a regulator, which are not needed with the NodeMCU. Take care that the supply voltage of the SD card is sufficient. If the Module has a regulator, you may supply it with 5V. The output level of MISO should still be at 3.3 V.

Post Reply