I have a project which uses a 128x64 oled display. I have to use the U8GLIB as the available displays change from SSD1306 to SSH1106 depending on when you buy it which that library covers both displays. I don't want the program for the display to eat up the memory of the arduino so I use u8glib instead of u8g2! for this project I need to display numbers 0 to 9, decimal point, omega (ohm symbol) and metric prefixes such as μ,m,k,M, etc... I first tried to create a bitmap font (.bdf) and convert it to a C file because that was what was hinted at on a few posts. There were no tutorials and after messing about with the different formats and trying to add the font to the library I just gave up because I couldn't figure it out. Instead I decided to use this website which generates bitmaps from TTF files: https://littlevgl.com/ttf-font-to-c-array

Now I can use those bitmaps and have my few characters which use very little memory (about 20% as opposed to more than 70% using a complete symbols font in u8g2!) but this makes things really awkward as I have to translate every number I get into separate digits and then into a bitmap! also I can only use font sizes which have a height in multiples of 8 because for some weird reason this library expects width in number of bytes and height in number of pixels!

cnt: Number of bytes of the bitmap in horizontal direction. The width of the bitmap is cnt*8.

so I can do fonts of size 48 for example, but not 50 or 52 which would be more suitable for my application! I'm not sure if anyone else has had this issue but there must be a way to display the characters you want without destroying your entire memory space like u8g2 does! Just getting to this point took me 2 days (on the left there is a 0.96" SSD1306 and on the right there is a 1.3" SSH1106):

enter image description here Please help if you have any idea on how to deal with this library as it's driving me insane at the moment!

1 Answer 1


While this may not exactly answer your question, there may be some information about u8g2lib that you have not seen. The library source code is linked here: u8g2lib

Within that repository is the FAQ documentation which includes such gems as:

Q: U8g2 requires a lot of memory. How to reduce this? - Visit https://github.com/olikraus/u8g2/wiki/u8g2optimization - Disable U8g2 features if possible (see u8g2.h) - Limit the font size. If possible avoid "f" fonts, instead use "r" or "n" fonts - If the I2C interface is not required, then uncomment #define U8X8_HAVE_HW_I2C in U8x8lib.h (Background: Due to a problem in Wire.h, the I2C Arduino lib is always included)


Q: How can I generate my own font. A: The font must be available in bdf file format. Then use bdfconv to generate the font data. The font data can be pasted into an existing file of your project. There is also a nice Windows Bitmap Font Editor "Fony" (http://hukka.ncn.fi/?fony) which can export .bdf files. A copy of Fony 1.4.7 is available here: https://github.com/olikraus/u8g2/tree/master/tools/font/fony

The tools/font directory includes several utilities, including what looks like one that converts OTF fonts to BDF format

Once you get a BDF format font, you use bdfconv to create the C file that holds the font array. One of the arguments for bdfconf is the -m 'map' option. You can place in there a list of Unicode ranges that limit which characters get included. So, you can create a font that has ONLY the characters you need.

For example -m '45-46,48-57,77,107,109,181,937' gets you minus, decimal, 0-9, 'M', 'k', 'm', mu, omega. Unicode character map at https://unicode-table.com/en/

The benefit to creating a font is that the u8g2lib library itself does all the mapping to bitmaps and calculating the character widths, etc. so you don't have to.

  • this is really helpful,specially with memory reduction part, but I'm still not sure how to use the bdfconv tool, it seems to be used with linux command line, not windows. Also even when I get the C file, I'm not sure how to use it. should I add something to the u8g2_fonts.c? should I just copy and paste the generated file into my .ino sketch? please link to a full tutorial if you can, or at least create a basic walk through, thanks!
    – OM222O
    Feb 7, 2019 at 16:53
  • I'm not sure there is a full tutorial. Look in github.com/olikraus/u8g2/tree/master/tools/font/bdfconv for a .exe windows version of bdfconv!. The resulting .c font file: Just #include "fontfile.c" in your program, and put the file in the same folder as your sketch. That will bring in the font without having to edit the existing fonts file. Feb 7, 2019 at 17:08
  • when I run the .exe file nothing happens. Should I download and modify the " Makefile" as well? The instructions are really vague and lacking tbh.
    – OM222O
    Feb 7, 2019 at 17:20
  • I downloaded github.com/olikraus/u8g2/blob/master/tools/font/bdfconv/… and it runs fine. Feb 7, 2019 at 17:32
  • does it not require any other files and runs on it's own? for me it opens and closes immediately afterwards! I think I have to stick with creating manual bitmaps :(
    – OM222O
    Feb 7, 2019 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.