<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SD mount fail on M5Stack basic]]></title><description><![CDATA[<p dir="auto">Hi all, I have problems with lovyan launcher... now the app doesn,t open the sd of the stack basic..</p>
<p dir="auto">when I burn lovyan launcher with M5burner in a M5stack basic, the sd fail... same proces on a M5Stack gray, works...</p>
<p dir="auto">on a basic unit, with this sketch, sd fail!!</p>
<pre><code>/*
*******************************************************************************
* Copyright (c) 2022 by M5Stack
*                  Equipped with M5Core sample source code
*                          配套  M5Core 示例源代码
* Visit for more information: https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
*
* Describe: TF Card. TF卡
* Date: 2022/3/25
*******************************************************************************
    In this example, we will detect the existence of a file and perform read and
    write operations on it
    在这个示例中,我们将会检测某文件是否存在,并进行读写文件操作
*/

#include &lt;M5Stack.h&gt;

void setup() {
    M5.begin();
    if (!SD.begin()) {  // Initialize the SD card. 初始化SD卡
        M5.Lcd.println(
            "Card failed, or not present");  // Print a message if the SD card
                                             // initialization fails or if the
                                             // SD card does not exist
                                             // 如果SD卡初始化失败或者SD卡不存在，则打印消息
        while (1)
            ;
    }
    M5.Lcd.println("TF card initialized.");
    if (SD.exists("/hello.txt")) {  // Check if the "/hello.txt" file
                                    // exists.查看是否存在"/hello.txt"文件
        M5.Lcd.println("hello.txt exists.");
    } else {
        M5.Lcd.println("hello.txt doesn't exist.");
    }
    M5.Lcd.println("Creating hello.txt");
    File myFile = SD.open("/hello.txt",
                          FILE_WRITE);  // Create a new file "/hello.txt".
                                        // 创建一个新文件"/hello.txt"
    if (myFile) {  // If the file is open, then write to it.
                   // 如果文件打开,则进行写入操作
        M5.Lcd.println("Writing to test.txt...");
        myFile.println("SD test.");
        myFile.close();  // Close the file. 关闭文件
        M5.Lcd.println("done.");
    } else {
        M5.Lcd.println("error opening test.txt");
    }
    delay(500);
    myFile = SD.open("/hello.txt",
                     FILE_READ);  // Open the file "/hello.txt" in read mode.
                                  // 以读取模式打开文件"/hello.txt"
    if (myFile) {
        M5.Lcd.println("/hello.txt Content:");
        // Read the data from the file and print it until the reading is
        // complete. 从文件里读取数据并打印到串口,直到读取完成.
        while (myFile.available()) {
            M5.Lcd.write(myFile.read());
        }
        myFile.close();
    } else {
        M5.Lcd.println("error opening /hello.txt");  // If the file is not open.
                                                     // 如果文件没有打开
    }
}

void loop() {
}
</code></pre>
<p dir="auto">.... on basic unit with this sketch, sd works</p>
<pre><code>// Libraries for SD card
#include "FS.h"
#include &lt;SD.h&gt;
//#include "mySD.h"
#include &lt;SPI.h&gt;


// Define CS pin for the SD card module
#define SD_MISO     19
#define SD_MOSI     23
#define SD_SCLK     18
#define SD_CS       4
SPIClass sdSPI(VSPI);

String dataMessage;

void setup() {
  // Start serial communication for debugging purposes
  Serial.begin(115200);
 
  // Initialize SD card
  //SD.begin(SD_CS);  
  sdSPI.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
  if(!SD.begin(SD_CS, sdSPI)) {
    Serial.println("Card Mount Failed");
    return;
  }
  Serial.println("1");
  uint8_t cardType = SD.cardType();
  if(cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    return;
  }
  Serial.println("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("ERROR - SD card initialization failed!");
    return;    // init failed
  }
  Serial.println("2");
  // If the data.txt file doesn't exist
  // Create a file on the SD card and write the data labels
  File file = SD.open("/data1.txt");
  if(!file) {
    Serial.println("File doens't exist");
    Serial.println("Creating file...");
    writeFile(SD, "/data1.txt", "Reading ID, Date, Hour, Temperature \r\n");
  }
  else {
    Serial.println("File already exists");  
  }
  file.close();
  logSDCard();
  
}

void loop() {
  // The ESP32 will be in deep sleep
  // it never reaches the loop()
}

// Write the sensor readings on the SD card
void logSDCard() {
  //dataMessage = String(readingID) + "," + String(dayStamp) + "," + String(timeStamp) + "," + 
  //              String(temperature) + "\r\n";
  dataMessage = "Hello World \n";
  Serial.print("Save data: ");
  Serial.println(dataMessage);
  appendFile(SD, "/data1.txt", dataMessage.c_str());
}

// Write to the SD card (DON'T MODIFY THIS FUNCTION)
void writeFile(fs::FS &amp;fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if(!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if(file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  file.close();
}

// Append data to the SD card (DON'T MODIFY THIS FUNCTION)
void appendFile(fs::FS &amp;fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if(!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if(file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}
</code></pre>
<p dir="auto">maybe I have to change some pins assignement some where??</p>
<p dir="auto">tnks a lot!!</p>
]]></description><link>https://community.m5stack.com/topic/4770/sd-mount-fail-on-m5stack-basic</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 17:15:45 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/4770.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 31 Oct 2022 14:00:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SD mount fail on M5Stack basic on Sat, 05 Nov 2022 10:01:27 GMT]]></title><description><![CDATA[<p dir="auto">the first sketch works, with M5Stack basic, if I modify the M5Stack.cpp library from:</p>
<pre><code>// TF Card
if (SDEnable == true) {
    SD.begin(TFCARD_CS_PIN, SPI, 40000000);
}
</code></pre>
<p dir="auto">to</p>
<pre><code>// TF Card
if (SDEnable == true) {
    SD.begin(TFCARD_CS_PIN, SPI, 10000000);
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/19209</link><guid isPermaLink="true">https://community.m5stack.com/post/19209</guid><dc:creator><![CDATA[cepics]]></dc:creator><pubDate>Sat, 05 Nov 2022 10:01:27 GMT</pubDate></item></channel></rss>