<?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[Problems writing to SD Card]]></title><description><![CDATA[<p dir="auto">Has anyone else had issues writing to SD on the stack?  I can place a file on an sd card and the read the directory and read the file.  I can read files that were previously written to the card manually, but writing has been a challenge.  I constructed this simple example to test writing and it fails every time.  I'm not sure what im doing wrong?  <em>(I used to have code to initialize the card, using the proper CS pin but have seen from other examples that it wasn't necesssary on the stack.  Writing didn't work for me either way)</em></p>
<pre><code>#include &lt;M5Stack.h&gt;

void setup() {

  M5.begin();

  Serial.begin(9600);

  char filename[] = "LOGGER00.CSV";

  File logfile = SD.open(filename, FILE_WRITE); 
  logfile.close();

  if (SD.exists(filename)) {
    Serial.println("LOGGER00.CSV exists.");
  } else {
    Serial.println("LOGGER00.CSV doesn't exist.");
  }


}


void loop() {
 M5.update();
}
</code></pre>
]]></description><link>https://community.m5stack.com/topic/184/problems-writing-to-sd-card</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 22:32:26 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/184.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Apr 2018 11:53:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problems writing to SD Card on Wed, 02 Nov 2022 13:58:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stoni99" aria-label="Profile: stoni99">@<bdi>stoni99</bdi></a> , yes, I have the same issue with my "picky" M5Stack. Samsung 64GB EVO plus XC Speedclass 3 are working fine, but I can no longer find it on Amazon. Sometimes Sundisk 32GB V30 are working, but in the next insert they refuse to work.  Is it really the card or the software?</p>
]]></description><link>https://community.m5stack.com/post/19187</link><guid isPermaLink="true">https://community.m5stack.com/post/19187</guid><dc:creator><![CDATA[PeterO]]></dc:creator><pubDate>Wed, 02 Nov 2022 13:58:24 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Mon, 17 Oct 2022 17:32:45 GMT]]></title><description><![CDATA[<p dir="auto">A third, newly ordered sd card works now. 👍It is a Verbatin 16Gb Premium microSDHC. The m5stack seems to be pretty picky?!</p>
]]></description><link>https://community.m5stack.com/post/19017</link><guid isPermaLink="true">https://community.m5stack.com/post/19017</guid><dc:creator><![CDATA[Stoni99]]></dc:creator><pubDate>Mon, 17 Oct 2022 17:32:45 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Sun, 16 Oct 2022 07:53:58 GMT]]></title><description><![CDATA[<p dir="auto">I tried it on my M5Stack Core with a SanDisk 32GB Fat32 and a Noname 4GB Fat32. Even repeated formatting did not lead to success. Do you have another tip for me?</p>
]]></description><link>https://community.m5stack.com/post/18985</link><guid isPermaLink="true">https://community.m5stack.com/post/18985</guid><dc:creator><![CDATA[Stoni99]]></dc:creator><pubDate>Sun, 16 Oct 2022 07:53:58 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Fri, 14 Oct 2022 16:31:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jj" aria-label="Profile: jj">@<bdi>jj</bdi></a> said in <a href="/post/883">Problems writing to SD Card</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vsthose" aria-label="Profile: vsthose">@<bdi>vsthose</bdi></a> Hi Vsthose,</p>
<p dir="auto">The following code should work provided you use a Micro SD / TF card that only has a few files on it.... too many and the display will run off the screen and you won't see the write to card and read back.</p>
<pre><code>
#include &lt;M5Stack.h&gt;
 
//Micro SD / TF Card Test

void listDir(fs::FS &amp;fs, const char * dirname, uint8_t levels){

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    Serial.printf("Listing directory: %s\n", dirname);
    M5.Lcd.printf("Listing directory: %s\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        M5.Lcd.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        M5.Lcd.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            M5.Lcd.print("  DIR : ");
            Serial.println(file.name());
            M5.Lcd.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            M5.Lcd.print("  FILE: ");
            Serial.print(file.name());
            M5.Lcd.print(file.name());
            Serial.print("  SIZE: ");
            M5.Lcd.print("  SIZE: ");
            Serial.println(file.size());
            M5.Lcd.println(file.size());
        }
        file = root.openNextFile();
    }
}

