Adafruit GFX vs U8g2: Which OLED Library Should You Use?
Short answer: on an Arduino Uno or Nano, U8g2 is usually the better choice. In our compile tests the same sketch used about 4.8 KB less flash, and U8g2's page mode needs only 128 bytes of RAM for the screen. On an ESP32 or ESP8266 either works: pick Adafruit GFX if you follow Adafruit tutorials, and U8g2 if you want lots of fonts or one library for many display chips.
By Bilal Ramzan · Measured 29 October 2026 · Arduino Uno · Arduino AVR compiler (avr-gcc 7.3) · Adafruit SSD1306 2.5.17 + GFX 1.13.0 · U8g2 2.37.1
Adafruit GFX vs U8g2 at a glance
| Adafruit SSD1306 + GFX | U8g2 | |
|---|---|---|
| Flash, same 16x16 icon sketch (Uno) | 13,172 bytes (11,698 without the start-up logo) | 8,378 bytes full buffer, 8,406 bytes page mode |
| RAM for a 128x64 screen | 1,024-byte buffer, taken when begin() runs | 1,024 bytes (_F_), 256 bytes (_2_) or 128 bytes (_1_) |
| Bitmap format | drawBitmap: rows of bytes, leftmost pixel in the highest bit (MSB first) | drawXBMP: XBM, leftmost pixel in the lowest bit (LSB first) |
| Fonts | One built-in 5x7 font plus 57 font files in its Fonts folder | Over 2,000 fonts, counting each character-set version |
| Display chips | One library per chip family: Adafruit_SSD1306, Adafruit_SH110X (SH1106, SH1107), Adafruit_SSD1327 and others | One library for many controllers (91 driver files in version 2.37.1) |
| How you draw | Draw into the buffer, then display.display() | clearBuffer() / sendBuffer(), or a firstPage() / nextPage() loop |
| Help and examples | Adafruit Learn guides and most beginner tutorials | The U8g2 wiki, with a reference page for every function |
Flash and RAM, measured
We compiled the same small sketches with both libraries for an Arduino Uno, using the compiler the Arduino IDE uses. Flash is the "Sketch uses" number; RAM is the "Global variables use" number the IDE prints.
| Sketch | Adafruit SSD1306 | U8g2 full buffer (_F_) | U8g2 page mode (_1_) |
|---|---|---|---|
| 16x16 icon | 13,172 B flash 344 B RAM + 1,024 B at begin() | 8,378 B flash 1,556 B RAM | 8,406 B flash 660 B RAM |
| "Hello, OLED!" in a small font (Adafruit built-in 5x7, U8g2 6x10) | 13,136 B flash 358 B RAM + 1,024 B at begin() | 9,546 B flash 1,568 B RAM | 9,568 B flash 672 B RAM |
| "Hello, OLED!" in a larger font (FreeSans 9pt, U8g2 helvR12) | 14,962 B flash 358 B RAM + 1,024 B at begin() | 10,032 B flash 1,568 B RAM | - |
Three things the table shows:
- The IDE's RAM number hides Adafruit's screen buffer. Adafruit SSD1306 allocates its 1,024-byte buffer when
display.begin()runs, so "Global variables use 344 bytes" is really about 1,368 bytes once the sketch starts. U8g2's full buffer is counted up front. For a 128x64 screen the two are close; page mode is what really saves RAM (660 bytes in total). - About 1.5 KB of the Adafruit sketch is the Adafruit logo that
begin()draws at start-up. Uncomment// #define SSD1306_NO_SPLASHnear the top ofAdafruit_SSD1306.hto remove it: our icon sketch dropped from 13,172 to 11,698 bytes. - Fonts cost flash in U8g2, not in Adafruit's default text. Adafruit's built-in 5x7 font is always compiled in, so printing text added nothing. Each U8g2 font adds its own size: the 6x10 font added about 1.2 KB, helvR12 about 1.7 KB. Adafruit's FreeSans 9pt added about 1.8 KB.
Same image, both libraries
Both libraries store a 1-bit picture as bytes in flash (PROGMEM), and a 128x64 image is 1,024 bytes in both. But they read the bits of each byte in opposite order:
// Adafruit GFX: horizontal rows, leftmost pixel = highest bit (0x80)
display.drawBitmap(x, y, logo, 128, 64, SSD1306_WHITE);
display.display();
// U8g2: XBM rows, leftmost pixel = lowest bit (0x01). Note the argument order.
u8g2.clearBuffer();
u8g2.drawXBMP(x, y, 128, 64, logo_xbm);
u8g2.sendBuffer();
If you use an array made for the other library, the picture looks mirrored inside every 8-pixel strip. You do not need the original image to fix it: paste the array into OLED Bitmap Converter, choose the other library, and it writes the bytes in the right order. The U8g2 Image Converter does the same from an image.
Speed
On I2C, both libraries send the whole 1,024-byte screen at 400 kHz, which takes about 25-30 ms per full frame, so both top out at roughly 30-40 FPS for full-screen animation. Adafruit GFX and U8g2 full-buffer mode run your drawing code once per frame. U8g2 page mode runs it once per strip, 8 times per frame with _1_ or 4 times with _2_. That costs processor time on a slow board, and is the price of the tiny RAM use.
Which one should you use?
| Your project | Pick | Why |
|---|---|---|
| Arduino Uno or Nano with a full-screen image or animation | U8g2 | About 4.8 KB less flash in our tests leaves room for more frames |
| Uno or Nano showing "SSD1306 allocation failed" | U8g2 page mode (_1_) | A 128-byte buffer instead of 1,024 bytes |
| Menus, readings and lots of text | U8g2 | Hundreds of font designs in many sizes |
| ESP32, ESP8266 or Pico | Either | Plenty of flash and RAM; use the one you know |
| Following an Adafruit Learn guide or using an Adafruit OLED board | Adafruit GFX | Your code will match the guide line by line |
| 1.3" SH1106 module | Either | Adafruit SH110X or a U8g2 SH1106 constructor; see SH1106 vs SSD1306 |
| 1.5" 128x128 SSD1327 | U8g2 (in this converter) | Our converter writes SSD1327 code for U8g2 only |
| Several different display chips in one project | U8g2 | One library and one set of functions for all of them |
Switching from Adafruit GFX to U8g2
Most drawing functions have a direct match. Both lists below compile for an Arduino Uno.
| Adafruit GFX | U8g2 |
|---|---|
display.clearDisplay(); | u8g2.clearBuffer(); |
display.display(); | u8g2.sendBuffer(); |
display.drawPixel(x, y, SSD1306_WHITE); | u8g2.drawPixel(x, y); |
display.drawLine(x0, y0, x1, y1, SSD1306_WHITE); | u8g2.drawLine(x0, y0, x1, y1); |
display.fillRect(x, y, w, h, SSD1306_WHITE); | u8g2.drawBox(x, y, w, h); |
display.drawRect(x, y, w, h, SSD1306_WHITE); | u8g2.drawFrame(x, y, w, h); |
display.drawBitmap(x, y, bmp, w, h, SSD1306_WHITE); | u8g2.drawXBMP(x, y, w, h, xbm); (convert the bytes to XBM first) |
display.setCursor(x, y); display.print("Hi"); | u8g2.setFont(u8g2_font_6x10_tr); u8g2.drawStr(x, y, "Hi"); (y is the text baseline) |
display.setRotation(2); | u8g2.setDisplayRotation(U8G2_R2); |
Frequently Asked Questions
Is U8g2 better than Adafruit GFX?
Neither is better for everything. On an Arduino Uno, U8g2 used about 4.8 KB less flash than Adafruit SSD1306 in our compile tests, and its page mode needs only 128 bytes of RAM for the screen. Adafruit GFX has simpler code and matches most tutorials. On an ESP32 or ESP8266 either is fine.
Why does my image look wrong after switching from Adafruit to U8g2?
The two libraries read bitmap bytes in opposite bit order: drawBitmap expects the leftmost pixel in the highest bit, drawXBMP in the lowest. The picture looks mirrored in 8-pixel strips. Convert the image again for the library you use, or paste the old array into the converter and choose the other library.
How much RAM does each library need for a 128x64 OLED?
Adafruit SSD1306 takes a 1,024-byte screen buffer when display.begin() runs. U8g2 needs 1,024 bytes in full-buffer mode (_F_), 256 bytes with _2_ and 128 bytes with _1_. An Arduino Uno has 2,048 bytes of RAM in total.
Does U8g2 work with the SH1106?
Yes. Use U8G2_SH1106_128X64_NONAME_F_HW_I2C, or the _1_ / _2_ version for page mode. With Adafruit you need the separate Adafruit SH110X library and the Adafruit_SH1106G class.
Can I make the Adafruit SSD1306 library smaller?
Yes, a little. About 1.5 KB of flash is the Adafruit logo that begin() draws at start-up. Uncomment #define SSD1306_NO_SPLASH in Adafruit_SSD1306.h to remove it; in our Uno test the sketch went from 13,172 to 11,698 bytes.
Get code for either library
Upload an image or GIF, choose Adafruit GFX or U8g2, and get a complete sketch with the right byte order and constructor. Sources: Adafruit SSD1306, Adafruit GFX, U8g2 wiki.
Open OLED Bitmap Converter