SegFault
SegFault

Reputation: 2190

Arduino doesn't recognize escape character

i'm trying to save some values on a file stored in the SD card, the code is this one:

void loop()
{
  // make a string for assembling the data to log:
  String dataString = "";

    int analogPin = 0;
    for (int j=0; j<20; j++){
      i=i+1;
      int sensor = analogRead(analogPin);
      dataString += String(sensor);
      dataString += " ";
      dataString += millis();
      dataString += " ";
      dataString += i;
      dataString += "\n";
    }

  // open the file.
  File dataFile = SD.open("rumore.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening rumore.txt");
  } 
}

the problem is that it seems not to recognize this line: dataString += "\n"; so that while on the Serial monitor i get the right output,on the file rumore.txt values are not written in the same way, but they're all in the same line..any idea?

Upvotes: 2

Views: 2683

Answers (1)

DotNetRussell
DotNetRussell

Reputation: 9857

I think with the Arduino you need to use "\r\n" to exicute a carriage return\new line command

I believe this is how I have done it in the past and also here is a supporting article

http://forum.arduino.cc/index.php/topic,44334.0.html

Upvotes: 4

Related Questions