🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    TAB5 SD doesnt work in Arduino IDE

    PRODUCTS
    5
    7
    107
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      Krmiller
      last edited by

      I have been trying to convert some core2 code to work with Tab5 with little success when in comes to the microSD. I have chatted with chat.m5stack.com to get some minimal working code and it still doesn't work. I have tested on known good cards and 2 new TAB5s.

      Here's the code from their chat bot (doesn't work)
      thanks for any direction,
      Kris

      #include <M5Unified.h>
      #include <SPI.h> // Include SPI library
      #include <SD.h> // Include Arduino SD library

      // Tab5 SD card SPI pin definitions
      #define SD_CS_PIN 4
      #define SD_SCK_PIN 18
      #define SD_MISO_PIN 19
      #define SD_MOSI_PIN 23

      void setup() {
      auto cfg = M5.config();
      M5.begin(cfg); // Initialize M5Unified

      // Initialize SPI for SD card
      SPI.begin(SD_SCK_PIN, SD_MISO_PIN, SD_MOSI_PIN, SD_CS_PIN);

      // Initialize SD card with specified CS pin and speed (25MHz)
      if (!SD.begin(SD_CS_PIN, SPI, 25000000)) {
      M5.Lcd.println("SD Card failed!");
      while (1); // Halt if failed
      }
      M5.Lcd.println("SD Card initialized.");
      }

      void loop() {}

      felmueF 1 Reply Last reply Reply Quote 0
      • felmueF
        felmue @Krmiller
        last edited by

        Hello @Krmiller

        I tried talking to the SD card on my M5Tab5 using Arduino myself but without any luck.

        I think that maybe the Arduino SD library isn't ready (yet) for the ESP32-P4 in M5Tab5. See here - ESP32-P4 is not listed.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        K 1 Reply Last reply Reply Quote 0
        • K
          Krmiller @felmue
          last edited by

          @felmue Thanks for testing Felix. If you hear of any work arounds, please let us know.

          felmueF 1 Reply Last reply Reply Quote 0
          • felmueF
            felmue @Krmiller
            last edited by

            Hello @Krmiller

            I found another example using SDIO (instead of SPI) which works for me. You can find the correct GPIOs here - section: microSD SDIO mode.

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            P 1 Reply Last reply Reply Quote 0
            • S
              sapphire
              last edited by

              I managed to get the SD card reader to work.

              H_SDIO_DRV error: sdio card init failed
              The WiFi module (ESP32-C6) uses an independent set of dedicated pins (SDIO2_D0 to SDIO2_CK), thus avoiding any physical interface overlap and conflicts.

              sd_mmc_card:
              id: sd_card
              clk_pin: GPIO43
              cmd_pin: GPIO44
              data0_pin: GPIO39
              data1_pin: GPIO40
              data2_pin: GPIO41
              data3_pin: GPIO42
              mode_1bit: false
              slot: 0

              esp32_hosted:
              variant: esp32c6
              active_high: true
              clk_pin: GPIO12
              cmd_pin: GPIO13
              d0_pin: GPIO11
              d1_pin: GPIO10
              d2_pin: GPIO9
              d3_pin: GPIO8
              reset_pin: GPIO15
              slot: 1

              1 Reply Last reply Reply Quote 0
              • P
                Powersoft @felmue
                last edited by

                @felmue Thanks for this, please can you post an simple example that works with the changes in the example you mentiod to get it run on the Tab5. That wil be great.

                1 Reply Last reply Reply Quote 0
                • S
                  SiberianHamster
                  last edited by

                  The best, fastest and most reliable way I've found to access the µSD card on the Tab5 is via the SD_MMC.h library. Try the below;

                  #include <M5Unified.h>
                  #include <SD_MMC.h>
                  
                  #define sd_D0 GPIO_NUM_39
                  #define sd_D1 GPIO_NUM_40
                  #define sd_D2 GPIO_NUM_41
                  #define sd_D3 GPIO_NUM_42
                  #define sd_CLK GPIO_NUM_43
                  #define sd_CMD GPIO_NUM_44
                  
                  #define GPS_RX_PIN 48  // CoreS3 GPIO RX
                  #define GPS_TX_PIN 2  // CoreS3 GPIO TX
                  
                  #define sd_speed 20000
                  
                  void setup() {
                    M5.delay(500);
                    M5.begin();
                    M5.Lcd.setTextColor(GREEN, BLACK);
                    M5.Lcd.setTextFont(2);
                    SD_MMC.setPins(sd_CLK, sd_CMD, sd_D0, sd_D1, sd_D2, sd_D3);
                    M5.Lcd.println("Mounting Tab5 µSD");
                    //M5.delay(5000);
                    if (!SD_MMC.begin("/sdcard", false, false, sd_speed)) { // SD_MMC.begin("/sdcard", false, false, sd_speed)
                      M5.Lcd.println("µSD mount failed!");
                      while (1);
                    } else {
                      M5.Lcd.println("µSD mounted.");
                    }
                  
                    // List files on SD card root
                    File root = SD_MMC.open("/");
                    if (!root) {
                      M5.Lcd.println("Failed to open root dir");
                    } else {
                      M5.Lcd.println("Files:");
                      File file = root.openNextFile();
                      while (file) {
                        M5.Lcd.println(file.name());
                        file = root.openNextFile();
                      }
                      root.close();
                    }
                  }
                  
                  void loop() {
                    M5.delay(50);
                  }
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post