void readFile(fs::FS &amp;fs, const char * path) {
    Serial.printf("Reading file: %s\n", path);
    M5.Lcd.printf("Reading file: %s\n", path);

    File file = fs.open(path);
    if(!file){
        Serial.println("Failed to open file for reading");
        M5.Lcd.println("Failed to open file for reading");
        return;
    }

    Serial.print("Read from file: ");
    M5.Lcd.print("Read from file: ");
    while(file.available()){
        int ch = file.read();
        Serial.write(ch);
        M5.Lcd.write(ch);
    }
}

void writeFile(fs::FS &amp;fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\n", path);
    M5.Lcd.printf("Writing file: %s\n", path);

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

// the setup routine runs once when M5Stack starts up

void setup() { 
 
    // initialize the M5Stack object
    M5.begin();

    M5.startupLogo();
    Wire.begin();

    // Lcd display
    M5.Lcd.setBrightness(100);
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setCursor(0, 10);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.setTextSize(1);

    // Page Header
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setCursor(0, 05);
    M5.Lcd.printf("           Testing Micro SD Card Functions:\r\n");
    // digitalWrite(TFT_CS, 1);
 
    // Print blank line on screen
    M5.Lcd.printf(" \n    ");
    M5.Lcd.printf(" \n    ");
    
    listDir(SD, "/", 0);
    M5.Lcd.printf("");
    M5.Lcd.printf("");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    writeFile(SD, "/hello.txt", "Hello world from M5Stack !!");
    M5.Lcd.printf("");
    M5.Lcd.printf("");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    readFile(SD, "/hello.txt");
}

void loop() {

  // put your main code here, to run repeatedly:
   
    M5.update();
}
</code></pre>
</blockquote>
<p dir="auto">I tested the example. unfortunately it doesn't work for me. there are no folders or many other files on the card. what am I doing wrong?</p>
<p dir="auto">rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)<br />
configsip: 0, SPIWP:0xee<br />
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00<br />
mode:DIO, clock div:1<br />
load:0x3fff0030,len:1344<br />
load:0x40078000,len:13516<br />
load:0x40080400,len:3604<br />
entry 0x400805f0<br />
M5Stack initializing...OK<br />
Listing directory: /<br />
Failed to open directory<br />
Writing file: /hello.txt<br />
Failed to open file for writing<br />
Reading file: /hello.txt<br />
Failed to open file for reading</p>
]]></description><link>https://community.m5stack.com/post/18964</link><guid isPermaLink="true">https://community.m5stack.com/post/18964</guid><dc:creator><![CDATA[Stoni99]]></dc:creator><pubDate>Fri, 14 Oct 2022 16:31:44 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Thu, 17 May 2018 21:10:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/imro" aria-label="Profile: imro">@<bdi>imro</bdi></a></p>
<p dir="auto">Hi Imro,  no problem... glad it helped.</p>
<p dir="auto">That code is taken from the FactoryTest example that is part of the M5Stack library....</p>
<p dir="auto">The code in the examples is a useful source for learning how to make things happen on the M5Stack.</p>
]]></description><link>https://community.m5stack.com/post/990</link><guid isPermaLink="true">https://community.m5stack.com/post/990</guid><dc:creator><![CDATA[JJ]]></dc:creator><pubDate>Thu, 17 May 2018 21:10:18 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Thu, 17 May 2018 19:55:29 GMT]]></title><description><![CDATA[<p dir="auto">Thank you ! It helps !</p>
]]></description><link>https://community.m5stack.com/post/989</link><guid isPermaLink="true">https://community.m5stack.com/post/989</guid><dc:creator><![CDATA[ImRo]]></dc:creator><pubDate>Thu, 17 May 2018 19:55:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Mon, 23 Apr 2018 15:06:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vsthose" aria-label="Profile: vsthose">@<bdi>vsthose</bdi></a> No problem !  Would be great if the Arduino IDE could identify tiny errors like this....   We wait !</p>
]]></description><link>https://community.m5stack.com/post/886</link><guid isPermaLink="true">https://community.m5stack.com/post/886</guid><dc:creator><![CDATA[JJ]]></dc:creator><pubDate>Mon, 23 Apr 2018 15:06:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Mon, 23 Apr 2018 12:04:09 GMT]]></title><description><![CDATA[<p dir="auto">Thank you!</p>
<p dir="auto">I had started with those functions, but my function that retrieved data from the serial port was sending back a string and all these SD card functions require a Const Char * and I didn't have the skills yet to compensate.</p>
<p dir="auto">Ultimately, it came down to the path.  I was using "\filename.ext" and the SD card functions require "/filename.ext."  Instead of giving me a nice soft error message like "bad file path" or something, it just compiles and does nothing.</p>
<p dir="auto">I caught the difference when I was comparing your code to mine.  Thanks for the assistance!</p>
]]></description><link>https://community.m5stack.com/post/885</link><guid isPermaLink="true">https://community.m5stack.com/post/885</guid><dc:creator><![CDATA[vsthose]]></dc:creator><pubDate>Mon, 23 Apr 2018 12:04:09 GMT</pubDate></item><item><title><![CDATA[Reply to Problems writing to SD Card on Sun, 22 Apr 2018 06:19:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vsthose" aria-label="Profile: vsthose">@<bdi>vsthose</bdi></a> Hi Vsthose,</p>
<p dir="auto">The following code should work provided you use a Micro SD / TF card that only has a few files on it.... too many and the display will run off the screen and you won't see the write to card and read back.</p>
<pre><code>
#include &lt;M5Stack.h&gt;
 
