Go Down

Topic: U8glib: Graphics Lib for LCDs and OLEDs (Read 243114 times) previous topic - next topic


Guten Tag, ich bin am experimentieren mit der UG8lib und einem Oled-display SSD1306_128X64 mit I2C-Bus, angeschlossen an einen Atiny 85 im Dil 8 Gehäuse, clock und Data sind an Pin 5 und 7 angeschlossen. Leider weiss ich nicht 100 %ig welche Eintragung in der u8glib freischalten muss. Ich verwende die Lib 1.18 sowie die Enwickungsumgebung 1.66 für den Arduino. Das einbinden des Atiny Prozessors war kein Problem, ich habe auch schon Erfolge mit der Ausgabe auf dem display allerdings mit einer andwer Librariy. leider ist die nicht so gut wie die u8glib vom Olli Kraus (Danke Olli) Wer kann mir weiter helfen, ich weiss das der Speicherplat im Atny 85 begrent ist, aber ich benötige relativ wenig an Programmplatz.Wäre schön wenn einer eine Lösung oder eine Idee hätte
Gruß Christian DD7LP


Hi Oliver,

Thanks for such a great library.

I have written a simple program (home heating control) using various snippets from examples on line and your u8glib and it works a treat. see attached pictures.

I'm using a Nano and a generic OLED screen with DHT22 sensor and a generic quadrature encoder. I can give more details about the hardware but this is not the issue, its my understanding of the software. Please forgive me if I don't use the correct terminology, I'm just getting my head around this programming business :)

I was looking through your examples and in particular the graphics test example. Now this is worrying me because I think I might have my code set up incorrectly.

I noticed that you have each display set up as a void()

