How does one insert CR?LF into string to be written to a file?

Please pardon my ignorance.
My sketch plan is to read 100 data points (x,y) into a string each pair of points followed by a CR/LF so the file can be imported to a spreadsheet. then write the string to a file. Had no problem getting the data comma delimited, but can't seem the get the CR/LF appended to the string between each pair of points. so the spread sheet imports the data into 2 columns

Here is what I've tried:

dataString += String(x);
dataString += String(",");
dataString += String(y,'/rl');
// dataString += String('/r');

The CR and the LF doesn't seem to get added into the string.
Can anyone tell me what I did wrong?

Can anyone tell me what I did wrong?

Some would say that using Strings is wrong and that you should use C style strings in the first place.

How are you outputting these Strings ?
Have you tried println() as opposed to print() if that is relevant

Seeing your whole program would be a distinct advantage. (HINT)

'/r' is not a string, it is two characters. It also is not an escaped code for a carriage return character - "\r" is what you would need for that.
But, I suspect that UKHeliBob is right that println is probably what you need.
He is also right that you should not be using String. It will eventually cause mysterious crashes. Use a C-style null-terminated string. You can then use sprintf to format the output string.

Pete

Try running the sample program below as is:

void setup() {
  Serial.begin(115200);                      // You need to adjust this on the monitor, or set to 9600
  char final[30] = {"This is a test"};

//  strcat(final, "\n");                     // Remove comment chars later...
  Serial.print(final);
  Serial.print("Done");
}

void loop() {
}

Note that the output appears on the same line. Then remove the comment for strcat() and note that the output is on different lines. Then ask yourself why.

We are working in the dark here because we don't know the exact requirement.

People often try to concatenate a whole String/string together before sending it to another device over Serial or to a file when the receiving device would be quite happy to receive the String/string in smaller segments until something happens to close the file or the connection.

This would seem to me to be such a case as the output is being written to a file which will not be closed until it is done explicitly. If that is the case then there is no need to concatenate the parts of the String/string in the first place. This is particularly applicable when output is derived inside a for loop or nested loops as the output can be sent line by line with commas separating the data items and CR/LF pairs separating the lines.

I look forward to seeing the program.

The first problem I encountered was that the ADXL345 is a SPI bus hog, If I read the data sheet on it correctly the only way to get it off the bus is to cut power to it. This means I have to initialize the XL345 get all of my readings then turn it off to clear the SPI bus for writing to the SD card file.
This sketch is not complete yet, I've been working on small sections to get a little less to chew on at one time.
Currently working on getting the data formatted in a file to transfer to a spread sheet.
I haven't done any programming in about 20 years but seem to be able to get most things working on my own for the most part. BTW the Arduino can not be connected to a computer as it will be spinning at around 1500 rpm. If it could I could have copied the data from the terminal and pasted it into a text file.
There is a lot of junk still in the sketch to be cleaned out later. Here is a snippet of the code.

