SOLVED: How to write a degree symbol to SD-card?

I need to write a header line with physical unities to a CSV-file.

I tried:

dataString = String ("[s]") + "," + "[W/m2]" + ", " + "[°C]" + ", " + "[°C]";
  myFile.println(dataString);

In the csv-files will be written:
,[W/m2], [°C], [°C]
That is not fully correct.
How to solve my problem?

How to solve my problem?

Quit pissing away resources on the String class.
Proof-read your post in the Preview window BEFORE posting.

I agree with Paul: Forget about the String class; it uses too much memory relative to the C string (note lower case ‘s’) data type which is built from character arrays. Load and run the following program:

void setup() {
 
  int i;

  Serial.begin(9600);
  for (i = 128; i < 256; i++) {
    Serial.print(i);
    Serial.print("   ");
    Serial.println((char) i);
  }
}

void loop() {
}

which displays the extended character set for the Arduino. It looks like character 186 is the degree mark. Also take a look at itoa() function.

Econjack Thanks for the tip. I did not know that printing characters to SD differs from printing to LCD.

#PaulS Of course I made a preview of my topic, but this editor can not handle special characters.

econjack:
I agree with Paul: Forget about the String class; it uses too much memory relative to the C string (note lower case ‘s’) data type which is built from character arrays. Load and run the following program:

void setup() {

int i;

Serial.begin(9600);
 for (i = 128; i < 256; i++) {
   Serial.print(i);
   Serial.print("   ");
   Serial.println((char) i);
 }
}

void loop() {
}




which displays the extended character set for the Arduino. It looks like character 186 is the degree mark. Also take a look at *itoa()* function.

I’ve tried this program, and many characters in the output show as an empty rectangle. Something must be wrong with the font, I presume. What can be done about it?

No. Many characters are unprintable. How do you print an end-of-file character? What representation should you use to show that?

The A-hat problem is due to the way that the Arduino IDE saves the files as unicode. If you type the degree character and upload to the Arduino before saving, you will get a different result to when you open that saved file and upload it.

const char DEGREE_SYMBOL = 167; //167 is the ASCII code for the degree symbol (may not work on unicode systems.)
...
  Serial.write(DEGREE_SYMBOL);

Saving the degree symbol to SD-card can be done as follows:

myFile.print ((char)176);

It looks like character 186 is the degree mark.

const char DEGREE_SYMBOL = 167;

myFile.print ((char)176);

That thing gets around. Any more votes? Any explanations?

No. But a question - Why would you want to do that?

Nick_Pyner:
But a question - Why would you want to do that?

Are you asking why I want an explanation for the discrepancy?

It seems that instructions for presentation to the serial monitor, LCD and saving to SD-card don’t be the same.

No. I am asking why bother sending degree signs to SD. The variety of answers may all be correct, they may all be wrong. They may also reflect the relevance.

ArduinoStarter1:
It seems that instructions for presentation to the serial monitor, LCD and saving to SD-card don't be the same.

The style of sending the instructions is essentially the same. the detail is unsurprisingly different for a special character. I believe a degree sign is built into the limited character set of a typical character LCD library, while in a graphic one you probably always have to make your own.

While I think sending deg signs to CSV is pretty pointless. I think

lcd.print((char)223);

worked for LCD