Go Down

Topic: SD Card file not being Created (Read 491 times) previous topic - next topic

FarrukhQamar

Trying to create directory and file on the arduino Card Info can be retrieved it can list down the existing files it says the file has been created but if i try to check the sd card on computer, no file is found. Though it lists down the recently created file in the same session. But restarting the board willnt display the recently created file.

here is the code

Code: [Select]
/*
  SD card basic file example

 This example shows how to create and destroy an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    if(SD.mkdir("/Arduino")){
      Serial.println("Directory with name Arduino has been created");
     
      } else {
       
      Serial.println("couldnt create the directoy...");
       
        }
    Serial.println("example.txt doesn't exist.");
  }

//   open a new file and immediately close it:
  Serial.println("Creating example.txt...");
  myFile = SD.open("example.txt", FILE_WRITE);
  myFile.close();

  // Check to see if the file exists:
  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }

  // delete the file:
//  Serial.println("Removing example.txt...");
 // SD.remove("example.txt");

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }
}

void loop() {
  // nothing happens after setup finishes.
}



Southpark

Have you tried any sketch examples to just create a text file on the sd card and to write some text to the file yet? (without creating directories).

Could also try formatting the SDcard ... eg format to FAT 32 with default allocation unit size.

mudassir9999

#2
Jan 05, 2017, 09:50 am Last Edit: Jan 05, 2017, 09:53 am by mudassir9999
Troubleshoot

-Try with the Cardinfo example, This will let know you if the card is present and also being detected.

-Format the card and then try again.

-Change the name of the file from "example.txt" to any other.

Go Up