Code: [Select]
void u8g_box_frame(uint8_t a) {
  u8g.drawStr( 0, 0, "drawBox");
  u8g.drawStr( 0, 30, "drawFrame");

and you use the void draw(void) to contain your switch case statement. I understand the switch, case statement but to be honest I don't really understand how your implementation of the switch, case works and how it works in the void loop etc. I need to be sat down and shown  :smiley-confuse:

Code: [Select]
void draw(void) {
  switch(draw_state >> 3) {
    case 0: u8g_box_frame(draw_state&7); break;
    case 1: u8g_disc_circle(draw_state&7); break;
    case 2: u8g_r_frame(draw_state&7); break;
    case 3: u8g_string(draw_state&7); break;
    case 4: u8g_line(draw_state&7); break;
    case 5: u8g_triangle(draw_state&7); break;
    case 6: u8g_ascii_1(); break;
    case 7: u8g_ascii_2(); break;
    case 8: u8g_extra_page(draw_state&7); break;

I have placed my switch, case statement in the void loop and it seems to work ok. Is this correct?

Code: [Select]
//This is the display screens for the OLED screen, more can be added in the future - keeping it basic at the moment

  switch (encoderPos) {

    case 0: // Room Temperature - displays the current room temperature level
      do {
        u8g.drawStr( 20, 11, "Temperature");
        u8g.drawStr( 40, 63, "(Room)");
        u8g.drawStr( 7, 21, dtostrf(t, 4, 1, str));
        u8g.drawStr( 39, 21, "\260C");

    while( u8g.nextPage() );

I use an encoder to determine which page is selected using the switch, case feature.

I have tried to use the graphics test example to try and replicate my current code and I cant seem to get it to work :( One of the issues is to display the current temperature that the DHT is reading onto the OLED using the graphics test example.
I generally get 't was not defined' when compiling, so I declare 't' globally and the code compiles correctly, but then when the screen is displayed I still don't get the temperature reading.

All I'm looking for is an explanation of how your switch case is implemented and is it the standard way it should be and should I look at changing my code to a more standard format?
I enjoy the challenge of trying to figure out problems but this is a little beyond me at the moment.

I have attached my code... I'm a little embarrassed as its only in rough at the moment and needs tidying up.

Any pointers would be a great help





I had a look at your code, but i did not find any issues regarding u8glib. The only optimization i suggest is to place u8g.firstPage in the case itself, directly before the do statement.

What exactly does not work? What is displayed at the moment?



Hello Oliver :)

I'm actually using an adafruit oled display, 128x64 pixels, with SSD1306, hardware SPI and the adafruit libraries.
I have some performance issues, and after testing all the parts of my sketch it appears the display is taking barely 70% of the cycle time.

I expect your library to be faster than the adafruit, do you think it will be ?

Below is my screen, I don't have any animated feature. Its only display some variables inside boxes.
But as you can see it's rotated to use it in portrait mode, and I see the setRot will decrease performance.

Do you have any advice for me to keep this display and having the best performance ?
Maybe using drawstr90 will be faster than rotating the entire screen ?

Thank you for your help :)


U8glib probably will be slower, however in your application, I assume it should be fast enough. Maybe you could share your u8glib code (if any).
Rotating the text only is probably faster than rotating the entire screen.



Hi All

I have finally create another release. It is available via Library Manager of your Arduino IDE. 
From the ChangeLog:
  * Fixed contrast (brightness) setting for SH1106 and SSD1306 devices
  * Fixed compiler warnings
Also some contributed code should be includes (as far as I have accepted pull requests).



May 03, 2016, 01:10 pm Last Edit: May 03, 2016, 01:34 pm by matthewpoletin
I am creating my little project using this library (github.com/matthewpoletin/podzol) and ran into a little problem. After creating some simple openGL programs, i thought that the way to deal with this lib is similar: specify what you want to draw anywhere in your program and then call update function to draw it.
Unfortunately, i've spent some time looking for similar solutions, but didn't find any yet. The closest one is this code (https://github.com/michaelmargolis/asip/blob/master/asip/utility/asipLCD.cpp), author creates buffer of strings himself and then draw them between "first-" and "nextpage" functions.
If there is any common way to deal with it, i will be glad to take it as an advice.
Edit: I want to add that i fully understand that all works in picture loop. We create an image inside MCU and then draw it on GLCD. But in doing so i got a several lines of text instead of one.


Hello, everyone!
After some time of research and thinking I came to a simple solution to my problem. In my program I store all the information about graphics primtives all together. Then in the begining of the main while loop I draw them all. I've tested code on my ks0108 GLCD and got quiet a good speed with about 10 primitives, which is enough for me.
If anyone is intrested, for more details you can checkout my implementation on github.
I would like to hear any suggetions on such a solution from you.


Thank's for the library.
I have got it working, but would also like to make a custom font and icons.
I have made a .bdf of my font, and have downloaded the bdf2u8g_101.exe, but I don't understand how I can use the .exe to convert the .bdf file.
I have read this page https://github.com/olikraus/u8glib/wiki/bdf2u8g, but I still don't get it.
Can someone please enlighten me.

Cheers, Hal


Hal, are you able to generate the .c file?



Jul 18, 2016, 07:58 pm Last Edit: Jul 18, 2016, 10:04 pm by smithy
Hello Olli,

thanks for that awesome library.
I´ve been following your answers but i couldn´t find the right information.
I need to reduce code size of the fonts i´m using (right now 3 different are used, 6x10, courb12r/14r and symbol). Since i need an arrow up/down which is not in courb12/12r i used fony and opened the original bdf. On any font i checked you begin with 0x20, i guess there is some predefined order to find the right character when using lcd.print("A").
Where should/can i place my special characters while maintaining minimal flash usage for the font ?

Thanks in advance

Successfully converted my custom font :)

After some tests i understand that "A" converts to some number which is the big A as ascii code. So the space required for the font depends on the range of characters i provide bdf2u8g to convert.

What i don´t understand is how the width per character is defined in fony, i can only see height and ascent (ascent != width)



bdf2u8g accepts several options. You could also instruct to start with glyphs below 0x020 (dec 32): Use -b 30 to start two glyphes before 0x020 (which would be 0x1e and 0x1f)

Also in u8g.print(" ") is identical to u8g.print("\x20"). So if your custom char is at 0x1e, you could print this by using u8g.print("\x1e")

If i remember correctly, fony defines width by the number of columns in the grid.

Another option is to use u8g2, which has a build in compression for the fonts.



Jul 19, 2016, 09:22 pm Last Edit: Jul 19, 2016, 11:35 pm by smithy
Hello Oliver,

thanks for the fast reply !

I still have a problem with the output on my glcd (KS0108), sometimes the display seems not to be fast enough and some digits are displayed with bugs. I wonder if this could be a problem with my ram or rather the picture loop

This is my constructor : U8GLIB_KS0108_128 lcd(2, 3,  4,  5, 6, 7, 8, 9, A0, 11, 10, 13, 12);

I bought an 2,4" oled via the bay with SSD1305 controller and want to give it a try with your lib and SPI.
Do you suggest to use the old or the new u8g2 with this device ?

Best regards


> some digits are displayed with bugs
You probably change the values within the picture loop. Keep your variables constant while looping through the first/next loop of u8glib.

SSD1305 is not supported with both of the libs. Maybe the SSD1306 works, but i have never checked. U8g2 is more powerful and has a full frame buffer mode, which avoids the problem with wrong digits.



Aug 12, 2016, 07:41 am Last Edit: Aug 12, 2016, 08:26 am by Pspranav7
i am using this u8glib library for t6963c graphic lcd(240x128).
I am having trouble using it, as i want to Pass font via function, but hen i do that i got this error

"invalid conversion from 'char*' to 'const u8g_fntpgm_uint8_t* {aka const unsigned char*}' [-fpermissive]"

can anybody help me?

Go Up