u8g2

2.29.11
U8g2 is a comprehensive monochrome graphics library for embedded systems, designed to support a vast array of OLED and LCD controllers. It provides a flexible dual-library approach, offering U8g2 for full graphical rendering and font support, and U8x8 for memory-efficient, direct-to-display text output.

Features

  • Support for a wide range of monochrome display controllers including SSD, SH, ST, UC, and IST series.

  • Dual-mode operation: U8g2 (full graphics) and U8x8 (text-only, direct-to-display).

  • Memory-optimized rendering using 1-page, 2-page, or full-frame buffer configurations.

  • Extensive font support with virtually no restriction on font height.

  • Comprehensive graphics primitives for drawing lines, boxes, circles, and frames.

  • Multiple communication protocol support: 3-wire/4-wire SPI, I2C (Hardware and Software), and 8-bit parallel (6800/8080).

  • Software-based display rotation for 0, 90, 180, and 270 degrees, plus mirroring support.

  • MUI (Minimal User Interface) subsystem for creating interactive menus and forms.

  • U8log component for emulating a serial terminal output on the display.

  • 16-bit coordinate mode support for displays exceeding 240x240 pixel dimensions.

  • Support for specialized display technologies including E-Ink and VFD controllers.

  • Dynamic memory allocation options for page buffers to optimize RAM usage.

  • Integrated icon and symbol font libraries.

  • Tile-based coordinate system in U8x8 mode for extreme memory efficiency.

  • Hardware I2C pin remapping support for compatible microcontroller architectures.

Architecture

U8g2 is designed with a layered architecture that balances hardware abstraction with graphical flexibility. At the lowest level, the library interacts with display hardware through specific communication drivers (SPI, I2C, or Parallel). The U8x8 sub-library serves as the foundational layer, providing a direct-to-display interface that operates on 8x8 pixel tiles. This layer requires no RAM buffer in the microcontroller, making it suitable for the most resource-constrained environments.

Sitting above the hardware abstraction is the U8g2 graphics engine. This layer manages the rendering pipeline and provides the API for drawing primitives and complex fonts. A core architectural feature is the Page Buffer mechanism. To support high-resolution displays on microcontrollers with limited RAM, U8g2 can render the screen in horizontal slices (pages). The application uses a firstPage()/nextPage() loop to redraw the scene for each slice, which the library then transfers to the display controller. This allows for full graphical support even when the MCU cannot hold a complete frame buffer in memory.

Use Cases

This library is ideal for:

  • Industrial Monitoring: Displaying real-time sensor data, telemetry, and diagnostic information on ruggedized monochrome LCDs.
  • User Interfaces: Building interactive menus, settings screens, and forms using the MUI (Minimal User Interface) module.
  • Portable Instrumentation: Implementing low-power visual feedback for handheld devices like multimeters, environmental sensors, or testers.
  • System Logging: Utilizing the U8log component to create an on-screen terminal for real-time debugging without requiring a secondary PC connection.
  • Battery-Powered Devices: Leveraging U8x8 mode to minimize CPU cycles and RAM usage, thereby extending the battery life of wearable or remote hardware.
  • Retro Gaming and Hobbyist Projects: Rendering simple sprites and graphics on accessible platforms like Arduino, ESP32, and STM32.

Getting Started

To begin developing with U8g2, users should first identify their display controller and the desired communication interface. In the Arduino IDE, the library can be installed via the Library Manager. The setup process involves selecting a specific Constructor that matches the hardware; this constructor defines the controller type, the buffer strategy (Full, 1-page, or 2-page), and the physical pin connections.

Once the constructor is defined, the u8g2.begin() function initializes the display and sends the required setup sequence. Drawing operations are typically performed within a do...while loop using u8g2.firstPage() and u8g2.nextPage(). For developers working in pure C or porting to new platforms, the library provides a specific C-API and documentation for implementing custom hardware abstraction layers. Detailed reference manuals and setup guides for various controllers can be found in the official Wiki.

Related Projects (30)

View All 30 Projects →
ESP32 SoundFont (SF2) Sampler Synthesizer

ESP32 SoundFont (SF2) Sampler Synthesizer

A high-performance wavetable synthesizer firmware for ESP32-S3 and ESP32-P4 microcontrollers that plays SoundFont 2 (SF2) samples. It utilizes PSRAM for large sample banks, supports USB MIDI for plug-and-play connectivity, and features real-time audio effects like reverb and chorus.

freertos littlefsu8g2
QBIT

QBIT

QBIT is an open-source desktop companion robot and personal IoT avatar based on the ESP32-C3. It features a custom monochrome animation system, integrated Wi-Fi management via NetWizard, and seamless Home Assistant integration through MQTT. The project includes a full-stack web platform for remote interaction, device claiming, and community animation sharing.

freertos littlefssqliteu8g2
PixelRoot32 Game Engine

PixelRoot32 Game Engine

PixelRoot32 is a lightweight, modular 2D game engine written in C++17 for ESP32 microcontrollers and PC simulation. It features a scene-based architecture, NES-style audio synthesis, and a high-performance rendering pipeline optimized for embedded hardware using DMA transfers.

tft-espiu8g2
ESP32 MP3

ESP32 MP3

A custom-built portable MP3 player based on the ESP32 that features Bluetooth A2DP audio streaming and a dedicated OLED user interface. It utilizes a modular C++ architecture and a custom-designed PCB to manage media playback from a MicroSD card.

freertos u8g2
EPD-nRF5: E-Paper Display Calendar and Photo Frame

EPD-nRF5: E-Paper Display Calendar and Photo Frame

An embedded firmware for nRF51 and nRF52 microcontrollers designed to drive e-paper displays for calendar and digital photo frame applications. It features Bluetooth image transmission, Chinese lunar calendar support, and a Web Bluetooth interface for cross-platform configuration.

nanopbu8g2
ESP8266 OLED HW-364A/B Development Guide

ESP8266 OLED HW-364A/B Development Guide

A comprehensive configuration guide and code repository for the HW-364A and HW-364B ESP8266 modules featuring integrated 0.96-inch OLED displays. It provides corrected I2C pin mappings, implementation examples using the U8g2 library, and specific Arduino IDE configuration settings to ensure reliable operation.

u8g2
dtuGateway for Hoymiles HMS Inverters

dtuGateway for Hoymiles HMS Inverters

dtuGateway is an ESP32-based firmware that bridges Hoymiles HMS-series solar inverters with integrated Wi-Fi to smart home ecosystems. It provides reliable data monitoring and remote control via MQTT, REST API, and openHAB, bypassing the limitations of the official cloud interface. The project supports various local displays and features a captive portal for easy configuration.

freertos nanopbtft-espiu8g2
Minigotchi-ESP32

Minigotchi-ESP32

A security-focused firmware for ESP32 microcontrollers that replicates Pwnagotchi-style peer detection and network interaction. It supports Wi-Fi scanning, deauthing, and BLE functions while providing an emotional interface through various display modules.

freertos tft-espiu8g2
255