microSD card reading with mp on Feather Huzzah

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
federicomonaldi72
 
Posts: 8
Joined: Mon Mar 20, 2017 3:02 pm

microSD card reading with mp on Feather Huzzah

Post by federicomonaldi72 »

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 - that the problem could be
or in the sdcard.py driver or in the mp firmware that I have installed on the two
Adafruit ESP boards.

Reference from Adafruit uSD board literature:
https://learn.adafruit.com/micropython- ... 6?view=all.

=== 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 adapter pin Huzzah or Feather Huzzah pin
=== CLK 14. SCK
=== DO 12. MI
=== DI 13. MO
=== CS 15. 15
=== 3v 3V3
=== 5v. USB
=== """
=== 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
huzzah_no_SD_card.jpg
huzzah_no_SD_card.jpg (195.1 KiB) Viewed 1454 times
feather_huzzah_no_SD_card.jpg
feather_huzzah_no_SD_card.jpg (246.48 KiB) Viewed 1454 times
NodeMCU_AdafruitSDca_reading_success.jpg
NodeMCU_AdafruitSDca_reading_success.jpg (248.41 KiB) Viewed 1490 times
Last edited by federicomonaldi72 on Fri May 26, 2017 7:46 pm, edited 1 time in total.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: microSD card reading with mp on Feather Huzzah

Post by adafruit_support_mike »

[moved to the MicroPython forum]

User avatar
federicomonaldi72
 
Posts: 8
Joined: Mon Mar 20, 2017 3:02 pm

Re: microSD card reading with mp on Feather Huzzah

Post by federicomonaldi72 »

I have already placed an issue about this topic ( some day ago) on the suggested address, but until now, without any feedback.

Regards
Federico Monaldi
Attachments
Micropython Forum
Micropython Forum
Forum_micropython.png (296.15 KiB) Viewed 1465 times

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: microSD card reading with mp on Feather Huzzah

Post by tdicola »

Yeah the wiring looks good from what you mentioned and show, and it's interesting you see the card working with NoceMCU but not micropython. I think your best option is to follow up in the MicroPython forums since they maintain the SD card driver. If it helps the failure is happening right here at the start of initialization: https://github.com/micropython/micropyt ... py#L77-L82 So likely micropython isn't able to talk to the SD card as it expects--like if the SPI bus should be a different value or a wire/connection isn't making a good connection.

User avatar
federicomonaldi72
 
Posts: 8
Joined: Mon Mar 20, 2017 3:02 pm

Re: microSD card reading with mp on Feather Huzzah

Post by federicomonaldi72 »

Hello Tony,
thank you for yours consideration that I have
appreciated and also for yours
great technical micropython literature. I have already placed a request
about this topic on the micropython forum and I am waiting for good news.

Best regards and newly many thanks.

Federico Monaldi

User avatar
federicomonaldi72
 
Posts: 8
Joined: Mon Mar 20, 2017 3:02 pm

Re: microSD card reading with mp on Feather Huzzah

Post by federicomonaldi72 »

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.

About the sintax in the sdcard.py examples
we have :
Example usage on ESP8266:

import machine, sdcard, os
sd = sdcard.SDCard(machine.SPI(0), machine.Pin(15))
os.umount(). (*)
os.VfsFat(sd, ""). (*)
os.listdir()

(*) with the new release 1.9 the functions
sintax is changed

for reference see the following

This is now fixed, esp8266's internal flash FS is mounted at /.

ESP8266  os.umount() function
from :
https://github.com/micropython/micropython/issues/2920

RFC: filesystem layout, VFS and user mounting #2920

dpgeorge commented Feb 28, 2017

As brought up in #2850, there has been a change to esp8266's filesystem. Previous to the change the root dir was the one-and-only filesystem, being a FatFS filesystem backed by the flash. After the change, the root dir is a virtual filesystem upon which you can mount an abritary number of filesystems, of whatever type you like (included one implemented purely in Python).

This change makes esp8266 the same as pyboard/stmhal: the flash is mounted at /flash. And you can mount an SD card at /sd.

If you unmount everything (eg os.umount('/flash')) you still have the root dir, and can then mount filesystems there again (eg os.mount(flashbdev, '/flash2')).

Ciao ed ancora grazie
Federico Monaldi
Attachments
feather_huzzah_mp_SD_reading_OK.jpg
feather_huzzah_mp_SD_reading_OK.jpg (217.34 KiB) Viewed 1410 times

User avatar
stecrz
 
Posts: 1
Joined: Mon Aug 07, 2017 8:24 am

Re: microSD card reading with mp on Feather Huzzah

Post by stecrz »

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 (without the listdir commands) in root.py if you automatically want the system to do this after reset (see here)

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”