Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display degree symbol in Arduino OLED

Tags:

c

arduino

To display degree symbol to plot on OLED you can use

display.print((char)247); // degree symbol

example:

void loop(void){

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.clearDisplay();

display.print("Temperature: ");
display.print("23");
display.print((char)247); // degree symbol 
display.println("C");
display.display();
delay(1000);
}
like image 952
Hayk Martirosyan Avatar asked Sep 04 '25 04:09

Hayk Martirosyan


2 Answers

The documentation says:

Each filename starts with the face name (“FreeMono”, “FreeSerif”, etc.) followed by the style (“Bold”, “Oblique”, none, etc.), font size in points (currently 9, 12, 18 and 24 point sizes are provided) and “7b” to indicate that these contain 7-bit characters (ASCII codes “ ” through “~”); 8-bit fonts (supporting symbols and/or international characters) are not yet provided but may come later.

In other words, the degree symbol (U+00B0, °) is not supported by the fonts by default.

Of course, nothing stops you from redefining one of them as the degree symbol in the .h file that corresponds to the font you wish to use -- in particular, to make a copy of the existing file, renaming the copy, and replace one of the ASCII characters you do not need with the degree symbol. I would suggest replacing ` (ASCII code 96), because it is very similar to the more commonly used apostrophe ' (ASCII code 39).

An easier option is to just draw a small circle (say, radius 1, 2, or 3 pixels) at the correct position using display.drawCircle(xcenter, ycenter, radius, WHITE);. After all, the degree glyph is just a small circle -- consider the looks of e.g. 25°C or 77°F.

For more complex glyphs, if you don't want to create your own font .h files, you can use the display.drawBitmap() interface. Examine and experiment with the Adafruit example for details.

You can use the image2cpp web page at GitHub to generate the Arduino data array. It also supports font format, so you can use that to generate the data for your degree symbol glyph, just by "drawing" it on that page.

like image 87
Nominal Animal Avatar answered Sep 05 '25 21:09

Nominal Animal


I think you missed by 1. Mine works on char(248).

like image 44
Paul Avatar answered Sep 05 '25 21:09

Paul