Go Down

Topic: [SOLVED] How to print the degree symbol ? (extended ASCII) (Read 10744 times) previous topic - next topic


ninja2


ninja2

Just upgraded to IDE 1.8.3

still see same issue, although appearing as a backward quesiton mark now - see attached

Whandall

IDE 1.8.1 / Win7-64 / Mega
Code: [Select]
float TbmpC = 24.1;

void setup() {
  Serial.begin(250000);
  Serial.print("Temperature: ");
  Serial.print(TbmpC, 1);
  Serial.print(char(176));
  Serial.println("C");
}
void loop() {}

Code: [Select]
Temperature: 24.1°C
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

ninja2

yep I used to see similar printed as per @Whandall

I'm using 1.8.3 on Win10-64 and Mega2560

still not solved :(

PS: @Whandall its curious you set 250000 as baud rate. I would have thought 115200 x 2 = 230400 more appropriate?

Coding Badly

#20
Jul 06, 2017, 10:17 am Last Edit: Jul 06, 2017, 10:18 am by Coding Badly

Serial Monitor now uses UTF-8...

Code: [Select]

float TbmpC = 24.1;

void setup() {
  Serial.begin(250000);
  Serial.print("Temperature: ");
  Serial.print(TbmpC, 1);
 
  Serial.write(0xC2);
  Serial.write(0xB0);
  //Serial.print(char(176));

  Serial.println("C");
}
void loop() {}


The correct byte sequence is easy to locate through Google...

https://www.google.com/search?q=utf8+degree+symbol


Whandall

That does not work on my 1.8.1 / Win7-64 / Mega

Btw 0xB0 == 176 (11 * 16)

Code: [Select]
float TbmpC = 24.1;

void setup() {
  Serial.begin(250000);
  Serial.print("Temperature: ");
  Serial.print(TbmpC, 1);
  Serial.write(176);
  Serial.println("C");
  Serial.print("Temperature: ");
  Serial.print(TbmpC, 1);
  Serial.write(0xC2);
  Serial.write(0xB0);
  Serial.println("C");
}
void loop() {}

Code: [Select]
Temperature: 24.1°C
Temperature: 24.1°C
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

ninja2

Serial Monitor now uses UTF-8...
thanks, that solves it.

Did that come in after IDE 1.8.1 ?

FWIW all these work correctly:

Code: [Select]
Serial.print("\xC2");
Serial.print("\xB0");


Code: [Select]
Serial.print("\xC2\xB0");

Code: [Select]
Serial.print(char(194));
Serial.print(char(176));

Whandall

I would still prefer
Code: [Select]
Serial.write(0xC2);
Serial.write(0xB0);
Serial.write(194);
Serial.write(176);
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

ninja2

I actually prefer the Streaming library by Arduinana for simplified outputting of Serial string commands. I've used it for years with no big issues:

Code: [Select]

#include <Streaming.h>

void loop {
.
.
Serial << "Temperature: " << TbmpC  << "\xC2\xB0" << "C\n"; // 0xC2B0 is degree symbol in UTF-8 charset
.
.

septillion

Small function to write extended ASCII

Code: [Select]
void writeAscii2Utf8(Print &out, byte in){
  if(in < 0x80){
    out.write(in);
  }
  else{
    out.write(0xC0 | (in >> 6));
    out.write(in & 0x3F | 0x80);
  }
}
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Coding Badly

#26
Jul 06, 2017, 07:23 pm Last Edit: Jul 06, 2017, 07:24 pm by Coding Badly
Did that come in after IDE 1.8.1 ?
Given @Whandall's experience the answer is clearly "yes".

It looks like charting was added between x.1 and x.3.  But, as far as I can tell, text handling was not changed.

I suspect a bug existed in x.1 that was silently fixed by x.3.  Given the code for Serial Monitor the bug was either in the Java runtime itself or in the way the Java text components were initialized.


JohnnyDoe

for anyone who may run into this:

Code: [Select]
Serial.print("\xC2\xB0");

is the ONLY snippet I could get to work on my system:

Linux Mint 18.1, Cinnamon 3.2.7
Arduino IDE 1.8.3
Mega2560 R3

Eheran

Im on 1.8.4. And they are all not working for me now. And I just want to get a nice little "°"...
It used to be "\260" but nope. Giving me mirrored "?" or even more weird symbols:
Code: [Select]
      Serial.println("\xC2\xB0 C");
      Serial.write(0xC2);
      Serial.println();
      Serial.write(0xB0);
      Serial.println();
      Serial.write(194);
      Serial.println();
      Serial.write(176);
      Serial.println("\xC2");
      Serial.println("\xB0");

ninja2

I moved to 1.8.4 recently and \xC2\xB0 is still working as before for me ...

Go Up