2

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?

4

1 回答 1

4

我认为您需要使用 Arduino"\r\n"来执行回车\换行命令

我相信这就是我过去的做法,这里也是一篇支持文章

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

于 2013-08-21T16:28:44.493 回答