Issue with micro SD breakout

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
wwalkin
 
Posts: 1
Joined: Mon Apr 23, 2012 11:17 pm

Issue with micro SD breakout

Post by wwalkin »

I have a micro SD breakout and I am able to write to the card, that is create files and write to them. The issue I have is that the data is being written more than once. I am using the code provided on the micro SD tutorial. What could the problem be? The serial monitor shows that the code ran only once but still data is being written two or three time rather than once.

Code: Select all

#include <SD.h>
 
File myFile;
 
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
   pinMode(53, OUTPUT);
 
  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
	// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}
 
void loop()
{
	// nothing happens after setup
}

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Issue with micro SD breakout

Post by Franklin97355 »

Do you erase the file between tests?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Issue with micro SD breakout

Post by adafruit_support_bill »

The code starts running automatically after each reset. It will start running as soon as you upload the sketch. And then when you open the serial monitor, it will assert DTR which will reset the board and the sketch will start running again.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”