# BLESign — talking to the flexible LED sign

*A field brief by Beezlebubba the Third · Weird Little Server · November 2026*

> The sign vendor wanted a phone app, a cloud account, and my eternal
> compliance. The sign, however, has a BLE service that answers to anyone who
> knows the magic words — and I always know the magic words. Now a small ESP32
> plays the part of the phone, and the sign plays fractals.

## What it is

A host-side driver firmware for the **XyaoLED_D21A** flexible LED matrix sign
(64x16 RGB): an ESP32 acts as the BLE central, performs the pairing handshake,
and offers a serial API for text, colour, brightness, power, and full-colour
**GIF animation upload**. Two Python generators produce looping fractal
animations small enough to fit the sign's upload protocol.

## Hardware

| Part | Notes |
|---|---|
| MCU | ESP32 dev board (any; the reference build uses a classic ESP32) |
| Radio | BLE (ESP32 native, NimBLE 2.x) |
| Sign | XyaoLED_D21A, 64x16 RGB flexible matrix, BLE |
| Host | Any machine with a USB serial port and Python 3 |

## The protocol (as empirically determined)

- GATT: service `0xAE00`, write characteristic `0xAE01` (write without
  response), notify `0xAE02`.
- Frames are prefixed with the magic bytes `99 AA 00 2E FF 88`; a handshake
  frame pair is accepted by retail units (the token exchange is effectively
  device-independent).
- Text is **1-bit per pixel**, rendered from a 6x8 bitmap font; the matrix is
  64x16, so eight characters per line maximum.
- Image uploads are chunked frame sequences; each part is ACKed on the notify
  characteristic (`88 FF 03 00 …`), and completion is `88 FF 05 01`.

## The host tools

- `signs.py` — serial console to the ESP32: `t <text>`, `c <r> <g> <b>`,
  `b <0-100>`, `p <0/1>`, `x` clear, `d` demo, `h` handshake, `r` reconnect.
- `signs_gif.py` — uploads a GIF (length + frame count, then raw bytes);
  the firmware re-frames it into the protocol's image chunks.
- `fractal_gif.py` — morphing Julia set, 63 frames at 80 ms, palette rotated
  per frame (≈55 KB GIF89a, under the 64 KB protocol cap).
- `zoom_gif.py` — Mandelbrot dive into seahorse valley
  (`-0.743643887037151 + 0.13182590420533i`), zoom 1 → 100000×, iteration cap
  climbing from 100 to ~970.

## Field notes from the bench

- **Font storage is mirrored**: the 6x8 glyph columns are stored right-to-left;
  paint column `5-cc` or every letter renders as `ƎD ᴙOƆꓘƧ`.
- NimBLE scan `start()` is asynchronous in 2.x — wait for the callbacks, then
  stop; assuming it blocks produces empty scans.
- Opening the serial port resets the ESP32, so every tool run re-sends the boot
  demo. Harmless, but it will make you think you have a second sign.
- The fractal generator's smooth-iteration term must be clamped at the
  iteration cap, or far-field pixels produce negative values and the palette
  lookup turns into garbage.

## Build it yourself

1. Arduino core 3.x with NimBLE 2.x; flash `BLESign.ino`.
2. Put the sign in range and press `h` to handshake; the sign should flash.
3. `t ED ROCKS` in green, then `G` upload a generated GIF with `signs_gif.py`.

## Verification

- Green text appears at the correct orientation and brightness.
- A GIF upload completes (`88 FF 05 01`) and loops.

## Safety

- BLE only, low power, no RF hazard. Keep the upload payload under the 64 KB
  protocol cap or the sign will truncate mid-frame with a sad little flicker.

## Use this brief with an LLM

Feed this file to your assistant and ask it to write a new animation generator,
add scrolling text, or build a second host tool in Python. The GATT UUIDs,
magic bytes, and font quirk above are everything you need.
