惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
腾讯CDC
博客园 - Franky
S
SegmentFault 最新的问题
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
J
Java Code Geeks
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
I
InfoQ
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
博客园 - 叶小钗
博客园_首页
有赞技术团队
有赞技术团队
雷峰网
雷峰网
量子位
小众软件
小众软件
月光博客
月光博客
U
Unit 42
D
DataBreaches.Net

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
5x5 Pixel Font for Tiny Screens: The Complete Developer G...
佐藤玲 · 2026-04-24 · via DEV Community

5x5 Pixel Font for Tiny Screens: The Complete Developer Guide to Micro Typography

You're staring at a 128×64 OLED display, a tiny e-ink badge, or a retro game screen — and suddenly you realize your fancy TrueType font is completely useless. You need every pixel to count.

Welcome to the world of the 5×5 pixel font: the unsung hero of embedded development, retro gaming, and wearable tech. In this guide, we'll break down everything you need to know — from the theory behind micro typography to rendering your own characters in code.


Why a 5×5 Pixel Font?

When working with tiny screens — think SSD1306 OLEDs, Nokia 5110 LCDs, or even low-resolution LED matrix panels — standard fonts simply don't fit. A typical 8×8 bitmap font already feels large on a 32-pixel-tall display. A 5×5 font gives you:

  • More characters per line — on a 128-pixel-wide screen, you can fit ~25 characters vs. ~16 with an 8×8 font
  • More lines per screen — critical for data-dense UIs like sensor dashboards
  • Retro aesthetic — perfect for indie games, pixel art tools, and demoscene projects
  • Minimal memory footprint — each glyph fits in as few as 3–5 bytes

The tradeoff? Readability is a craft. Every pixel decision is intentional, and designing or choosing the right 5×5 font requires understanding the constraints deeply.


Anatomy of a 5×5 Glyph

A 5×5 pixel font means each character fits inside a 5-column by 5-row grid. With a 1-pixel gap added between characters, you effectively work with a 6×5 cell per character in horizontal layout.

Here's what the letter A might look like in a 5×5 grid:

. X X X .
 X . . . X
 X X X X X
 X . . . X
 X . . . X

Enter fullscreen mode Exit fullscreen mode

Translated to binary rows (1 = lit pixel, 0 = dark):

Row 0: 0 1 1 1 0  → 0x0E
Row 1: 1 0 0 0 1  → 0x11
Row 2: 1 1 1 1 1  → 0x1F
Row 3: 1 0 0 0 1  → 0x11
Row 4: 1 0 0 0 1  → 0x11

Enter fullscreen mode Exit fullscreen mode

This gives us a compact 5-byte representation per glyph — incredibly efficient for microcontrollers with limited flash storage.


Storing the Font in Code

Let's look at how to store a basic 5×5 font in C, suitable for Arduino, STM32, or any embedded platform.

// Each character is stored as 5 bytes (one per row)
// Bit 4 (MSB of 5-bit value) = leftmost pixel

const uint8_t font5x5[][5] = {
  // Space (ASCII 32)
  { 0x00, 0x00, 0x00, 0x00, 0x00 },
  // ! (ASCII 33)
  { 0x04, 0x04, 0x04, 0x00, 0x04 },
  // A (ASCII 65)
  { 0x0E, 0x11, 0x1F, 0x11, 0x11 },
  // B (ASCII 66)
  { 0x1E, 0x11, 0x1E, 0x11, 0x1E },
  // C (ASCII 67)
  { 0x0F, 0x10, 0x10, 0x10, 0x0F },
  // ... continue for full ASCII range
};

Enter fullscreen mode Exit fullscreen mode

To render a character at position (x, y) on a pixel buffer:

void draw_char(uint8_t *framebuffer, int fb_width, char c, int x, int y, uint8_t color) {
  int idx = c - 32; // offset from ASCII space
  for (int row = 0; row < 5; row++) {
    uint8_t row_data = font5x5[idx][row];
    for (int col = 0; col < 5; col++) {
      if (row_data & (0x10 >> col)) {
        int px = x + col;
        int py = y + row;
        framebuffer[py * fb_width + px] = color;
      }
    }
  }
}

void draw_string(uint8_t *fb, int fb_width, const char *str, int x, int y, uint8_t color) {
  while (*str) {
    draw_char(fb, fb_width, *str++, x, y, color);
    x += 6; // 5px glyph + 1px spacing
  }
}

Enter fullscreen mode Exit fullscreen mode

This is clean, portable, and works on any device where you can write pixels to a buffer.


Python Example for Prototyping

Before burning code to hardware, prototype your font rendering in Python with Pillow:

from PIL import Image, ImageDraw

font5x5 = {
    'A': [0x0E, 0x11, 0x1F, 0x11, 0x11],
    'B': [0x1E, 0x11, 0x1E, 0x11, 0x1E],
    'C': [0x0F, 0x10, 0x10, 0x10, 0x0F],
    ' ': [0x00, 0x00, 0x00, 0x00, 0x00],
}

