Go Down

Topic: Arduino SD Card Writer Doesn't Write to SD Card (Read 121 times) previous topic - next topic

nathan_ngu

Nov 09, 2018, 05:41 am Last Edit: Nov 09, 2018, 06:21 am by nathan_ngu
I've recently purchased a Virtuabotix SD Card Reader/Writer and for some reason it doesn't write to files.

It can't be the SD card because the sketch CardInfo works properly on it (even though it is 8 gb).

Everything from the Serial Monitor standpoint functions correctly. It prints out "Initializing SD Card...initialization done" then "test.txt exists" then "writing to test.txt...done"



Even though I created the text file on Notepad manually, I know that it is able to recognize the file because it printed out "writing to test.txt"


But when I plug the SD Card into the computer, I don't see anything on the file test.txt   .




#include <SD.h>
#include <SPI.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!");
    while (1);
  }
  Serial.println("initialization done.");
 

  if (SD.exists("test.txt")) {
    Serial.println("test.txt exists.");

  } else {

    Serial.println("test.txt doesn't exist.");
  }

  myFile = SD.open("test.txt", FILE_WRITE);
 
  if (myFile) {

    Serial.print("Writing to test.txt...");

    myFile.println("testing 1, 2, 3.");

    Serial.println("done.");
    myFile.close();

  } else {

    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}


void loop() {
  // put your main code here, to run repeatedly:
}




What could possibly be wrong with my file writing functions? I even used multiple types of print functions in hopes one would work.

Hopefully somebody more skilled than I can work this out.


Thanks,

Nathan

Edit: I've figured out that the problem centers around the line myFile.println("testing 1, 2, 3.");
How do you properly output data onto the sd card w/o causing errors

Juraj

SD cards have a small switch for read-only mode. check it
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

nathan_ngu

Nevermind, I fixed it.

The SD Card must be formatted to FAT 16 (FAT) for it to function properly.

Thanks anyway

Juraj

Nevermind, I fixed it.

The SD Card must be formatted to FAT 16 (FAT) for it to function properly.

Thanks anyway
FAT32 should work too
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Go Up