Hi everyone. Im trying to read a micro SD card using an USB adapter on the USB host port.
The micropython machine module doesn't have the SDCard class, so I cannot access to the card like I do with other boards:
>>> sd = machine.SDCard()
AttributeError: 'module' object has no attribute 'SDCard'
I didn't find any access to the usb-host and Ethernet into the libraries, also trying with the Ethernet shield V2 (WIZnet W5500), I got same error, it seems missing into the firmware. Also the network module is present but available WLAN only: WiFi works fine but network.LAN is missing too.
I'm not sure it should be done differently or those functionalities still under development, I also tried Nightly builds v1.19.1-992->995 (all available) without success.
About the schematic, I simply plugged a USB-microSD adapter into the usb-host port of the GIGA R1 (same adapter I use to read and write the micro sd with the PC), so I have no schematic about it (if any).
About the ethernet and other micro SD slot, the schematic is from the original Arduino Ethernet Shield V2. Whole test I did so far didn't involve a single wire, it's simply a micropython test: >>> import machine >>> sd = machine.SDCard() # this is the code
AttributeError: 'module' object has no attribute 'SDCard'
About the network, the code is almost the same, but just as quick check, I simply did: >>> import network >>> dir(network)
['class', 'name', 'dict', 'AP_IF', 'STA_IF', 'WLAN', 'route']
As you can see there is no LAN in this module to play with.
I believe machine.SDCard is a module designed for use with SPI protocol
These are the first few lines I use with an ESP32, adjust the SPI pins accordingly and see if it yields any positive results in the REPL
import machine
from machine import Pin,SPI,SDCard
import os
# Initialize the SD card ........ these parameters will likely be different for the GIGA
machine.SDCard(2,sck=Pin(18),mosi=Pin(23),miso=Pin(19),cs=5)
Thank you sumguy, this was exactly my intention, but there is no SDCard class: >>> from machine import Pin,SPI,SDCard
ImportError: can't import name SDCard
That is odd, we both have Micropython but obviously a difference in the contents of the two packages, sorry I don't know enough about the GIGA to provide more help.
I believe that some classes are missing because the micropython GIGA R1 firmware (GIGAR1_MP_FW.dfu) it's an early release and possibly many classes still under development...
Just trying to write it by myself from this:
If you are sure that there is no sd card module with your micropython port you might find the module you need through another source, this goes for any other library you might require. The following repository has many such libraries and the instructions on how to install them.
This is my last try:
copy https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/storage/sdcard/sdcard.py
into /flash (root)
this module needs micropython and time modules only, I'm just trying to create an sd instance, my code is:
import pyb, sdcard, os
pd10 = pyb.Pin.cpu.D10 # ETH CS pin on Ethernet Shield 2
pd4 = pyb.Pin.cpu.D4 # SD CS pin on Ethernet Shield 2
pg7 = pyb.Pin.cpu.G7 # PIN 53? ...on Arduino MEGA
pd10.init(pd10.OUT, value=0) # disable ETH CS (SPI chip select)
pd4.init(pd4.OUT, value=1) # enable SPI SD CS. ...useless, sdcard.py will do it
pg7.init(pg7.OUT, value=1) # is this the hardware SS pin?
sd = sdcard.sdcard(pyb.SPI(1), pyb.Pin.cpu.D4)
OSError: no SD card
My first try was without pin PG7 setting, then I found on the Arduino Ethernet Shield 2 tech spec: "On the Mega, the hardware SS pin, 53, is not used to select either the W5500 or the SD card, but it must be kept as an output or the SPI interface won't work."; without saying anything about the GIGA R1, my best guess is to map it on the PG7, simply in the same position, but I didn't find the hardware SS on the GIGA board.
Also I've noticed that pyb.SPI(1) and machine.SPI(1) are different: pyb.SPI(1).MASTER leads the sdcard initialization as "pyboard", machine.SPI(1) doesn't have MASTER attribute and the init is like the "ESP8266", so I've tried all combination with pyb, machine, SPI(1) and SPI(5) with no luck.