Utilize Expansion module SD card with Arduino code



  • Re: Utilize Expansion module SD card with Arduino code

    Apologies, I had originally posted in LoPy, but now I think this is really belongs here in Expansion Board. Unfortunately, I think I won't be able to be helped unless someone is willing to fire up Arduino. Please understand I can get the SD card working in MicroPython, that's just not what I'm doing here.

    I am working under the assumption that the pins the Expansion Board uses for the SD card are SD: P8: DAT0, P23: SCLK and P4: CMD.

    The thread in LoPy4 details how far I've gotten. Spoiler alert: not very.

    tl;dr the SD_MMC sketch complains about missing pullups, and that message goes away when I start using internal pullups in my code. Yet I still cannot mount the SD card. I've tried different cards (all Sandisk Ultra - the same used successfully under MicroPython)

    More detailed error logs available in the other thread using different methods - native SD, native SD_MMC and SPI

    I would be incredibly grateful if someone else was willing to try to mount an SD card using Arduino.

    Thanks in advance!



  • Answering my own question in case anyone else is interested in this.

    Accessing the SD card on the Expansion module seems to be exclusively done with the SD_MMC library in arduino. Specifically in 1-bit mode. Internal pullups are required.

    This works for me:

     /*
     * Connect the SD card to the following pins:
     *
     * SD Card | ESP32
     *    D2       12
     *    D3       13
     *    CMD      15
     *    VSS      GND
     *    VDD      3.3V
     *    CLK      14
     *    VSS      GND
     *    D0       2  (add 1K pull up after flashing)
     *    D1       4
     */
    
    #include "FS.h"
    #include "SD_MMC.h"
    
    
    void setup(){
        Serial.begin(115200);
        
        pinMode(2, INPUT_PULLUP);
        pinMode(4, INPUT_PULLUP);
        pinMode(15, INPUT_PULLUP);
        
         
    
        if(!SD_MMC.begin("/sdcard",true)){    // First arg = mount point, Second arg is 1-bit-mode
            Serial.println("Card Mount Failed");
            return;
            
        }
        uint8_t cardType = SD_MMC.cardType();
    
        if(cardType == CARD_NONE){
            Serial.println("No SD_MMC card attached");
            return;
        }
         Serial.print("SD_MMC Card Type: ");
        if(cardType == CARD_MMC){
            Serial.println("MMC");
        } else if(cardType == CARD_SD){
            Serial.println("SDSC");
        } else if(cardType == CARD_SDHC){
            Serial.println("SDHC");
        } else {
            Serial.println("UNKNOWN");
        }
    
        uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
        Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
        
    }
    void loop(){
    
    }

Log in to reply
 

Pycom on Twitter