u8g2

repository·master·Indexed 24 days ago

https://github.com/olikraus/u8g2

A versatile monochrome graphics library for embedded devices supporting a wide variety of OLED and LCD controllers (e.g., SSD1306, SH1106, ST7920). It provides two modes: U8g2, a full-featured graphics library with support for lines, boxes, circles, and various fonts; and U8x8, a memory-efficient text-only character device library for low-memory environments that writes directly to the display without a microcontroller buffer.

Tokens
3.3K
Snippets
9
Records
24
Agent score
92%

What's inside u8g2

  1. Overview of U8g2 and U8x8 libraries

    master

    U8g2 is a monochrome graphics library for embedded devices supporting a wide range of OLED and LCD controllers (e.g., SSD1306, SH1106, ST7920, etc.). The project provides two distinct libraries depending on your memory and feature requirements:

    • U8g2: A full graphics library. It includes procedures for drawing lines, boxes, and circles, and supports a vast array of fonts with varying heights. Note that it requires microcontroller memory to maintain a buffer for rendering the display.
    • U8x8: A text-only character device library. It is designed for extremely low-memory environments as it writes directly to the display without requiring a microcontroller buffer. It only supports fonts that fit within an 8x8 pixel grid.
  2. Use Fony bitmap font editor

    master
    Fony is a freeware bitmap font editor included in the repository. It is a Windows executable used for creating or editing bitmap fonts for use with u8g2. While the original website was previously unavailable, it is now accessible again at the link below.
  3. Hardware timing requirements for SSD13xx controllers

    master

    When working with SSD13xx displays, observe the following timing constraints to ensure stable operation:

    • Power-on delay: SSD1306 and SSD1306b require a "stable" delay. SSD1317 and SSD1320 require 20ms. SSD1322, SSD1325, SSD1326, and SSD1327 require a "stable" delay.
    • Init to Data delay: Most controllers (SSD1306, SSD1306b, SSD1309, SSD1312, SSD1317, SSD1320, SSD1322, SSD1325, SSD1326, SSD1327) require a 100ms delay after initialization before data can be sent.
  4. Quick Start U8g2 on RT-Thread

    master

    You can set up U8g2 on the RT-Thread operating system using either a GUI-based approach or a terminal-based approach depending on your preferred environment:

    • Windows (GUI): Use RT-Thread Studio. A video tutorial is available on YouTube to guide you through the process.
    • Ubuntu (Terminal): Use RT-Thread ENV tools. A terminal-based tutorial is available via asciinema.

    Note: RT-Thread offers both a Standard version for resource-rich IoT devices (manageable via online software packages) and a Nano version for resource-constrained MCUs (requiring as little as 3 KB Flash and 1.2 KB RAM).

  5. Build U8g2 with GPIO character device support

    master

    Use this build method for better performance and stability on modern kernels. It utilizes the c-periphery userspace library via the GPIO character device.

    cd ~/u8g2/sys/arm-linux
    make clean
    make CPPFLAGS=-DPERIPHERY_GPIO_CDEV_SUPPORT=1 CC=gcc CXX=g++
  6. Hardware configuration for STM32L031 DMA SPI performance test

    master

    This guide provides the hardware wiring and performance benchmarks for using U8g2 with an STM32L031 microcontroller using DMA SPI. This configuration is optimized for high FPS (Frames Per Second) using the uc1609_slg19264_f or uc1609_slg19264_1 constructors.

    GPIO Wiring Mapping

    Connect the display to the STM32L031 using the following GPIO pins:

    GPIODisplay PinColor
    PA14CDbrown
    PA13CSyellow
    PA7MOSIgreen
    PA6Resetwhite
    PA5SCKpurple
  7. Configure non-root access for U8g2 on arm-linux

    master

    To access GPIO, I2C, and SPI devices without running as root, create a dedicated u8g2 group, add your user to it, and set permissions for the device files via /etc/rc.local.

    sudo groupadd u8g2
    sudo usermod -a -G u8g2 username
    
    # Add the following to /etc/rc.local:
    chown -R root:u8g2 /dev/gpiochip*
    chmod -R ug+rw /dev/gpiochip*
    chown -R root:u8g2 /dev/i2c*
    chmod -R ug+rw /dev/i2c*
    chown -R root:u8g2 /dev/spidev*
    chmod -R ug+rw /dev/spidev*
  8. Modify U8g2 source for hardware configuration

    master

    Before building, you must modify the example source files to match your specific hardware configuration. Key parameters to adjust in the .c files include:

    • GPIO_CHIP_NUM: The GPIO chip number (e.g., 0 for /dev/gpiochip0).
    • SPI_BUS: The SPI bus number (e.g., 0x10 for /dev/spidev1.0).
    • OLED_SPI_PIN_RES: The RESET pin number.
    • OLED_SPI_PIN_DC: The DC pin number.
  9. Integrate u8g2 with Raspberry Pi Pico / RP2040 using the Pico SDK

    master

    This implementation provides a reference HAL (Hardware Abstraction Layer) for integrating u8g2 with Raspberry Pi Pico-class boards using the official Raspberry Pi Pico SDK. It is intended to be used as a template that can be copied and adapted for specific projects on RP2040 or RP2350 platforms.

    The implementation provides minimal HAL layers for:

    • GPIO control
    • Delay functions
    • Communication callbacks (e.g., SPI/I2C)

    This example is compatible with both the Raspberry Pi Pico (RP2040) and Raspberry Pi Pico 2 (RP2350) without modification.