SDK
How Miblo animates a screen with 80 KB of RAM
Miblo's memory: what is fixed, what a scene costs, the 8 and 12 KB floors, what is lent to the network and how to read the diagnostics when a scene does not load.
Miblo has 80 KB of RAM for everything: the firmware, Wi-Fi, your sessions, the pet, the card and the app's scene on the screen. There is no frame buffer (a picture of the screen would take 115,200 bytes) and no virtual memory: what does not fit does not run. This page says where that memory goes, what a scene costs, what Miblo lends to the network and how to read the diagnostics when a scene does not load. The animation guide (Animations on Miblo's screen) explains how to animate; this is the arithmetic behind it.
The budget
Of the 80 KB, the firmware takes a fixed part, there before any connection: 47.7 KB after the RAM diet (51.4 KB on 1.29.0, 54.8 KB on 1.28.0). The rest is the heap, which feeds the Wi-Fi's buffers, every open connection, every request from the bridge while it is read, the app's card, the pet's buffers, the items' captures and the scene. On a paired Miblo with a card set and the bridge's stream up, about 17 to 19 KB are free between one request and the next (measured on Amon). A scene has to fit inside those KB, beside the floors below.
Three numbers organise everything:
| Number | What it is |
|---|---|
| 12 KB | The network's reserve. A request that needs N bytes (its body, the JSON document of its answer) is served only when N + 12 KB are free, in one whole block of N + 4 KB; otherwise the answer is 503 busy. It is what keeps Wi-Fi alive |
| 8 KB | The player's floor. A scene loads when its need + 8 KB are free (and its largest allocation fits a block with 4 KB to spare), and gives its memory back when the heap drops under 8 KB after a request |
| 16 KB | The reserve of the ordinary off-screen drawing layers (a filled mesh item, for instance). The items' composition strips do not use this reserve: they use the 8 KB floor |
What is fixed
Inside the 47.7 KB are the firmware's state (38.5 KB of variables, 7.2 KB of them the context alone: config, pairings, snapshot, alerts, friends, notes), 6.7 KB of constants and 2.5 KB of initial values. On the ESP8266 constants sit in RAM unless the code sends them to the flash. Since 1.28.1 three things that were fixed follow the use instead:
The sessions' texts. The names, tools, models and details of the snapshot's rows sat in a fixed 1,536-byte block. They now live in a pool sized to the content, with every repeated text stored once: 20 typical sessions use 234 bytes. The cap is still 1,536 bytes (a larger snapshot leaves its last rows without text, never a cut text). That is 2.4 KB more free.
The pet's buffers. A bitmap pet (MPET1) draws from a 1,152-byte frame; a vector pet (MPET2) uses scratch tables. Miblo gives those buffers back whenever the pet is off the screen (the App screen, the Overview, an app alert, the display off) and when the pet's format changes; the logo and the identity stay, and the pet's next draw reloads what it needs.
The constants. Some of Miblo's own formats moved to the flash.
The RAM diet took 3.6 KB more off the fixed part, without touching any limit (20 sessions, 6,144 bytes of snapshot, 48 slots, the texts' lengths) or the drawing:
The arcs without libm's tables. The Limits ring, the cards' rings, the focus ring and some pets' heads used libm's sine and cosine, which left ~1 KB of tables in RAM. The arc is now TFT_eSPI's own, step for step, with a sine and cosine of ours that give the same bits; the pixels are the same (the test compares primitive for primitive).
No empty copies. Several structures (the config, the notes, the friends, the Wi-Fi request, the governor, the live charts) kept in RAM an empty copy of themselves, only to be born from it. They are now born cleared; the config's defaults live in the flash. About 900 bytes.
Only while in use. The off-screen drawing layer, your pet's header (only with a pet of your own), the setup network's DNS (only while it is up), the charts the bridge paints (only while there is one) and the list of networks seen (only after the first search) moved to the heap and go back when done. The file names moved to the flash.
The screens' texts. The screens' ring of translated texts had room for the longest text of the whole system (the settings page's hints, which never go through it). It is now the size of the screens' texts, with room to spare; a test says when a new translation does not fit.
Left out, on purpose: the write table of the 48 slots (the write limit needs each slot's last write at all times), the snapshot (the format the bridge uses), lwIP's and the SDK's buffers, the 12 KB and the OTA reserves, the backlight's PWM generator (512 bytes of the core; replacing it changes how the screen dims) and the config's text keys (the config's JSON reader).
The app's card, when there is one, takes up to 1 KB of heap while it is on the screen.
What a scene costs
A tile scene (the screen.animate path for art that fits in 256 tiles, with or without a per-line effect) costs three parts in RAM:
| Part | Bytes |
|---|---|
| The resident tiles | the set's compacted size (below) |
| The player | 3,104 |
| The palette cache | 528 |
The tiles are the part that varies. In the file every tile takes 32 bytes (64 pixels of 4 bits). In RAM Miblo keeps each one in the shortest form that reproduces its pixels exactly, decided when the scene loads:
| Colours in the tile | How it is kept | Bytes |
|---|---|---|
| 1 | a constant | 1 |
| 2 | two indices and 1 bit per pixel | 9 |
| 3 or 4 | four indices and 2 bits per pixel | 18 |
| 5 to 16 | the file's 4 bits per pixel | 32 |
Plus a 2-byte directory entry per tile. The compact form is used only when the total, directory included, is smaller than the file's 32 bytes × tiles; no colour is dropped, nothing changes in the file or in the SDK, and drawing keeps reading from RAM, never from the flash. The Radar, with 237 tiles, went from 7,584 to 3,816 bytes of tiles: the whole scene from 11,724 to 7,448 bytes. With the 8 KB floor it loads when about 15.6 KB are free, with its largest allocation (the tiles, 3.8 KB) in a block of 7.9 KB. A small scene (few tiles, flat colours) costs 4 to 5 KB and loads with about 12 to 13 KB free.
What helps, in the art: fewer distinct tiles and fewer colours per tile. A flat background is one byte per tile; a gradient is a 32-byte tile in every cell. The rules of the guide's chapter 4 hold here for the same reason they hold for speed.
What helps, in the fps: nothing. The rate does not change a scene's memory. The player reads each step's map from the flash in 512-byte pieces; a step that only moves sprites does not read the map again.
Items over the animation
The card is drawn over the scene. A still item (big, text or bar with no fx and no live) is composed in memory with the animation's pixels, strip by strip of 240x16 pixels and only on the rows where it has ink, and goes to the panel in one push: the panel never receives the background without the letters. That holds the first time the item appears, when its value changes and at every frame moving under it.
The memory of that:
A 240x16 strip at 4 bits asks for 1,953 bytes. It is admitted with the 8 KB floor (not the 16 KB reserve of the ordinary layers), so it fits beside a loaded scene.
When memory is to spare, Miblo keeps the capture of every still item (up to 6 KB for all of them, taken only from what is left above 12 KB + 4 KB) and composes without drawing the item again. When it is not, it composes with a temporary strip and returns it before the network needs it.
The captures are the first memory Miblo lends, before the scene.
An item with fx, a ring, a spark or a mesh does not go this way: at every step its box is repainted whole (the animation's pixels first, then the item). That is why the guide asks for small items and few effects over the art.
What is lent, and when
A scene is a cache of the flash: Miblo may drop it at any moment and load it again where it was, at the same step, with the effect's clock carrying on. While the memory is lent, the scene's picture stays on the glass (there is no frame buffer to erase), and the items keep being drawn the old way.
The order of the loans, for a request that does not fit with the 12 KB reserve:
The items' captures go first (their budget goes to zero).
The scene goes next, if the request asks for more than 2 KB, or if, asking for less, it does not fit beside the scene with 8 KB to spare. A small request (a poll, a 1 KB document) runs beside the scene.
And the floor: after a request, when under 8 KB are left with the scene loaded, the captures and then the scene are given back to the network.
The return:
Never while a request is being read.
After a hold: 150 ms after a loan to a request, 2 s after the floor.
When the scene's need + 8 KB are free (the captures count as free: they go first) and the largest of its three allocations (the tiles or the player) fits the largest block with 4 KB to spare; once loaded, a whole 4 KB block is left for the network, checked there and then (if not, it goes back and is asked again). A shortage at that instant is tried again 250 ms later; a file that does not open or a player that fails, 5 s later.
Only with the App screen on the panel. Three seconds after the App screen leaves, the scene's memory is given back for good.
POST /api/screen/anim-play answers 503 busy only when the scene would not fit even after the request is over (need + 8 KB over the free heap + what is reclaimable + 4 KB). Otherwise it is taken and loads when the heap has room.
App mode
While an app is on the screen, the Miblo switches off what neither the app nor the Miblo's own duties need and gives that memory back to the heap, for the scene (1.30). It mirrors the first setup, which runs only what the setup needs.
What never switches off:
The alerts, whole: the snapshot and the alerts the bridge sends (
POST /api/state, the stream), their parsing, the alert screens and the "needs you" mark. The alert screens ask the heap for nothing (a test draws them with every allocation failing).What takes the app off the screen: a session waiting on you, the rotation, "Show now", the apps' requests and alerts.
What the app uses: the card, the frames, the live charts, the scene and the stream.
The update (
POST /update/openand the transfer), the Wi-Fi and the clock.mDNS: the bridge finds the Miblo by browsing
_miblo._tcp, and that is part of the alerts' path (it keeps no memory between two passes of the loop).
What switches off:
| What | Bytes (measured with the device's compiler, with the heap's cost) | Comes back |
|---|---|---|
| The friends (visits, beacons, presence): their UDP socket closes and their state freezes (nothing goes out or comes in; the friends it knows stay, and expire only after 95 s without a beacon, once it runs again) | 128 (the socket) and the packets it held | The socket at the next pass; our beacon at its turn (up to 30 s) |
| A visiting pet's file fetch (and the file, with no visit) | 384, only during a visit | With the next visit |
| The list of Wi-Fi networks seen | 424, only for 5 min after a search | At the next search, as when it expires |
The friends' state (2,076 bytes) is static on this firmware; once it moves to the heap, app mode can give it back too. What already followed the screen stays as it was: the pets' buffers go away off the pet screens, the items' captures are the first memory lent, the live charts and strips go when the app leaves. The sessions' text pool stays: the alert screens take the session's name from it.
When it is on: with the App screen on the panel. It goes off in the same pass when an alert comes (or a session waits on you), when an update or the setup takes the Miblo, when the panel sleeps, when someone asks the Miblo for something (a code, a command) and when the pet's screen comes (its visits need the friends). Otherwise it stays on through the rotation's other turns shorter than 30 s (the sessions' turn, the limits arc): the rotation does not restart the friends every turn. Off, everything comes back within a pass.
After an alert, the Miblo shows the sessions (or the limits), not the app, until you have seen it: with a session waiting, until it is answered; otherwise the sessions' turn (sessionsDwellSec, 15 s by default). The rotation starts again from them; a pinned app, "Show now" and the apps' alerts wait that long.
GET /api/screen carries appMode: on, released (the heap its last entry gave back, measured there and then), enters, leaves and left (why it went off last: alert, held, person, pet, away). The serial log says appmode: on ... released N and appmode: off ... at each edge.
The floors
The two numbers that guard the network, worked out again with the binary format's measured peaks (1.30):
The player's floor, 8 KB, is what lwIP and the Wi-Fi SDK may take from the heap while a scene step draws (up to ~160 ms, with the loop unable to give anything back): one TCP receive window (4 × 536 bytes, each segment in its own buffer with its headers: ~2.5 KB) for each connection that can be receiving beside the scene (the stream, the bridge's HTTP request, a third one in its handshake: a reconnecting stream or a browser), plus ARP, beacons and the SDK's frames: 3 × 2,560 + 512 = 8,192. App mode switches off only UDP (the friends), so all three remain possible: the floor stays. Under it, the device has shown lwIP stop accepting connections with 2 to 6 KB free (1.26.0).
What runs beside the scene, 2 KB. A request of up to 2 KB runs with the scene loaded, as long as the 8 KB are left after it. In the binary format the snapshot asks for the text pool (1,600 bytes; measured peak 2,565 bytes with its body, judged in two steps) and the card asks for a small document and the Card (1,276 bytes; the measured peak beyond the body is 227 bytes): both stay under 2 KB with 256 bytes to spare, so the bridge's snapshots and cards never take the scene's memory.
The SDK's reserve, 12 KB, stays for the rest: a JSON body (sized by its length, as before; a JSON snapshot peaks at 12,094 bytes) is over 2 KB and takes the scene's memory before it is read.
The block. A scene is three allocations (the player, the palette cache and the tiles), never one block the size of its whole need. The Miblo asks for the largest of them in a block with 4 KB to spare and, once loaded, checks that a whole 4 KB block is left for the network. Asking for the whole need + 4 KB in one block refused scenes the heap could hold: the simulator's "Excellent" stopped at a 10.2 KB scene with a 14.3 KB largest block. The largest possible tiles (256 × 34 bytes) fit the measured block.
The native tests (test_anim, test_appmode) fail if any of these reserves drops under the measured peak plus its margin.
The room a scene has on the App screen, by the simulator's account (the free heap measured on 1.28.1, plus what the firmware gave back since, less the floor and the margin):
| Excellent up to | Attention up to | |
|---|---|---|
| Measured on 1.28.1 | 9.7 KB | 12.0 KB |
| 1.30.0 with app mode (projected) | 12.9 KB | 16.6 KB |
The projection adds 3,268 bytes of static RAM (51,216 on 1.28.1, 47,948 now: the linker's count) and the friends' socket's 128 bytes. The next long reading on 1.30.0, with the App screen up and app mode on, measures the real idleHeap and replaces the projection.
What your app costs the Miblo
Your app's code runs on the computer; what costs the Miblo is what the app puts there: the card (its items, the live charts), the scene (the resident tiles, the player and the cache; or, for frames, a step's decoder and strip and the open files), the frames in the flash slots, the fps asked times each step's measured cost, and the requests the bridge sends. The simulator (miblo apps dev), miblo screen status and the SDK's screen.budget() (TypeScript and Python) do that sum with the numbers measured on a real Miblo and put each resource in one of three bands, with one line of what to do. It is an estimate: the numbers come from the measurements below and never promise more than they show.
Estimate, measured on Miblo 1.30.0, 1.30.2 (Amon, 2026-10-12; 275 memory readings, 1378 scene steps).
| Excellent | Attention | Won't fit | |
|---|---|---|---|
| RAM (scene + card + live charts) | up to 12.3 KB | 12.3 KB to 15.8 KB: loads while the Miblo is calm, may be lent away and stutter | over 15.8 KB: does not load |
| Storage | up to 3 slots and 23.0 KB | up to 8 animation slots, fitting in the flash | over 8 slots in one animation, a frame over 60 KB or over 650 KB |
| Processing | up to 81 % of the loop, at the fps asked | the Miblo lowers the rate, staying at half the fps asked or more | under half the fps asked |
How each boundary is made: a fixed part (the firmware's rule) and a flexible part (the measured spread). RAM: the measured free heap (p10 22.2 KB, median 24.0 KB), less the player floor (8 KB) and a margin of 7.6 %, and the scene's largest allocation (its tiles or the player) in one whole block with 4 KB to spare (largest block p10 17.9 KB). Frames (rectangle or whole) count a step's decoder (0.3 KB), the 8-row strip (3.8 KB) and each open file (0.3 KB: the base and the step, or the step alone); without room for the strip a step is drawn one row at a time (0.5 KB), and only won't fit when not even that fits. A card alone (up to 1 KB, plus 2 KB with live charts) always fits. Processing: the governor (interval = the larger of 1000 / fps and the draw + 2 ms; everything together up to 90 % of the loop) less a margin of 10 % for the measured spread of a step.
Measured cost of a step (with the card's items over it): tiles 42 ms (p90) + 0.04 ms per tile that changes; perspective 39 ms + 2.44 ms per thousand pixels; rotate 39 ms + 3.33 ms per thousand pixels; scroll 39 ms + 4.65 ms per thousand pixels; wave 39 ms + 3.61 ms per thousand pixels (from the guide, not measured in this round); zoom 39 ms + 3.33 ms per thousand pixels (the same as rotate: not measured yet); live chart 7 ms; item effect 62 ms.
The numbers live in one file (plugin/assets/budget.json), rebuilt from a long reading of GET /api/info and GET /api/screen by plugin/scripts/budget-from-soak.mjs (p10 of the free heap, p90 of each effect's draw); this table is generated from it by plugin/scripts/budget-docs.mjs.
How to read the diagnostics
Everything below is read on the device, with the paired computer's token (Authorization: Bearer), or through the bridge where said. That token is the one the bridge keeps for Miblo Desk it paired, in Miblo's data folder; it is never handed to programs, and you rarely need it: miblo screen status prints what matters here (the scene, whether it loaded and why not, the real fps and the budget), and your program reads the same through screen.status() and screen.budget().
GET /api/info
| Field | What it is |
|---|---|
heap | The free heap at the instant of the answer, inside the handler, after it allocated its own document (~2 KB). Do not compare it with idleHeap |
idleHeap | The free heap sampled by the main loop, outside any request. This is the number to compare between readings and between versions |
maxBlock | The largest whole free block. Much smaller than idleHeap means fragmentation |
minHeapParse | The lowest free heap seen while a snapshot was read |
petDrawingBytes, guestDrawingBytes | The drawing buffers of your pet and of the visiting pet, if loaded (0 when given back) |
petLogoBytes | The custom pet's logo, which stays |
snapshotTextBytes, snapshotTextUsed | The sessions' text pool: allocated and used |
GET /api/screen
| Field | What it is |
|---|---|
panel | What is on the glass now: app, main, desk, summary, alert, pet, limits, preview, boot, setup, code, disconnected, updating, off (display off) or other. shown only says whether the App screen is pinned; it does not say it is on the glass |
anim.loaded | The scene is loaded in RAM |
anim.yielded | It is not, because its memory was lent; it comes back by itself |
anim.need | What loading costs: compacted tiles + player + cache (while it is not loaded) |
anim.why | While it is not loaded: how many passes of the loop were refused for each reason since the last load. notShown (the App screen is not on the panel), pending (a request being read), hold (the wait after a loan), free (need + 8 KB were not free; lastFree says how much was), room (no whole block; lastFree and lastBlock), failed (the file or the player) |
anim.yields, anim.yieldNeed | How many times the scene's memory was lent to a request since it started playing, and what the last one asked for |
anim.floorYields | How many times it was given back by the 8 KB floor |
anim.compose | ok: strips composed over the animation; noLayer: strips that did not fit in memory at that instant (the item was repainted the old way); inexact: captures that did not represent the item exactly (the same). ok counts strips, not frames, and an item drawn from its kept capture does not count |
anim.heap, anim.tileBytes, anim.tileRawBytes | With the scene loaded: what it takes, the compacted resident tiles and what they would be uncompacted |
anim.real | { fps, drawMs }: the rate achieved and the last draw |
appMode | App mode (1.30): on, released (bytes its last entry gave back), enters, leaves, left (why it went off: alert, held, person, pet, away) |
governor | Every animating kind (anim, fx, meshWire, meshFlat, transition, live): its current fps, its last draw and the average |
miblo screen status
The bridge reads loaded, yielded, why and yields from the device and prints a reason on the animation's line:
Animação: blocos de Clima · 8 fps pedidos · — fps real · — ms · não carregada (sem memória livre: 7,9 KB livres).
Animação: blocos de Radar · 10 fps pedidos · 9 fps real · 48 ms · memória emprestada 3×.panel, floorYields and compose do not go through the bridge: read them on the device.
Why the scene did not load
miblo screen status says | anim.why | What is going on | What to do |
|---|---|---|---|
| "a tela do app não está no Miblo" | notShown | The App screen is not on the panel (another screen, the rotation on another app, the display off). The scene loads only with it on the glass | Nothing: it loads on the app's turn. Check panel |
| "uma requisição em curso" | pending | The bridge is sending something (a card, a live batch) on every pass | Normal for moments; constant, it is a bridge sending too much (a card every second, for instance) |
| "devolvendo a memória emprestada" | hold | The 150 ms or 2 s wait after a loan | Nothing |
| "sem memória livre: N KB livres" | free | need + 8 KB were not free. lastFree says how much was | A smaller scene (fewer distinct tiles, fewer colours per tile); fewer things open on the Miblo (another computer's stream, a visiting pet) |
| "sem um bloco de memória inteiro: N KB livres" | room | There are free bytes, but the scene's largest allocation does not fit a block with 4 KB to spare, or, once loaded, no 4 KB block would be left: fragmentation | As above; maxBlock in /api/info shows the block |
| "o arquivo ou o player falhou" | failed | The file in the slot does not open or does not validate | Send the scene again (screen.animate); the SDK rewrites the slot |
| "(memória emprestada a uma requisição)" | yielded with no counts | The scene was loaded and gave way to a request; it is back in 150 ms | Nothing |
| "memória emprestada N×" | yields | The scene plays, but gives way often | Normal a few times a minute; every second, it is the bridge sending requests too large (big cards, snapshots every second) |
A scene stuck on free or room with the App screen on the glass is this page's arithmetic: its need (anim.need) + 8 KB does not fit in idleHeap. The anim.compose numbers say whether the items are being composed (ok growing) or repainted the old way (noLayer growing): in the second case the heap is at its limit during the draw, even with the scene loaded.
What lives in the flash and what lives in the data partition
The ESP8266 maps 1,044,464 bytes of program flash. Miblo 1.29.0's image took 983,360 (94 %), and 159 KB of it were data, not code: the fonts (44.6 KB), the seven languages' strings (42.8 KB), the settings page's scripts (26 KB). Code cannot be loaded dynamically on the ESP8266, but data can live on the data partition (LittleFS, 1 MB) as the apps' scenes already do. Since 1.30.0 the firmware carries only what must exist before any internet, and fetches the rest from miblo.ai by itself (lib/miblo_core/src/miblo_assets.h):
| Stays in the firmware | Goes to the data partition (/assets/) |
|---|---|
| English and Brazilian Portuguese whole; of the other five languages only the strings of the setup, pairing, update and download screens (104 each) | Each other language's whole table (strings-<code>.bin, 7 to 8 KB) |
| ASCII, the Portuguese letters, the common signs (° º ª · £ ¥ ± × ÷ µ) and every letter a built-in string draws (¡ ä è ñ ò), in every font (17.8 KB), the digits fonts | The other Latin glyphs (Latin-1, Latin Extended-A, Ș Ț) of every font: the font-latin.bin pack (31.7 KB). Packs for other scripts (Cyrillic, Greek, CJK...) use the same mechanism once published |
| The CSS, the time zone picker, the settings page's main script, the Terms and Privacy summaries | The page's extra scripts (the System panel, the Wi-Fi card, My pet) and the miblo.local picker: page-extra.bin (15 KB) |
Without a resource nothing goes blank: a language without its file shows English (outside the setup screens, which speak all seven), a glyph only the pack has draws the replacement box, and a card of the page whose script is missing says what is missing and that Miblo fetches it itself. With the resources on the device every screen is pixel for pixel what it was (test_fonts compares the whole fonts with the built-in part plus the pack, glyph by glyph).
How it arrives: once on Wi-Fi (never on the setup network, never during a firmware update or with the heap short), Miblo fetches http://miblo.ai/dl/assets/<version>/catalog.sbin, its version's catalogue signed with the project's release key (Ed25519; the public key is in the firmware), checks the signature and the generation (a generation below the installed one is refused), and downloads one file at a time into /assets/dl.tmp, checking its SHA-256 as it writes; only a whole, verified file replaces the previous one. The first download after a start shows on the screen ("Downloading resources… 3 / 8", the item, its size, "from miblo.ai"); the later ones (daily, or when a screen misses something) land in the settings page's "Downloaded resources" list, dated. The request to miblo.ai carries only the file's path and the firmware version (User-Agent: Miblo/<version>).
In RAM the resources cost little: the table of what is installed (16 × 8 bytes), the active language's file kept open between frames (only when the language is neither English nor Portuguese: ~230 bytes of heap plus its pair table, ~270) and each open font pack (~500 bytes of heap, with the last glyph read). Strings and glyphs are read from the file in small pieces, as the scenes are. Firmware 1.30.0 is 952,704 bytes (91 %, −30.7 KB from 1.29.0), the Ed25519 verifier (4.1 KB), the fetch, the screen and the new strings included.
Diagnostics: GET /api/assets (a token or the page's session) lists each resource with its size, date, source, whether it was verified, whether it is required (and why) and the last error (dns, connect, timeout, http, signature, catalog, rollback, sha256, no_space, storage, memory); the Serial says "assets: ..." at every step.