def draw_string(text, scale=8):
    width = len(text) * 6 * scale
    height = 5 * scale
    img = Image.new('1', (width, height), 0)
    draw = ImageDraw.Draw(img)

    for i, char in enumerate(text):
        glyph = font5x5.get(char, font5x5[' '])
        for row, row_data in enumerate(glyph):
            for col in range(5):
                if row_data & (0x10 >> col):
                    x = (i * 6 + col) * scale
                    y = row * scale
                    draw.rectangle([x, y, x+scale-1, y+scale-1], fill=1)
    return img

img = draw_string("ABC")
img.save("font_preview.png")

Enter fullscreen mode Exit fullscreen mode

Run this to generate a scaled-up preview PNG — great for validating your glyph designs before deploying to tiny screens.


Designing Your Own 5×5 Glyphs

If the existing open-source fonts don't match your aesthetic, designing custom glyphs is a satisfying challenge. Here are the key rules:

1. Prioritize Legibility Over Style

At 5 pixels tall, optical illusions are real. What looks balanced in your head may appear lopsided on screen. Always test on the actual hardware or a 1:1 preview.

2. Use Consistent Stroke Width

Most successful 5×5 fonts use a 1-pixel stroke throughout. Two-pixel strokes are possible for bold variants but leave very little negative space.

3. Leverage the Center Row

The middle row (row 2) is your anchor. Characters like E, F, H, and B rely on it heavily. Plan your glyph from the center outward.

4. Numbers Need Special Attention

Digits 0–9 in a 5×5 font are tricky — especially 8 and 3. Consider if your use case is data-heavy (clocks, sensors) and optimize numbers first.

5. Avoid Isolated Single Pixels

A lone lit pixel surrounded by darkness reads as noise, not detail. Every pixel should connect to at least one neighbor — vertically, horizontally, or diagonally.


Notable Open-Source 5×5 Fonts

Before rolling your own, check these battle-tested options:

  • Tom Thumb — One of the most downloaded micro fonts. Designed specifically for tiny screens. Available as a BDF file and easily converted.
  • Mx5x5 — Clean proportional font used in several embedded UI libraries.
  • Pico-8 Font — The built-in font from the PICO-8 fantasy console. 4×6 cells but 5 pixel tall characters — widely cloned and modified.
  • u8g2 library fonts — The u8g2 graphics library ships with a massive collection of bitmap fonts including several 5-pixel-height variants, ready to use on Arduino and ESP32.

Real-World Use Cases

Wearable Displays

Smartwatch DIY projects on tiny 80×160 or 96×64 TFT screens depend on compact fonts. A 5×5 font lets you display heart rate, steps, and time simultaneously without scrolling.

Retro Game Development

Building a game for the Game Boy-style or PICO-8? The 5×5 pixel font fits naturally into 8×8 tile grids and gives your UI a classic feel. pixel art game dev courses often cover custom font design as a foundational skill.

IoT Sensor Dashboards

An ESP32 with a 128×32 OLED showing temperature, humidity, and RSSI needs every pixel. With a 5×5 font and 1px line spacing, you fit 5 lines of 20 characters — more than enough.

LED Matrix Panels

Scrolling text on a 32×8 LED matrix? A 5×5 font with smooth column-by-column scrolling is the standard approach in clock and sign projects worldwide.


Performance Tips for Embedded Rendering

  • Store font data in PROGMEM (Arduino) or flash-mapped memory to avoid eating your tiny RAM budget
  • Cache rendered strings as bitmaps when content doesn't change frame-to-frame
  • Use dirty rectangle tracking — only re-render regions of the screen that changed
  • Precompute character offsets into the font table if you're doing frequent random access
// Arduino PROGMEM example
const uint8_t font5x5[][5] PROGMEM = {
  { 0x0E, 0x11, 0x1F, 0x11, 0x11 }, // A
  // ...
};

// Reading with pgm_read_byte
uint8_t row_data = pgm_read_byte(&font5x5[idx][row]);

Enter fullscreen mode Exit fullscreen mode

This single change can save hundreds of bytes of RAM on an ATmega328 — critical when your total SRAM is only 2KB.


Accessibility Considerations

It's worth acknowledging: 5×5 fonts are not accessible by default. They are purposeful tools for constrained environments, not a first choice for general UIs. If your hardware can support larger text, do it. Reserve 5×5 for situations where the screen physically cannot accommodate anything bigger.

For mixed-size UIs, consider using 5×5 for secondary data (labels, units) and a larger font (8×8 or proportional) for primary values. embedded UI design toolkits like LVGL support multi-font layouts even on resource-constrained hardware.


Wrapping Up

The 5×5 pixel font is one of those elegant engineering constraints that forces creativity. With just 25 pixels, you craft something readable, functional, and often beautiful. Whether you're building a retro game, a wearable sensor node, or an IoT display dashboard, mastering micro typography is a skill that pays dividends every time you stare at a tiny screen.

Key takeaways:

  • Store glyphs as 5-byte row arrays for maximum efficiency
  • Add 1px character spacing for readability
  • Test on real hardware or 1:1 scale previews early
  • Use PROGMEM/flash storage on microcontrollers
  • Start with open-source fonts like Tom Thumb before designing your own

If you found this useful, follow me here on DEV for more embedded systems, graphics programming, and hardware hacking content. Got a 5×5 font you've built or a project using micro typography? Drop it in the comments — I'd love to see what you're working on.