---
title: "u8g2 OLED Draw"
description: "native_sim build-and-run only; not yet run on a bench SoM."
source: https://docs.alplab.ai/sdk/examples/u8g2-oled-draw
---

# `u8g2-oled-draw`

:::warning[`[UNTESTED]`]
`native_sim` build-and-run only; not yet run on a bench SoM.
:::

Render text, a frame, and a box into a RAM framebuffer with [u8g2](https://github.com/olikraus/u8g2), then dump the buffer to the console as ASCII art.

Source: [`examples/display/u8g2-oled-draw/`](https://github.com/alplabai/alp-sdk/tree/main/examples/display/u8g2-oled-draw).

## What it does

Sets up a `u8g2_t` against a hand-written **null device** (`src/u8g2_ram_null.c`, 64×32, never touches a bus) via `u8g2_SetupDisplay()` / `u8g2_SetupBuffer()`, then calls `u8g2_DrawFrame()`, `u8g2_DrawBox()`, and `u8g2_SetFont()` + `u8g2_DrawStr()`. Finally it dumps the RAM tile buffer as ASCII.

The teaching point: u8g2 draws through an abstract device callback (`u8x8_msg_cb`). The same `u8g2_t` and the same draw calls run whether that callback pushes tiles over I²C/SPI to a real SSD1306, or — as here — does nothing at all and leaves the drawing in RAM.

u8g2 ships no `zephyr/module.yml` upstream, so `libraries: [u8g2]` sets `CONFIG_ALP_SDK_U8G2_VENDORED_CORE`, which gates the SDK's Zephyr module compiling the vendored core draw pipeline.

## Hardware swap: a real SSD1306

Swap `u8g2_ram_null_Setup()` for a generated panel setup, e.g. `u8g2_Setup_ssd1306_64x32_1f()`. The `u8g2_t` and every draw call afterwards are unchanged. `u8g2_InitDisplay()` — commented out in `main.c` — becomes required on real hardware.

```yaml
# board.yaml
cores:
  m55_hp:
    peripherals:
      - i2c        # or spi, depending on the panel's wiring
chips:
  - ssd1306
```

## `board.yaml`

As shipped there is no panel peripheral: no `i2c` / `spi`, no `chips:` entry.

```yaml
libraries:
  - name: u8g2
    cores: [m55_hp]

som:
  sku: E1M-AEN801

preset: e1m-evk
cores:
  m55_hp:
    app: ./src
    peripherals: []

diagnostics:
  log_level: info
```

## Expected output

The real dump is 32 lines of 64 characters; this is trimmed. The string `alp` renders as *pixels* near the bottom of the frame, not as literal text.

```
[u8g2-oled-draw] 64x32 canvas (# = lit pixel):
................................................................
.##############################################################.
.#............................................................#.
.#..##########..................................................#.
...
.#............................alp..............................#.
.##############################################################.
................................................................
[u8g2-oled-draw] done
```

## See also

- [`gfx-compat-blit`](https://docs.alplab.ai/sdk/examples/gfx-compat-blit) — the RGB565 fill/blit shim
- [Examples overview](https://docs.alplab.ai/sdk/examples/overview)