void loop()
{ // Begin main loop
if (testmode == 1){ // 5
Serial.print(filename);
Serial.println(G_range, DEC);
}

if(G_range == 0){ // begin range check
// ADXL345 initialized in 2G mode in setup G range is stepped upward here through all of it's ranges.
// Program terminates after reading 16G range logging data and turns on blue LED.
G_range++; //increment range for next sample set
samplecount = 0; //reset data sample count to 0
filename = ("G_range2.txt");
goto sample;
}
// switch (G_range){ // begin range select
if (G_range == 1) {
// case 1:
//Put the ADXL345 into +/- 4 G range by writing the value 0x01 to the DATA_FORMAT register.
writeRegister(DATA_FORMAT, 0x01);

G_range++; //increment range for next sample set
samplecount = 0; //reset data sample count to 0
filename = ("G_range4.txt");
Serial.print(filename);
Serial.println(G_range, DEC);
goto sample;
}
if (G_range == 2){
// case 2:
//Put the ADXL345 into +/- 8 G range by writing the value 0x01 to the DATA_FORMAT register.
writeRegister(DATA_FORMAT, 0x10);

G_range++; //increment range for next sample set
samplecount = 0; //reset data sample count to 0
filename = ("G_range8.txt");
Serial.print(filename);
Serial.println(G_range, DEC);
goto sample;
}
if (G_range == 3) {
// case 3:
//Put the ADXL345 into +/- 16 G range by writing the value 0x01 to the DATA_FORMAT register.
writeRegister(DATA_FORMAT, 0x11);

G_range++; //increment range for next sample set
samplecount = 0; //reset data sample count to 0
filename = ("Grange16.txt");
Serial.print(filename);
Serial.println(G_range, DEC);
goto sample;
}
if (G_range == 4){
// case 4:
Serial.print(filename);
Serial.println(G_range, DEC);
digitalWrite(redledPin,HIGH);
digitalWrite(grnledPin,HIGH);
digitalWrite(bluledPin,LOW);
Serial.println("Program Terminated at line 154");
while (pend < 1){ // wait here till reset.
wait= millis();
}
G_range++; //increment range for next sample set
// return; // program terminates normaly with blue LED on.
// default:

// } // End range elect
//Reading 6 bytes of data starting at register DATAX0 will retrieve the x,y and z acceleration values from the ADXL345.
// G_range++; //increment range for next sample set
sample:
dataString =(""); // Clear for next sample set
while (samplecount <= 100){ // Begin sample read loop

//The results of the read operation will get stored to the values[] buffer.
readRegister(DATAX0, 6, values);

//The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combined for each axis.
//The X value is stored in values[0] and values[1].
x = ((int)values[1]<<8)|(int)values[0];
//The Y value is stored in values[2] and values[3].
y = ((int)values[3]<<8)|(int)values[2];
//The Z value is stored in values[4] and values[5].
z = ((int)values[5]<<8)|(int)values[4];

// clear string for next samples of data to log:
dataString += String(x);
dataString += String(",");
dataString += String(y,'/rl');
// dataString += String('/r');

// If test mode = true Print the results to the terminal.
if (testmode == 1){ // 5
Serial.print(samplecount, DEC);
Serial.print(" ");
Serial.print(x, DEC);
Serial.print(',');
Serial.println(y, DEC);

} // 5
samplecount = samplecount +1;

delay(50); // wait 50ms before reading next sample
} // end of sample read

// open the file.

File dataFile = SD.open(filename, FILE_WRITE);

// if the file is available, write to it:
if (dataFile) { // write to file routine
dataFile.println(dataString); //dataFile.println(dataString);
dataFile.close();

}
// if testmode is true print to the serial port too:
if (testmode == 1){
Serial.println(dataString);
}
// if the file isn't open, turn on red LED on error:
else { // error trap
// turn on red led on fail
digitalWrite(redledPin, LOW);
digitalWrite(grnledPin, HIGH);
digitalWrite(bluledPin,HIGH);
Serial.println("Program Terminated");
while (pend < 1){ // wait here till reset.
wait= millis();
}
return; // terminate program
} // End error trap
}

// } // End of sample read/write loop
/*
while (pend < 1){ // wait here till reset.
wait= millis();
*/
// }

}// End of main loop

You don't read the datasheet correctly, check out the *CS pin.

@bobc896
Edit your post and put your code in code tags. Then we won't have to guess/figure out what statements like this mean:
x = ((int)values[1]<<8)|(int)values[0];

Pete

KeithRB:
You don't read the datasheet correctly, check out the *CS pin.

That's not the issue, there are a whole raft of sensor chips that claim to be both SPI/I2C,
but they aren't true SPI and can only be used on a shared bus via the I2C interface since the
SPI CS pin is also the I2C/SPI mode line - so when its high the chip is listening for I2C
commands.

Its a pain since SPI is a lot faster than I2C, but basically its not worth interfacing these
sensor chips except via I2C.

PS There is a suggested hardware workaround in the "Preventing Bus Traffic Errors" section of the datasheet.