microSD card reading

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
federico
Posts: 6
Joined: Tue Feb 07, 2017 11:34 pm

microSD card reading

Post by federico » Wed May 24, 2017 4:18 pm

Object : microSD card reading on FeatherHuzzah and Huzzah ESP8266 boards
with installed micropython firmware.
** for more details about the used firmware see the following upython REPL session report.

As microSD card adapter a Adafruit Micro-SD breakout board is used.
The same SD adapter has been used with a NodeMCU dev board with
a Lua firmware installed. As we can see from the jpeg attachment, from
the ESPlorer session, the SD card reading has been positive. This result
demonstrate that we are working with good SD card adapter e that with Lua
we do not have problems.
I suppose - if I do not have done some wiring error that you can verify from the
attached pictures or from the wiring description - that the problem could be
or in the sdcard.py driver or in the firmware that I have installed on the two
Adafruit ESP boards.

=== MicroPython REPL session ===
>>> dir()
['uos', '__name__', 'webrepl', 'gc', 'bdev', 'vfs']
>>> uos.listdir()
['boot.py', 'webrepl_cfg.py', 'tpa.py', 'sdcard.py', 'bmp180.py']
>>> uos.uname()
(sysname='esp8266', nodename='esp8266', release='2.0.0(5a875ba)', version='v1.8.7-7-gb5a1a20a3 on 2017-01-09', machine='ESP module with ESP8266')
>>> f = open('boot.py', 'r+')
>>> src = f.read()
>>> print(src)
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import gc
import webrepl
webrepl.start()
gc.collect()

>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== """
=== Example taken from from sdcard.py driver file
=== making the following change :
=== machine.SPI(0) becames machine.SPI(1)
===
=== Adafruit hardware wiring
=== SD card adapter pin Huzzah or Feather Huzzah pin
=== CLK 14
=== DO 12
=== DI 13
=== CS 15
=== 3v 3V3
=== 5v
=== """
=== import machine, sdcard, os
=== sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
===
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
File "sdcard.py", line 54, in __init__
File "sdcard.py", line 82, in init_card
OSError: no SD card
>>>
Attachments
sd_mount_succes.jpg
NodeMCU Lua firmware
sd_mount_succes.jpg (248.41 KiB) Viewed 4541 times

federico
Posts: 6
Joined: Tue Feb 07, 2017 11:34 pm

Re: microSD card reading

Post by federico » Thu Jun 01, 2017 2:41 pm

The following my last email to Adafruit close
the question about the SD reading .

https://forums.adafruit.com/viewtopic.p ... 91#p590291

Hi Tony,
thank to your final hypothesis I newly examined the wiring circuit and an important detail regarding the clock pin
#14 make born the suspect that the DS18B20P data connection with this pin
were the source of the problem. As you can
see from the attachment, it was sufficient to
remove the DS18B20P data pin connection with the FeatherHuzzah pin14 and the SD reading problem was solved.
Ciao ed ancora grazie
Federico Monaldi

crizeo
Posts: 38
Joined: Sun Aug 06, 2017 12:55 pm
Location: Germany

Re: microSD card reading

Post by crizeo » Tue Aug 08, 2017 10:44 am

For those still wondering how to setup an SD card module on the ESP8266 using MicroPython 1.9.1 (as the process changed a bit, it is a lot easier now):
  • Copy sdcard.py to the board (e.g. using ampy)
  • Wiring SD card module <-> ESP8266 (GPIO):
    • GND <-> GND
    • DO/MISO <-> MISO (12)
    • DI/MOSI <-> MOSI (13)
    • CLK/SCK <-> SCK (14)
    • CS <-> CS (15)
    • VCC <-> VCC 3.3V/5V (Check your modules specification! If it has a voltage regulator on it (as mine), it probably requires 4.5~5.5V input, otherwise 3.3V. As the ESP8266 only supplies 3.3V output, you may need an external 5V power source. Some modules like the Feather HUZZAH are powered by USB and therefore have a 5V output (called USB / VBUS on the Feather). If not, connect the external power sources VCC to the SD modules VCC (and power sources GND to ESP8266 GND). If your module works with 3.3V you can simply connect VCC <-> VCC 3.3V of course)
  • Hard reset the ESP8266 (this may be required or may not?)
  • Run the following commands on your ESP:

    Code: Select all

    import os, machine, sdcard
    sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))  # hard reset required after wiring
    #os.umount('/')       # only if you want to unmount flash (NOT REQUIRED!)
    vfs = os.VfsFat(sd)   # is this required?
    os.mount(vfs, '/sd')   # or '/' if you did the umount command before
    #os.listdir()         # you'll see a new '/sd' folder
    #os.statvfs('/sd')	 # size of sd card = [0]*[2] bytes (free: [0]*[3])
    os.chdir('sd')        # to change directory (if you kept '/')
    #os.listdir()         # you'll see the sd card's contents (or listdir('/sd') from outside)
  • Put the code in boot.py if you automatically want the system to do this after reset (see here). If you want main.py on your SD card to be run instead of main.py on the ESP, you will need to do the os.unmount('/') command and instead of mounting to '/sd' mount to '/'. Then put your 'main.py' on your sd card and it will be run after boot.py.
Last edited by crizeo on Wed Aug 09, 2017 10:41 am, edited 2 times in total.

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

Re: microSD card reading

Post by deshipu » Tue Aug 08, 2017 3:09 pm

crizeo wrote:
  • Put the code in root.py if you automatically want the system to do this after reset (see here)
You mean boot.py?

crizeo
Posts: 38
Joined: Sun Aug 06, 2017 12:55 pm
Location: Germany

Re: microSD card reading

Post by crizeo » Tue Aug 08, 2017 7:23 pm

My bad, sorry. Edited the post, thanks!

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

Re: microSD card reading

Post by deshipu » Tue Aug 08, 2017 10:23 pm

Thanks for figuring this out. I wonder if we could push that to documentation, so that the cores can confirm that this is indeed the correct and officially supported way of doing things.

vahithosan
Posts: 9
Joined: Wed Jul 26, 2017 5:15 pm

Re: microSD card reading

Post by vahithosan » Sun Aug 20, 2017 1:18 pm

Hi.

What is the CSD format.

Code: Select all

>>> import os, machine, sdcard
>>> sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15))
  File "<stdin>", line 1, in <module>
  File "sdcard.py", line 54, in __init__
  File "sdcard.py", line 100, in init_card
OSError: SD card CSD format not supported
My sd card is fat32 formatted.

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

Re: microSD card reading

Post by pythoncoder » Mon Aug 21, 2017 6:04 am

CSD is the card specific data register on the microSD card. I'd re-test with another card from a known-good reputable manufacturer - there are a lot of dodgy and fake cards out there.
Peter Hinch

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

Re: microSD card reading

Post by Roberthh » Mon Aug 21, 2017 7:49 am

I see that error:
OSError: SD card CSD format not supported
often with a Wemos D1 and the Wemos SDcard shield, after the initial power up boot. After a hard reset while maintaining power, the device/SDCard work. After that, the card works fine. Seen with both Samsung amd Sandisk cards.

crizeo
Posts: 38
Joined: Sun Aug 06, 2017 12:55 pm
Location: Germany

Re: microSD card reading

Post by crizeo » Mon Aug 21, 2017 10:02 am

I always get this error with an old Nokia sdcard. You probably just want to use another sdcard (FAT32 is the correct format).

Post Reply