[SOLVED] Serial monitor resets the Arduino ?

not sure if this goes in Programming, but i doubt it's a bug with the Arduino board so i didn't want to put it there.

it's more likely bad coding, but i did follow the code from here;

here's the code as i actually used it;

/*
 This example shows how to log data 
 to an SD card using the SD library.
    
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10
                           created  24 Nov 2010
                           modified 9 Apr 2012       by Tom Igoe
 
 This example code is in the public domain.
 */

#include <SD.h>
const int chipSelect = 10;

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  }

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

  if (!SD.begin(chipSelect)) {
    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 a, b, c.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
        Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

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

the problem is the text is saved twice to the file.
i then discovered it's saved again if i close the Serial monitor and open it again.
is this a normal condition, and something that has to be accepted while debugging code ?

Yes

If you are using an Uno there is a trace that you can cut to disable auto reset. Other boards< I don't know.

groundfungus:
If you are using an Uno there is a trace that you can cut to disable auto reset. Other boards< I don't know.

okay, thanks for the confirmation Jimbo.
will have to start learning about trace & auto-reset.

I meant a trace (conductor) on the Uno PC board, in case I was misunderstood.

You can defeat the arduino auto reset by keeping the reset pin high. Often done with a resistor (100 to 220 ohm range) between the arduino 5v pin and reset pin, or a high value capacitor between the reset pin and ground.

thanks again everyone, i think we can consider this thread closed.
here's the link to continue to for anyone else stumbling on this same issue.
http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection

zoomkat:
You can defeat the arduino auto reset by keeping the reset pin high. Often done with a resistor (100 to 220 ohm range) between the arduino 5v pin and reset pin, or a high value capacitor between the reset pin and ground.

Hadn't thought of that... or rather I had, but didn't realise it prevented any reset other than pushing the reset button. Good to know....