Skip to content

u8g2optimization

kraus edited this page Oct 28, 2018 · 13 revisions

RAM Optimization

On AVR systems, use the Arduino F() macro. U8g2 supports the Arduino print function, which accepts the F() macro.

A simple example for the F() macro is available as an example:

https://github.com/olikraus/u8g2/blob/master/sys/arduino/u8g2_page_buffer/PrintHelloWorld/PrintHelloWorld.ino

A more complex example is here:

https://github.com/olikraus/u8g2/blob/master/sys/arduino/u8g2_page_buffer/PrintProgmem/PrintProgmem.ino

Flash Memory Optimization

Font Optimization

Usually U8g2 fonts are available in different sizes (number of glyphs included in the font). The last letter of the font name indicates the character set (and the size) of the fonts.

Font Name Character Set
u8g2_xxx_xe Extended: Glyphs with unicode 32 to 701 are included in the font (v2.16.x will also include big ß)
u8g2_xxx_xf Full: Glyphs with unicode 32 to 255 are included in the font
u8g2_xxx_xr Restricted: Only characters from 32 to 127 are included
u8g2_xxx_xu Uppercase: Numbers and uppercase letters
u8g2_xxx_xn Numbers and some extra glyphs for date and time printing are included
u8g2_xxx_x_something Special selection of glyphs. See the font picture for details.

For example if only a number needs to be displayed with a huge font, then the font should contain only numbers. In such a case, it is better to select a n font, which will almost only contain numbers.

Each font picture also includes the number of bytes, occupied by the font in flash memory (upper right part of the picture):

fntpic/u8g2_font_4x6_tr.png

These pictures are available on the font group pages.

See also: setFont

Clone this wiki locally