PiGoGUI – A MicroPython & LVGL Handheld Launcher for PiGo

New Article
PiGoRaspberryPiGamingProjects
PiGoGUI – A MicroPython & LVGL Handheld Launcher for PiGo

Why a Handheld Needs Its Own Launcher

When you build a pocketable gaming console around a Raspberry Pi Zero or Raspberry Pi Zero 2 W with a 320×240 SPI display and 16 physical buttons, a standard Linux desktop environment is completely out of place. Desktop shells expect a mouse pointer, high-resolution monitors, and hundreds of megabytes of RAM — resources you simply cannot spare when running games on a 512 MB board.

That is why I built pigogui: a dedicated, controller-first handheld launcher written in MicroPython and powered by LVGL 9.3 (Light and Versatile Graphics Library). Instead of pulling in Electron, Qt, or a full Python/Pygame stack, pigogui runs inside a tiny 4 MB MicroPython heap directly on Wayland and boots straight into a smooth 60 FPS console interface.

Purpose: More Than Just a Game List

pigogui is not merely a menu that spawns executables. Its purpose is to make the PiGo feel like a cohesive, self-contained gaming handheld from the moment you flip the power switch:

  • First-Boot Setup Wizard: Guides new users through language, theme color (dark/light mode + LVGL accent palette), Wi-Fi connection, and timezone configuration.
  • Game Library & Carousel: Automatically discovers installed games in /opt/pigo/games/, displays cover art, screenshots, and metadata, and launches them with per-game button mappings.
  • In-Game Quick Menu & HUD: Pauses and resumes running games on demand, while providing floating overlays for volume, display brightness, notifications, and real-time battery status.
  • Built-In Store & OTA Update Checks: Downloads pre-packaged games directly from GitHub Releases and checks for launcher updates in the background.
  • Full System Settings: Lets you configure Wi-Fi, Bluetooth, display brightness and sleep timers, audio volume, storage, SSH, and system updates without ever touching a terminal.

How the Code Is Structured

The repository follows a clean separation between a presentation layer (gui/), a manager and system-integration layer (libs/), and static configuration and assets (data/, fonts/, audio/).

Entry Point & Wayland Bootstrapping

Launching starts in start.sh, which configures SDL2 to render natively over Wayland and assigns the application ID pigogui so the Sway compositor recognizes it as a floating, sticky HUD:

#!/bin/bash
PIGO_PATH="$(dirname -- "${BASH_SOURCE[0]}")"
cd $PIGO_PATH
SDL_VIDEODRIVER=wayland SDL_APP_ID=pigogui micropython -X heapsize=4M $PIGO_PATH/main.py

Inside main.py, the launcher creates a 320×240 ARGB8888 LVGL SDL window, hides the cursor via SDL_ShowCursor(0), loads the user's theme from data/configuration.json (falling back to data/configurationDefault.json), initializes all core managers through SingletonsClass(), and enters a uasyncio loop ticking every 16 ms (~60 Hz) to pump lv.timer_handler() and keyboard input.

The Manager & FFI Layer (libs/)

libs/Singletons.py wires up nine singleton managers that share state across the entire UI:

  • ffishell.py: Because MicroPython's Unix port is intentionally minimal, this module binds directly to libc.so.6 via MicroPython's ffi module — exposing fork, execv, kill, waitpid, popen, setenv, and low-level open/ioctl/read/write syscalls.
  • ApplicationManager.py: The heart of game execution. It starts games with fork() and execv(), freezes and unfreezes them using POSIX SIGSTOP and SIGCONT when the user presses the Home button (mapped to SDLK_DELETE), and restarts uinput-pigo-mapper with either the game's custom keymap or the launcher's defaultKeyMap (always appending mandatoryKeyMap so hardware shortcuts never stop working).
  • DataManager.py: Merges user preferences with configurationDefault.json, scans /opt/pigo/games/ for subdirectories containing a game.json manifest, and runs non-blocking git fetch update checks via libs/threading.py.
  • BatteryManager.py: Talks directly to PiGo's onboard battery ADC over /dev/i2c-1 (I2C address 0x50) using ioctl(I2C_SLAVE). Every 3 seconds it reads a 12-bit sample, smooths it over a 20-sample rolling window, and calculates both battery voltage (3.0 V – 4.2 V) and state-of-charge percentage.
  • PageManager.py: Maintains a navigation stack with animated LVGL screen transitions across all pages, including EmptyPage, which hides the launcher cleanly while a game runs fullscreen underneath.
  • DownloadManager.py & libcurl.py: Uses FFI bindings to libcurl to stream game archives listed in data/store.json directly to disk with live progress tracking.
  • AudioManager.py, WifiManager.py, SoundDisplayBarManager.py, and NotificationManager.py: Handle UI sound effects (via CLI players such as mpg123), NetworkManager Wi-Fi scanning, brightness/volume HUD bars, and toast notifications.

Pages, Components, and Assets (gui/, fonts/, audio/)

The UI is organized into modular LVGL screens under gui/pages/ — including LaunchScreenPage, GamesOverviewPage, GameDetailsPage, StorePage, SettingsPage (with nine dedicated subpages under SettingsSubPages/), and the six-step setup/ wizard. Reusable widgets live in gui/components/ (such as GamesCarousel, BatteryIndicator, TopBar, BottomBar, SoundBar, and DisplayBar), backed by generic focusable controls in gui/components/Generic/. Pre-rendered bitmap fonts (baloo_chettan and ubuntu) and lightweight .ogg sound effects keep rendering sharp and responsive on the small screen.

Role in the PiGo Handheld Ecosystem

Within the PiGo software stack, pigogui is the console shell and orchestrator. While pi-gen-pigo builds the OS image and pigo-config sets up the kernel overlays and Sway compositor, pigogui is what turns that Linux environment into a real handheld experience: it reads hardware sensors over I2C, orchestrates uinput-pigo-mapper on every game switch, consumes packaged titles from pigo-games, and gives the player instant control over games and hardware settings with zero keyboard or mouse required.

Explore the Repository

Related articles

David Krawiec
About the Author
David Krawiec

I am very interested in many topics related to technology. My current focus lies on how to realize projects with a small budget regarding most importantly the cost of invested time. Being mostly a soloist means getting out most without the abstinence of freedom, performance or quality.