degree symbol on Oled screen using u8g

Can anyone, please, tell me how to put a degree symbol on the oled screen using the u8g lib?

I have scoured the internet and found all kinds of "solutions" but non just worked for me.

With U8g2:

  1. Use a font with _tf at the end
  2. Crosscheck that the font includes the degree symbol in the corresponding font group page
  3. use u8g2.drawUTF8
  4. open a charset tool
  5. select & copy the degree symbol
  6. past the symbol into the string argument of the u8g2.drawUTF8 command in the Arduino IDE

A suitable font could be u8g2_font_helvB12_tf

You can see the degree symbol at 0x0b0, which is also the official unicode position.

Oliver

1 Like

Thanks for replying, Oli!
I did come that far, but could not combine this piece of information with the code. Probably simple, when you know how. So, please, can you show me a piece of code incorporating the 176/0x0b0 resulting in printing the ° on the Oled screen?
Thanks in advance.

I believe u8g.print (char(176)); should work if the chosen is tf.

ASCII Version:

void setup(void) {
  u8g2.begin();
}
void loop(void) {
  u8g2.setFont(u8g2_font_helvB12_tf);  
  u8g2.setFontDirection(0);
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 15);
    u8g2.print("-1 \xb0C");
  } while ( u8g2.nextPage() );
  delay(1000);
}

UTF8 Version:

void setup(void) {
  u8g2.begin();
  u8g2.enableUTF8Print();		// enable UTF8 support for the Arduino print() function
}
void loop(void) {
  u8g2.setFont(u8g2_font_helvB12_tf);  
  u8g2.setFontDirection(0);
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 15);
    u8g2.print("-1 °C");
  } while ( u8g2.nextPage() );
  delay(1000);
}

The advantage of the UTF8 version is, that you can directly type the degree symbol from your keyboard.

Oliver

Thanks both of you.
Later today I will do some coding and try to implement your suggestions.

Thanks again,

Thanks guys, I have it running! Now I can concentrate on the real program.

It is possible to display degree symbol using the u8g library too.
I used the font "u8g_font_7x14B" to do it.

u8g.setFont(u8g_font_7x14B);
u8g.setPrintPos(20, 20);
u8g.print(tValue);
u8g.write(0xB0);

where tValue is a temperature value like
float tValue = 32.19;