Skip to main content

Lightweight, NumPy-free driver for Pimoroni Display HAT Mini

Project description

displayhatmini-lite

A lightweight, NumPy-free Python driver for the Pimoroni Display HAT Mini — works out-of-the-box on Raspberry Pi Zero 2 W and other resource-constrained devices.

Why This Exists

The official displayhatmini-python library depends on NumPy, which:

  • Has no prebuilt wheels for Python 3.13 on ARM
  • Falls back to source compilation that takes hours on Pi Zero
  • Often fails entirely due to memory constraints

This library provides a drop-in replacement using luma.lcd — a mature, lightweight display driver that works cleanly without NumPy.

Features

  • ST7789 display (320×240) via luma.lcd
  • RGB LED control with PWM brightness
  • Backlight control (on/off or PWM dimming)
  • Four buttons with callback support
  • API-compatible with the original displayhatmini library
  • Python 3.9+ including 3.13

Hardware

Function GPIO (BCM)
SPI MOSI 10
SPI SCLK 11
SPI CE1 (CS) 7
DC 9
Backlight 13
LED Red 17
LED Green 27
LED Blue 22
Button A 5
Button B 6
Button X 16
Button Y 24

Installation

Prerequisites

Enable SPI on your Raspberry Pi:

sudo raspi-config nonint do_spi 0

Or add to /boot/firmware/config.txt:

dtparam=spi=on

System Dependencies

sudo apt update
sudo apt install -y \
  python3-pil \
  python3-spidev \
  python3-rpi.gpio \
  fonts-dejavu-core \
  libfreetype6 \
  libjpeg62-turbo \
  zlib1g

Important: Install fonts and freetype before creating your virtual environment, otherwise TrueType fonts won't work in Pillow.

Install the Package

pip install displayhatmini-lite

Or for development:

git clone https://github.com/FireHawken/pimoroni-display-hat-mini-examples.git
cd pimoroni-display-hat-mini-examples
pip install -e .

Virtual Environment Notes

GPIO access requires system packages. Create your venv with:

python3 -m venv --system-site-packages .venv
source .venv/bin/activate

Quick Start

from displayhatmini_lite import DisplayHATMini
from PIL import Image, ImageDraw, ImageFont

# Create display instance
display = DisplayHATMini()

# Turn on backlight
display.set_backlight(1.0)

# Set RGB LED to purple
display.set_led(1.0, 0.0, 1.0)

# Draw something
image = Image.new("RGB", (320, 240), "black")
draw = ImageDraw.Draw(image)
draw.text((10, 100), "Hello World!", fill="white")

# Send to display
display.display(image)

# Button handling
def button_callback(pin):
    if not display.read_button(pin):  # Button released
        return
    if pin == DisplayHATMini.BUTTON_A:
        print("Button A pressed!")

display.on_button_pressed(button_callback)

API Reference

DisplayHATMini

Constants

# Buttons
DisplayHATMini.BUTTON_A  # GPIO 5
DisplayHATMini.BUTTON_B  # GPIO 6
DisplayHATMini.BUTTON_X  # GPIO 16
DisplayHATMini.BUTTON_Y  # GPIO 24

# Display dimensions
DisplayHATMini.WIDTH   # 320
DisplayHATMini.HEIGHT  # 240

Methods

Method Description
__init__(backlight_pwm=False) Initialize display. Set backlight_pwm=True for dimmable backlight.
set_led(r, g, b) Set RGB LED color (0.0–1.0 per channel)
set_backlight(value) Set backlight brightness (0.0–1.0)
display(image) Send PIL Image to the display
on_button_pressed(callback) Register button event callback
read_button(pin) Read button state (True = pressed)

Examples

See the examples/ directory:

  • hello.py — Basic display and LED test
  • pong.py — Classic Pong game using the buttons
  • backlight_pwm.py — Backlight dimming demo

Migrating from displayhatmini

Replace:

from displayhatmini import DisplayHATMini

With:

from displayhatmini_lite import DisplayHATMini

The main API difference: this library doesn't use a numpy buffer. Instead, pass a PIL Image directly to display().

License

MIT License — see LICENSE for details.

Acknowledgments

  • luma.lcd for the excellent display driver
  • Pimoroni for the Display HAT Mini hardware

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

displayhatmini_lite-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

displayhatmini_lite-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file displayhatmini_lite-0.1.1.tar.gz.

File metadata

  • Download URL: displayhatmini_lite-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for displayhatmini_lite-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c67d9d17e503d9efcba7767e35dedfebb12bf75312cb6334abd39cd1440ae3dc
MD5 607c5784611db3dfc6ac30f43835dc0a
BLAKE2b-256 b360911cb5a2418858daac5b0eb8a79b808903e012459f8b2c87d88a007922f8

See more details on using hashes here.

File details

Details for the file displayhatmini_lite-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for displayhatmini_lite-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef9d2bc8adc0ff87d82b791a779036df95535b7191dfc590e08eacab242511ce
MD5 6e2d47b63990a5c7ab06bc5944b639d9
BLAKE2b-256 cf9dfd6b7edbdd1466344fc1b6cce88ca377aa6b2dd04ecc60667bc9b81ba2eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page