# SD card loads correctly, but won't load file

**URL:** <https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801>\
**Category:** Storage\
**Created:** [October 17, 2025, 9:15pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801 "2025-10-17T21:15:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rainwater\_83c](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rainwater_83c/32/1241355_2.png) [@rainwater\_83c](https://forum.arduino.cc/u/rainwater_83c)\
**Post date:** [October 17, 2025, 9:15pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/1 "2025-10-17T21:15:08Z")

</div>

I have used an example project, and the file loads fine, but whenever _I_ make the code, it stops working...

My code: (Not finished)

```arduino
#include <SPI.h>
#include <SD.h>
#include <ArduinoJson.h>

const int inPin = 4;
const int outPin = 7;

File myFile;
JsonDocument doc;

void setup() {
  //Setup input and output pins
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // Wait for serial port to connect
  }
  Serial.print("Initializing SD card...");
  if (!SD.begin(2)) {
    Serial.println("Initialization failed");
    while (1);
  }
  Serial.println("Done");

  myFile = SD.open("index.json", FILE_WRITE);
  if (myFile) {
    Serial.print("File opened successfully");
    if (!myFile.available()) { //Check if file is empty or new 
    //Write default morse to index.json
    char defaultMorse[] = "{\"A\":\".-\",\"B\":\"-...\",\"C\":\"-.-.\",\"D\":\"-..\",\"E\":\".\",\"F\":\"..-.\",\"G\":\"--.\",\"H\":\"....\",\"I\":\"..\",\"J\":\".---\",\"K\":\"-...\",\"L\":\".-..\",\"M\":\"--\",\"N\":\"-.\",\"O\":\"---\",\"P\":\".--.\",\"Q\":\"--.-\",\"R\":\".-.\",\"S\":\"...\",\"T\":\"-\",\"U\":\"..-\",\"V\":\"...-\",\"W\":\".--\",\"X\":\"-..-\",\"Y\":\"-.--\",\"Z\":\"--..\"}";
    myFile.println(defaultMorse);
    myFile.close();
    } else {
      Serial.print("File is not empty!");
    }
  } else { 
    myFile.close();
    Serial.print("File failed to load");
    Serial.println(myFile);
    Serial.println(SD.open("index.json", FILE_WRITE));
  }
}

void loop() {
  //int inRead = digitalRead(inPin);
  //int outWrite = inRead; //Temporary for later code
  //digitalWrite(outPin, outWrite);
  //Serial.print(outWrite);
}

```

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [October 17, 2025, 9:18pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/2 "2025-10-17T21:18:06Z")

</div>

> [@rainwater\_83c](#):
>
> I have used an example project, and the file loads fine, but whenever _I_ make the code, it stops working...

What does that mean, exactly? Please be detailed and specific.

And by the way, as far as I know, the SD library doesn't support long file names. It's 8.3 only.

---

<div class="post-metadata">

**Author:** ![rainwater\_83c](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rainwater_83c/32/1241355_2.png) [@rainwater\_83c](https://forum.arduino.cc/u/rainwater_83c)\
**Post date:** [October 17, 2025, 9:20pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/3 "2025-10-17T21:20:53Z")

</div>

> [@van\_der\_decken](#):
>
> What does that mean, exactly? Please be detailed and specific.

I used the example project "Read Write" and it created and loaded the file successfully, but when I used the code that I made, it didn't work.

---

<div class="post-metadata">

**Author:** ![van\_der\_decken](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/van_der_decken/32/1006976_2.png) [@van\_der\_decken](https://forum.arduino.cc/u/van_der_decken)\
**Post date:** [October 17, 2025, 9:22pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/4 "2025-10-17T21:22:47Z")

</div>

If I said to you "it doesn't work" about something, would you be able to tell me anything useful without me providing details about exactly what happened, what didn't happen, and what you expected to happen?

No. And neither can I.

Good luck with your project.

---

<div class="post-metadata">

**Author:** ![rainwater\_83c](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rainwater_83c/32/1241355_2.png) [@rainwater\_83c](https://forum.arduino.cc/u/rainwater_83c)\
**Post date:** [October 17, 2025, 9:24pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/5 "2025-10-17T21:24:28Z")

</div>

> [@van\_der\_decken](#):
>
> If I said to you "it doesn't work" about something, would you be able to tell me anything useful without me providing details about exactly what happened, what didn't happen, and what you expected to happen?

That's the thing. I don't have any other details other than "File failed to load".

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [October 17, 2025, 10:09pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/6 "2025-10-17T22:09:56Z")

</div>

SD library supports 8.3 filenames. The “.json” is the problem.

```arduino
index.json

```

You can change to SdFat library. It supports long filenames.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [April 15, 2026, 10:10pm UTC](https://forum.arduino.cc/t/sd-card-loads-correctly-but-wont-load-file/1409801/7 "2026-04-15T22:10:31Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