//Micro SD / TF Card Test

void listDir(fs::FS &amp;fs, const char * dirname, uint8_t levels){

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    Serial.printf("Listing directory: %s\n", dirname);
    M5.Lcd.printf("Listing directory: %s\n", dirname);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        M5.Lcd.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        M5.Lcd.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
            Serial.print("  DIR : ");
            M5.Lcd.print("  DIR : ");
            Serial.println(file.name());
            M5.Lcd.println(file.name());
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            Serial.print("  FILE: ");
            M5.Lcd.print("  FILE: ");
            Serial.print(file.name());
            M5.Lcd.print(file.name());
            Serial.print("  SIZE: ");
            M5.Lcd.print("  SIZE: ");
            Serial.println(file.size());
            M5.Lcd.println(file.size());
        }
        file = root.openNextFile();
    }
}

void readFile(fs::FS &amp;fs, const char * path) {
    Serial.printf("Reading file: %s\n", path);
    M5.Lcd.printf("Reading file: %s\n", path);

    File file = fs.open(path);
    if(!file){
        Serial.println("Failed to open file for reading");
        M5.Lcd.println("Failed to open file for reading");
        return;
    }

    Serial.print("Read from file: ");
    M5.Lcd.print("Read from file: ");
    while(file.available()){
        int ch = file.read();
        Serial.write(ch);
        M5.Lcd.write(ch);
    }
}

void writeFile(fs::FS &amp;fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\n", path);
    M5.Lcd.printf("Writing file: %s\n", path);

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

// the setup routine runs once when M5Stack starts up

void setup() { 
 
    // initialize the M5Stack object
    M5.begin();

    M5.startupLogo();
    Wire.begin();

    // Lcd display
    M5.Lcd.setBrightness(100);
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setCursor(0, 10);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.setTextSize(1);

    // Page Header
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setCursor(0, 05);
    M5.Lcd.printf("           Testing Micro SD Card Functions:\r\n");
    // digitalWrite(TFT_CS, 1);
 
    // Print blank line on screen
    M5.Lcd.printf(" \n    ");
    M5.Lcd.printf(" \n    ");
    
    listDir(SD, "/", 0);
    M5.Lcd.printf("");
    M5.Lcd.printf("");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    writeFile(SD, "/hello.txt", "Hello world from M5Stack !!");
    M5.Lcd.printf("");
    M5.Lcd.printf("");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");

    // Print blank line on screen
    M5.Lcd.printf(" \n  ");
    M5.Lcd.printf(" \n  ");
    
    readFile(SD, "/hello.txt");
}

void loop() {

  // put your main code here, to run repeatedly:
   
    M5.update();
}</code></pre>
]]></description><link>https://community.m5stack.com/post/883</link><guid isPermaLink="true">https://community.m5stack.com/post/883</guid><dc:creator><![CDATA[JJ]]></dc:creator><pubDate>Sun, 22 Apr 2018 06:19:22 GMT</pubDate></item></channel></rss>