> ## Documentation Index
> Fetch the complete documentation index at: https://docs.edgeimpulse.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Halloween project: Feed the Gargoyle with Edge Impulse

> Arduino UNO Q candy-dispensing gargoyle with an Edge Impulse model cascade: visitor detection, scream and keyword recognition, costume-aware dialogue for Halloween

Created By: Abhinav Krishna N

Public Project Links:

* Visitor gate: [https://studio.edgeimpulse.com/public/1153004/live](https://studio.edgeimpulse.com/public/1153004/live)
* Riddle keywords: [https://studio.edgeimpulse.com/public/1172323/live](https://studio.edgeimpulse.com/public/1172323/live)
* Costume: [https://studio.edgeimpulse.com/public/1172324/live](https://studio.edgeimpulse.com/public/1172324/live)
* Props: [https://studio.edgeimpulse.com/public/1160020/live](https://studio.edgeimpulse.com/public/1160020/live)

GitHub Repo: [https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle](https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle)

![Feed the Gargoyle cover](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/cover.jpg?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=6f955a9cc89ebbdfbc745bec4274f2f5)

## The Story

![The finished model from the front: eyes lit, the third eye in the forehead, the tongue slide down the plinth.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-10-take-a-tour-of-the-3d-10.3a-front-render.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=37ccd0812f3f0f398e2215635c30c70a)

Nobody remembers who carved the imp. Everybody remembers the curse.

Long ago, a little stone trickster stole sweets off doorsteps one Halloween too many. The carver who caught it did not smash it. He sealed it in stone with one rule: guard the sweets forever, and never hand one out for free.

The curse said nothing about a good answer.

Halloween, just after dark. A small witch walks up the path and stops. Beside the door sits a cracked stone gargoyle. It has not moved all night.

Then its eyes open, glowing orange.

*"Pointed hat, wicked grin. Do you stir spells, or only sweets?"*

Mist curls from its teeth. Eight plates along its spine light up.

*"Light me and I work hard. The harder I work, the shorter I get."*

The plates start going dark, one by one. She spots the jack-o'-lantern on the step.

*"Pumpkin!"*

It cackles. *"Wrong! My stone belly rumbles with delight. Make a wish and blow me out."*

Two plates left. She thinks of birthday cake.

*"CANDLE!"*

Green eyes. A click deep inside the stone. A wrapped sweet slides down its tongue to her feet.

*"Right! I grumble, but I pay my debts. Take it."*

The eyes close, and it is a statue again. Her dad is already walking up the path to have a go.

On meaner nights it skips the riddle and demands a scream instead. Think you would have earned your sweet? Here are two more from its bank:

> *"I follow you everywhere, copy every move, and never once say thank you."*
>
> *"I have eight legs, I knit my own house, and flies are my dinner guests."*

(Answers at the end.)

[Answer the riddle for sweets: a visitor answers out loud and a sweet comes down the tongue.](https://www.youtube.com/embed/r3AiIEwYm_g)

Answer the riddle for sweets: a visitor answers out loud and a sweet comes down the tongue.

### Why I built it

I wanted to make trick-or-treat at our door a little more fun and interactive: something that makes people stop, think, laugh and earn their sweet, with no phone in sight. Riddling gatekeepers go back to the Sphinx, and long before trick-or-treat, people went guising: perform at the door, get fed. The gargoyle is that old deal with a new brain.

**In one line:** a cursed stone gargoyle for the front door that asks trick-or-treaters a riddle out loud, listens to their answer, and pays a right answer (or a loud enough scream) with one wrapped sweet down its tongue. Everything runs offline on one Arduino UNO Q: four Edge Impulse models, a voice rendered on the board, and a microcontroller that drives the lights, the candy servo and the mist with a watchdog that fails safe.

**Code, CAD and schematic (MIT):** [https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle](https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle)

***

## What It Does

[Feed the Gargoyle: the idea, explained as a stick figure animation.](https://www.youtube.com/embed/KMeBMjA--1M)

Feed the Gargoyle: the idea, explained as a stick figure animation.

1. You walk up. After about a second it notices you, and its eyes open.
2. It greets you. If it is sure about your costume, it teases the costume (never the person in it).
3. It picks its toll at random: a riddle to answer out loud, or a scream loud enough to light every plate on its spine.
4. The eight glowing plates on its spine count down while it waits, or fill up as you scream.
5. Right answer or big enough scream: green eyes, a puff of mist and one wrapped sweet down the tongue. Wrong answer: a cackle, a hint and one more go.
6. It says goodbye and goes back to sleep.

![One visit from sleep back to sleep. The times come straight from the game code.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-01-meet-the-gargoyle-1.2-one-visit.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=5ac8be6efd08fed69daf846d2f5261ce)

**See it play.** The right answer is at the top. Here are the other ways a visit can go, all on the finished statue:

[A wrong answer to the riddle gets a cackle and a hint.](https://www.youtube.com/embed/DpEMyR4kbdU)

A wrong answer to the riddle gets a cackle and a hint.

[The riddle timer runs out before anyone answers.](https://www.youtube.com/embed/Tovonox6Jp8)

The riddle timer runs out before anyone answers.

[Scream for candy: a scream loud enough to fill the spine wins a sweet.](https://www.youtube.com/embed/1b1tJlAf030)

Scream for candy: a scream loud enough to fill the spine wins a sweet.

[Failing the scream task: the scream is too quiet to fill the spine, so no sweet.](https://www.youtube.com/embed/oCOhtsfw_-A)

Failing the scream task: the scream is too quiet to fill the spine, so no sweet.

[Gargoyle demo: the cardboard prototype on the same UNO Q, before the stone body existed.](https://www.youtube.com/embed/rkadHnHlG5o)

Gargoyle demo: the cardboard prototype on the same UNO Q, before the stone body existed.

### In its own words

Every line is written ahead of time and rendered on the board in the gargoyle's own voice. A few favourites, straight from the voice bank:

| When | It says |
| - | - |
| You walk up | "Do not run, little one. I only bite sweets." |
| You came as a pirate | "Pirate on my doorstep! I accept only sweets as payment." |
| You came as Batman | "The Bat himself! I am impressed, and slightly worried." |
| You came as a skeleton | "Skeleton outfit! Careful, or you will rattle my jaw loose." |
| It wants a scream | "I feed on screams, and I am hungry. Scream as loud as you can to win a sweet. Scream now!" |
| Your scream was a whisper | "Much louder, please! My ears are made of rock." |
| You took too long | "Too late! Stone does not wait, only watches." |
| You got it right | "Right! I grumble, but I pay my debts. Take it." |
| You got it wrong twice | "No sweet for you tonight. The stone wins again." |
| The dispenser jams | "Hold on! A cobweb got in my jaw." |
| You leave | "Goodnight, and mind the cracks in the pavement." |

It only names a costume when the costume model is sure. Otherwise you get a general greeting. It teases the costume, never the person in it: the line filter throws out anything about face, body, age or size.

### What is new here

* **A four-model cascade on one board, fully offline.** A small visitor gate runs all the time. The costume, props and keyword models only wake when there is someone to look at or listen to. Only one heavy model runs at a time.
* **An LLM where it actually fits.** Gemma 3 1B runs on the UNO Q, but with camera and audio bricks busy it writes about 2.2 to 2.6 tokens per second (4 GB UNO Q, 3 threads, a 12 minute and a 30 minute run). A child will not wait 20 seconds for a reply. So the language model drafted lines while the board was idle, and Piper turned the checked lines into speech on the board ahead of time. During play it only picks a line.
* **A scream judged by loudness.** A calibrated loudness meter on the spine was fairer and easier to understand for a seven-year-old: fill the spine, win the sweet.
* **Two brains with a safety net.** The Linux side sends a heartbeat on every pass of its game loop, about ten times a second. If the microcontroller hears nothing for one second, it parks the servo, stops the mist, darkens the spine and holds the eyes at a still, dim glow by itself.
* **Every number measured on the board.** Every figure says which board, which settings and how it was measured. The raw logs are in the repo.

### Results at a glance

| What | Result | How it was measured |
| - | - | - |
| Notices a visitor | about 1.2 s | set in the code: a visitor score of 0.6 or more on 10 game loop passes in a row (each pass sleeps 0.1 s, plus its work), 4 GB UNO Q |
| False wake-ups | 60 down to 4 in 206 s, no visitor missed | public walk-up clips (ChokePoint and CAVIAR, 29 visits) replayed at 10 fps through the visitor model on my PC; single frames against a 1 s hold (the board now asks for about 1.2 s) |
| Hears the riddle answer | 34.5 ms per window, 93.15 % on 569 clips | test clips from speakers not in training, classified by the float32 .eim on the 4 GB UNO Q with no app running; median time per window |
| Confirms the sweet fell | 1.2 to 1.5 s after the command | IR sensor, real sketch, bench rig, 4 GB UNO Q |
| Fails safe | 1 s watchdog | heartbeat stopped for 1.5 s: the microcontroller reported its safe state over the Bridge, 4 GB UNO Q |
| Voice clarity | 18.7 % average word error, median 12.5 %; 58 of 179 lines word for word | the 179 bank lines on the board with known text, transcribed with Whisper base.en on my PC |
| Board headroom | 0 resets in 2 hours; 2.4 GB of 3.7 GB available (median), no swap; hottest zone peaked at 62.5 C | full app with real camera, mic and sound card, all four models, a sample every 5 s for 7,260 s, 4 GB UNO Q |

***

## How It Works

![How it all connects: sensors on the left, the models and game in the middle, the microcontroller and everything it drives on the right.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-01-meet-the-gargoyle-1.1-system-architecture.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=20723ad1484822a06b4f4be535cc2ff9)

**One board, two brains.** The Arduino UNO Q has a Linux computer (Qualcomm QRB2210) and a microcontroller (STM32U585) on the same board.

* **Linux side:** camera, microphones, the four models, the game and the voice.
* **Microcontroller:** the eye rings, the 24 spine LEDs, the candy servo, the IR drop sensor and the mist maker.

They talk over Arduino's Bridge. Linux sends "show the listening colours", "spine to 60 percent", "drop one sweet". The microcontroller answers "a sweet fell" or "nothing fell, it is jammed".

![Which model is awake at each moment of a visit. Only one heavy model runs at a time.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-05-get-the-models-5.1-model-cascade.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=f23ac44f5f9325906eeddef78ef42cf7)

**The models** (all trained in Edge Impulse, all float32 on the board):

| Model | Job | Result |
| - | - | - |
| Visitor gate | Is someone in front of me? | 91.8 % on 475 test images (Edge Impulse, float32) |
| Keyword spotter | Which of the six riddle answers was said? | 93.15 % on 569 test clips (530 right), the same score on the UNO Q as in Studio, 34.5 ms per window (median, 4 GB UNO Q, no app running) |
| Costume | Which costume is that? | 92.5 % on 186 test images (172 right, top answer, Edge Impulse, float32) |
| Props | No clear costume? Hat, glasses, crown, eye mask or scarf? | mAP\@50 0.82 on 1,153 test crops; 825 ms per check on the board (median of 10, app running) |

***

## Bill of Materials

![The main electronics before any wiring. Top row: servo, the two eye rings, sound card. Middle: mist maker, USB-C hub, UNO Q, drop sensor. Bottom: the two speakers (they go in the plinth) and the third eye camera.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-00-supplies-s.1-electronics.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=680268added7a80b853313c482ba1193)

### Hardware

| Part | Qty | Why this one |
| - | - | - |
| Arduino UNO Q, **4 GB** | 1 | The main board. Linux runs the camera, sound, four models and the voice; the microcontroller drives the LEDs, servo and mist. |
| USB-C hub with power-delivery (PD) pass-through | 1 | The UNO Q has one USB-C port, so power, camera and sound card share it. |
| USB-C PD charger, 45 W | 1 | A weak phone charger made my board restart in a loop. |
| Arducam B0490 USB camera (IMX462, M12 3.9 mm lens) | 1 | Good in low light; it becomes the third eye. |
| USB sound card with mic input and headphone output | 1 | One card: the mic goes in one port, the speakers in the other. |
| Boya BY-M1 lavalier microphone | 1 | Hears both the riddle answers and the scream. |
| Small speakers | 2 | In the plinth, behind small worn holes. |
| WS2812 round boards, 7 LEDs each | 2 | The eyes. |
| WS2812B strip, 5 V, 60 LEDs per metre | 24 pixels | Cut into single pixels for the spine, 8 plates of 3. |
| 1000 uF capacitor, 6.3 V or more | 1 | Across the LED supply. |
| 330 to 470 ohm resistor | 2 | One per LED data line. |
| SG90 micro servo, 180 degree | 1 (plus a spare) | Tips the candy pocket. |
| LM393 IR reflective sensor module (FC-51) | 1 | Confirms a sweet fell. |
| 5 V ultrasonic mist maker board, 20 mm disc | 1 | The breath. Plus a cotton wick, a small cup and a drip tray. |
| IRLZ44N MOSFET, 100 ohm and 10 k resistors | 1 each | Switches the mist from a 3.3 V pin. |
| 5 V 4 A supply | 1 | LEDs, servo and mist, separate from the board's charger. |
| Inline fuse holder, 2.5 A fast-blow fuse, small kill switch | 1 each | On the 5 V rail. |
| Grey PLA+ | 4 to 5 spools | Statue, wings and plinth. |
| Clear PLA+ | 1 spool | Eyes and spine plates. |
| M3 heat-set inserts and M3 x 16 screws | 4 each | Hold the statue on the plinth. |
| M3 x 10 screws | 3 | Dispenser. |
| 6 x 2 mm disc magnets | 8 | Refill lid. |
| Red, black and blue hookup wire, perfboard, heat-shrink | | Wiring. |
| CA glue, five-minute epoxy, putty, masking tape | | Assembly. |
| Grey epoxy primer, fine cement, waterproof PVA, matte clear sealer, acrylic paints | | The stone finish. |
| Individually wrapped soft toffees | | All one type of sweet, so the chute never jams on a big one. |
| Small cauldron-style bowl | 1 (optional) | Catches the sweets at the tip of the tongue. |

### Software and services

| Software | What it does here |
| - | - |
| [Edge Impulse Studio](https://studio.edgeimpulse.com) | Data, training, testing and the Linux (AARCH64) `.eim` builds for all four models. |
| [Arduino App Lab](https://docs.arduino.cc/software/app-lab/) | Runs the Python app and the sketch on the UNO Q, with the camera and microphone bricks. |
| [Piper TTS](https://github.com/rhasspy/piper), voice `en_GB-alan-medium` | Renders the gargoyle's lines on the board ahead of time. |
| [llama.cpp](https://github.com/ggml-org/llama.cpp) with Gemma 3 1B | Drafts the line bank on the board, before play only. |
| [YuNet](https://github.com/opencv/opencv_zoo) (OpenCV Zoo) | Finds the face that the props crop is cut around. |
| [KiCad](https://www.kicad.org) | The schematic. |

### Tools

3D printer with a 256 x 256 mm bed, soldering iron with an insert tip, multimeter, calipers, wire strippers, flush cutters, a long 2.5 mm ball-end hex key, hot glue gun, gloves, dust mask and safety glasses.

***

## Step 1: Set Up the UNO Q

Make sure the board works before any wiring. It is much easier to fix things now than inside a statue.

![The UNO Q pinout. Keep it open while wiring: the microcontroller pins are 3.3 V logic. Pinout: Arduino, docs.arduino.cc.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-02-say-hello-to-the-uno-q-2.0b-uno-q-pinout.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=990d6d1b486e4c0617fc3f99b06475b4)

The steps below follow Arduino's own pages. For more detail, see [Setup Arduino App Lab on Windows](https://docs.arduino.cc/software/app-lab/setup/windows/), [Connect, Configure, and Update boards](https://docs.arduino.cc/software/app-lab/configure/config/) and the [UNO Q user manual](https://docs.arduino.cc/tutorials/uno-q/user-manual/).

1. Download **Arduino App Lab** (Arduino's program for writing and running apps on the UNO Q) from the [Arduino software page](https://www.arduino.cc/en/software/) and install it. On Windows, pick **Windows (10/11), NSIS installer** (or **Windows 11 (ARM)** on an ARM laptop) and run the `.exe`.

![The App Lab download on the Arduino software page.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-02-say-hello-to-the-uno-q-2.1b-app-lab-download.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=0c1d26571f782fcd49b8af88dcb43e81)

2. Open App Lab. If Windows asks about `mdns-discovery.exe`, select **Allow**. App Lab needs it to find the board over Wi-Fi later.
3. Connect the UNO Q to your laptop with a USB-C data cable. Wait for the board to boot (up to 60 seconds), then select it in App Lab.
   * **You should see:** your UNO Q listed with a USB icon.

![App Lab finding the UNO Q as a new board.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-02-say-hello-to-the-uno-q-2.2-app-lab-finds-board.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=db2af2203e91116af53781378c2924a6)

4. Follow the setup wizard that opens for a new board:
   * **Board configuration:** pick your keyboard layout and give the board a name, for example `gargoyle`. On your network it becomes `gargoyle.local`.
   * **Network setup:** pick your Wi-Fi and enter its password. The board needs the internet for updates and Bricks.
   * **Linux password:** set a password for the `arduino` user. Write it down: SSH and file copies ask for it.
   * **Arduino account:** sign in, or skip and do it later from **Account**.
5. If App Lab shows **Updates available**, select **Install updates**. Keep the board plugged in until it finishes, then select **Restart App Lab** if asked.
6. Select **Inspirations** in the left sidebar, open **Blink LED from Python** and select **Run** (the play icon, top right).
   * **You should see:** the **Run** button turns into **Stop** and an LED on the board blinks.

![The example list in an earlier App Lab. In the current version the Blink LED example sits under Inspirations.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-02-say-hello-to-the-uno-q-2.3-app-lab-examples.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=b4f9a262992c44b60c8212a8777267c6)

7. Open **Settings**. Under **System info**, check that **Remote access (SSH)** is on (the wizard turns it on with Wi-Fi). Under **Network connections**, note the board's **IP**. Every command below uses it as `<board-ip>`; `<board-name>.local` works too.
8. On your computer, get the project files:

```
git clone https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle.git
cd Feed-the-Gargoyle
```

9. Copy the app to the board. It asks for the Linux password from item 4. App Lab keeps its apps in `/home/arduino/ArduinoApps/`, so it shows up under **Apps** as **Feed the Gargoyle**.

```
scp -r app arduino@<board-ip>:/home/arduino/ArduinoApps/gargoyle
```

More on SSH and copying files: [Connect to UNO Q via SSH](https://docs.arduino.cc/tutorials/uno-q/ssh/).

**Not working?**

| Problem | Fix |
| - | - |
| Board keeps restarting | The laptop port may not give enough power. Try another USB-C port, or power the board from the 45 W PD charger. |
| App Lab does not find the board | Try another USB-C cable. Some cables only charge and carry no data. |
| Board not found over Wi-Fi | Allow `mdns-discovery.exe` in Windows Firewall, and keep the laptop and board on the same network. |
| Update fails halfway | Leave it plugged in and run the update again. |

***

## Step 2: Find the Language Model's Limit (Optional)

The gargoyle does not need this at the door. Do it to see what a language model can and cannot do on a board this size, and why the voice is pre-rendered.

1. Open a terminal on the board: `ssh arduino@<board-ip>`
2. Install Gemma 3 1B with App Lab's own tool. It took about 2 minutes on my board and used about 690 MB of disk.

```
arduino-app-cli model install llamacpp:gemma-3-1b-it-Q4_0
```

3. On your computer, copy the test scripts to the board:

```
scp scripts/llm_bench.py scripts/line_bank.py scripts/gemma_jobs.py arduino@<board-ip>:~/
```

4. On the board, run the speed test at 3 threads. It starts llama.cpp with `-t 3 -c 2048 --cache-reuse 256` and asks for a short gargoyle line five times.

```
python3 llm_bench.py 3 bench-t3.jsonl --runs 5
```

* **You should see:** about 4.3 tokens per second. Mine gave 4.32 (median of 4 runs, 4 GB UNO Q, nothing else running).

5. Try prompt caching. This puts a fixed 168-token block of rules in front of the prompt and lets the server keep it.

```
python3 llm_bench.py 3 cache.jsonl --cache --prefix 8 --runs 6
```

* **You should see:** the first request is slow, then every later one reads the prompt in under a second.

![Prompt caching: the first request reads 168 tokens in 21.7 s, every later one reads 5 new tokens in 0.8 s.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-03-run-gemma-on-the-uno-q-3.3-prompt-cache.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=4c98d7a407b97d86139d5b01a93f232d)

6. Let it draft lines. The script checks each one: 14 words or fewer, ends with `.`, `!` or `?`, nothing about face, body, age or size, no riddle answers.

```
python3 line_bank.py drafts.jsonl --per 5
```

* **You should see:** roughly one draft in three or four passes. Read the passing ones too: some are good, many only look right.

![The line drafter's pass and fail marks. 17 of 51 passed on this run.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-03-run-gemma-on-the-uno-q-3.4-line-bank.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=df67c3e5380fc7bbc07f5c827d2e815f)

**What I found.** With the camera and audio models running, Gemma dropped to 2.58 tokens per second at 3 threads and 2.38 at 4, so a fourth thread bought nothing and 3 leaves a core free. A reply under that load took about 13 s. Most failed drafts broke character. So the lines in the bank are hand-written, with Gemma's drafts as a starting point, and every line passed the same checker.

**Not working?**

| Problem | Fix |
| - | - |
| `model install` fails | Check the board has internet and at least 1 GB free (`df -h`). |
| Server never answers | An old container holds the port. Run `docker ps`, then `docker rm -f gbench`. |
| Much slower than 4 tokens per second | Something else is running. Stop the app with `arduino-app-cli app stop`. |

> Aside: my favourite rejected line was "Stuck! Wait, a chilling request." I still do not know what it means, and neither does the gargoyle.

***

## Step 3: Give It a Voice

The gargoyle speaks from a bank of short lines, one list per situation: greetings, costume teases, riddles, hints, wins, too quiet, wrong answer, goodbye and a polite apology if the dispenser jams. A few of mine:

* "Who comes knocking at a hungry stone's door? Speak, sweet seeker."
* "Louder! A mouse sat in your voice and kept it tiny."

1. Install Piper on the board and download the **en\_GB-alan-medium** voice, following the Piper README (link in References).
2. Write your lines as a JSON file: each key is a situation, each value a list of lines. Keep every line to 14 words or fewer and never mention a face, body, age or size.
3. On your computer, set `GARGOYLE_SSH` to the helper that reaches your board (see the top of `scripts/gargoyle_speak.py`), then render:

```
python scripts/render_bank.py line-bank.json bank/
```

It speaks each line one sentence at a time, slightly slow (`--length_scale 1.1`), then adds the stone effect from `scripts/gargoyle_fx.py`: pitch down and a touch of echo. If it stops, run it again; it skips files it already made.

* **You should see:** a list of file names scroll past, about 8 seconds per line on my board.

![Rendering the greet and win lines with Piper on the board, 20 lines in 2 min 39 s.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-04-give-the-gargoyle-its-voice-4.2-piper-render.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=cb8ce6d4f085085ed838250951cb98dc)

4. Copy the rendered lines into the app on the board:

```
scp bank/*.wav arduino@<board-ip>:/home/arduino/ArduinoApps/gargoyle/python/bank/
```

* **You should see:** files named like `greet_0.wav` and `win_3.wav` in the bank folder.

![The rendered lines in the bank folder on the board.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-04-give-the-gargoyle-its-voice-4.3-bank-folder.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=c569f09100560875d5b28038d0caa9b8)

I checked the lines by transcribing them with Whisper (base.en, on my PC) and comparing the words with the written text. My board holds 191 rendered lines. On the 179 whose text I have, the average word error is 18.7 percent and the median 12.5 percent; 58 lines come back word for word. The worst are short lines with costume names: "Zombie costume!" came back as "So we cost you". A speech recogniser is a harsher listener than a person standing in front of the statue, but if a line of yours keeps failing, reword it and render it again.

**Not working?**

| Problem | Fix |
| - | - |
| Voice sounds rushed | Check `--length_scale 1.1` in `scripts/gargoyle_speak.py`. |
| A word comes out garbled | Reword the line. Piper struggles with rare names and stacked consonants. |
| Script cannot reach the board | Check `GARGOYLE_SSH` and that `ssh arduino@<board-ip>` works on its own. |

***

## Step 4: The Four Models at a Glance, and the Quick Route

Four small models do the seeing and hearing, and each one has its own beginner section after this step (Steps 5 to 8), all done in Edge Impulse Studio. If you just want the gargoyle working tonight, use the quick route below and come back to the training steps later.

| Model | Type | Input | Wakes when | Result |
| - | - | - | - | - |
| Visitor gate | Image classifier (MobileNetV2) | 160 x 160 camera frame | always on | 91.8 % on 475 audited test images |
| Keywords | Audio classifier | 1 s of sound, 16 kHz | a riddle is open | 93.15 % on 569 clips from new speakers |
| Costume | Image classifier (EfficientNet B2) | 224 x 224 body crop | a visitor is held | 92.5 % on 186 test photos |
| Props | Object detector (YOLO-Pro) | 224 x 224 head crop | costume model unsure | mAP\@50 0.82 on 1,153 crops |

Accuracy numbers are float32 in Studio on each project's fixed test set, top answer. Board timings are in each step.

Edge Impulse Studio is an online tool where you upload examples, train a model and download it for your board. My four projects there are public. Cloning copies the data, the settings and the trained model into your own account.

| Model | Public project | File name on the board |
| - | - | - |
| Visitor gate | [https://studio.edgeimpulse.com/public/1153004/live](https://studio.edgeimpulse.com/public/1153004/live) | `visitor.eim` |
| Keywords | [https://studio.edgeimpulse.com/public/1172323/live](https://studio.edgeimpulse.com/public/1172323/live) | `keywords.eim` |
| Costume | [https://studio.edgeimpulse.com/public/1172324/live](https://studio.edgeimpulse.com/public/1172324/live) | `costume.tflite` |
| Props | [https://studio.edgeimpulse.com/public/1160020/live](https://studio.edgeimpulse.com/public/1160020/live) | `props.eim` |

**For each project:**

1. Open the link and click **Clone this project** at the top right. Give it a name and wait a few minutes.
2. In your copy, open **Deployment** in the left menu.
3. Click the **Deployment target** box (it says **C++ library** at first), search for **Linux (AARCH64)** and select it.
4. Under **Model optimizations**, select **Unoptimized (float32)**. The page picks int8 by default.
5. Click **Build**. A `.eim` file downloads: the trained model packed as one file the UNO Q can run. Rename it to the name in the table.

![Deployment: Linux (AARCH64) with Unoptimized (float32) selected before Build.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.9-deployment-float32.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=264eb08b2c79e673f53ed38289efcf81)

**The costume model is different.** The app does not run it as a `.eim` file. It loads the bare model file with LiteRT (Google's small TensorFlow Lite runtime, which `requirements.txt` installs). So for the costume project, do item 1 (clone it), skip items 2 to 5, and do this instead:

1. In your copy of the costume project, click **Dashboard**, the first item in the left menu.
2. Scroll down the Dashboard page to the table called **Download block output**.
3. Find the row for the transfer learning block and click **TensorFlow Lite (float32)**. A file of about 31 MB downloads.
4. Rename it to `costume.tflite`.

**Why float32.** Every number in this guide comes from float32 builds on the UNO Q. The int8 props model scored 0.00 in Studio and was slower (Studio estimate 917 ms against 508 ms per frame).

**Install them on the board:**

6. Copy the visitor and keyword models to the folder the App Lab bricks read from (bricks are App Lab's ready-made blocks, here the camera and microphone classifiers):

```
scp visitor.eim keywords.eim arduino@<board-ip>:/home/arduino/.arduino-bricks/ei-models/
```

7. Copy the costume and props models next to the app:

```
scp costume.tflite props.eim arduino@<board-ip>:/home/arduino/ArduinoApps/gargoyle/python/models/
```

8. Make them runnable:

```
ssh arduino@<board-ip> "chmod +x /home/arduino/.arduino-bricks/ei-models/*.eim /home/arduino/ArduinoApps/gargoyle/python/models/*.eim"
```

* **You should see:** three `.eim` files, with `costume.tflite` and `yunet.onnx` next to `props.eim`. The props model uses YuNet to find the face it crops around.

![All four models in place on my board: visitor and keyword models in the bricks folder, costume.tflite and props.eim next to the app, plus the face finder.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-05-get-the-models-5.4-models-on-board.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=fcd01acae2648ff22ed1731474e14295)

**Not working?**

| Problem | Fix |
| - | - |
| A model will not load or scores 0.00 | You built int8. Rebuild with **Unoptimized (float32)** for **Linux (AARCH64)**. |
| Every props score is 0.00 in Studio | Model version is set to Quantized (int8). Switch to float32. |
| Visitor gate wakes for posters or TVs | Add posters, screens and statues to `empty` and retrain. |
| Props found in Studio but not at the door | Check `yunet.onnx` sits next to `props.eim`. The crop must match training. |

***

## Step 5: Train the Visitor Gate in Edge Impulse Studio

This model answers one question all night: is someone standing in front of me? Everything else waits for it.

**Shortcut:** my finished project is public at [https://studio.edgeimpulse.com/public/1153004/live](https://studio.edgeimpulse.com/public/1153004/live). Open it and click **Clone this project** to get my data and settings in your own account, then jump to item 14.

**Get the images ready**

1. Make two folders, `visitor` and `empty`.
   * **visitor:** an adult whose body fills at least 40 percent of the picture's height.
   * **empty:** everything else. Rooms, doors, pets, people far away, hands or feet at the edge, and the tricky ones: statues, posters, mirrors and TVs with people on them.
2. Keep a separate test set in its own two folders, taken from a different part of the dataset. I used the COCO public photo dataset: training from its train set, testing from its val set.

**Create the project**

3. In Edge Impulse Studio, click **Create new project**.
4. Type `gargoyle-visitor`, choose **Personal** and **Public**, and click **Create new project**.

![Creating the gargoyle-visitor project.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.1-create-project.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=81f890f807c0df5f29bad8e681099222)

**Upload the data**

5. Open **Data acquisition** and click the upload icon.
6. Upload the training `visitor` folder with **Enter label** set to `visitor` and **Training** selected. Do the same for `empty`.
7. Upload the two test folders the same way with **Testing** selected. Do not use the automatic split, or your separate test set is lost.
   * **You should see:** both labels in the list. Mine has 6,988 images: 6,500 training and 488 testing. 13 of the test images are disabled after I checked their labels, so 475 get scored.

![Data acquisition: 6,988 images in two labels, visitor and empty.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.2-data-acquisition.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=378addf2de8fb5bbfd96e888d77e3a87)

**Design the impulse**

8. Open **Create impulse**. Set **Image width** and **Image height** to `160` and **Resize mode** to `Squash`.
9. Click **Add a processing block** and choose **Image**.
10. Click **Add a learning block** and choose **Transfer Learning (Images)**. Name it `Visitor presence`.
11. Click **Save Impulse**.
    * **You should see:** Output features `2 (empty, visitor)`.

![The impulse: 160 x 160, Squash, an Image block and a Transfer Learning block called Visitor presence.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.3-create-impulse.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=12002c27697c6e8b54e523e5a495014f)

**Make the features**

12. Open **Image**. Set **Color depth** to `RGB` and click **Save parameters**.

![The Image block set to RGB.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.4-image-parameters.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=575ae10156b9d6e33ce2b25dd731760d)

13. Open the **Generate features** tab and click **Generate features**. Wait for it to finish.
    * **You should see:** a cloud of blue and orange dots in the **Feature explorer**. They overlap a lot. That is normal here; the network sorts them out.

![The feature explorer after Generate features. The two groups overlap, which is normal.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.5-generate-features.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=82bc9f595598b23deb96bcc7986c6dae)

**Train it**

14. Open **Visitor presence**.
15. Set **Number of training cycles** to `12`, **Learning rate** to `0.0005`, **Training processor** to `CPU`. Tick **Data augmentation** and leave **Use learned optimizer** unticked.
16. Click **Choose a different model** and pick **MobileNetV2 160x160 0.5**. Set the final layer to `16` neurons and dropout to `0.1`.

![Visitor presence: MobileNetV2 160x160 0.5, 16 neurons, dropout 0.1, 12 cycles, learning rate 0.0005.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.6-visitor-presence-settings.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=213f3699a3f8f5c8841aa24f312a56d3)

17. Click **Save & train**. You can close the tab and come back.
    * **You should see:** about 90 percent on the validation set, with most of the confusion matrix on the diagonal. Mine showed 89.5 percent in the int8 view.

![The training result on the validation set.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.7-training-result.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=7a4bebd069e9ef5861b0dfa79136c399)

Transfer learning starts from a model that has already seen millions of photos and teaches it only your two labels, so it needs far fewer images than starting from zero. Data augmentation flips, crops and brightens the pictures a little so the model sees more variety.

**Test it**

18. Open **Model testing**, set **Model version** to **Unoptimized (float32)** and click **Classify all**.
    * **You should see:** about 90 percent. Mine scored **91.79 percent** on the 475 test images, float32, in Studio: 93.9 percent of visitors caught, and 11.2 percent of empty scenes wrongly called visitor. The one-second rule below calms those false alarms down.

![Model testing on the 475 held-out images, float32: 91.79 percent.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.9-model-testing.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=2f289c644931f5e47e43a75115fad92a)

**Build it**

19. Open **Deployment** and pick **Linux (AARCH64)**.
20. Under **Model optimizations**, select **Unoptimized (float32)** and click **Build**.
    * **You should see:** Studio's estimate for the UNO Q: 17 ms, 1.6M RAM, 91.79 percent for float32. The int8 build is smaller but slower here (41 ms) and less accurate (88.63 percent), so float32 it is.

![Deployment: Linux (AARCH64) with Unoptimized (float32) selected. Studio estimates 17 ms on the UNO Q.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-06-train-the-visitor-gate-6.8-deployment.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=1227e177cc68bb09d3f5a4856966b52d)

21. Rename it `visitor.eim` and install it as in Step 4, items 6 to 8.

**Make it calm at a real door.** One frame on its own is jumpy. I replayed door-camera video at 10 frames per second through the model on my PC: a visitor score above 0.5 on a single frame woke the gargoyle 60 times in 206 seconds. Asking for a score above 0.5 on every frame for one full second (10 frames) cut that to 4, missed no visitors, and adds only about a third of a second. That one-second rule is already in `app/python/sensors.py`. (A replay of recorded video, not a measurement on the board.)

**What I tried first**

* **FOMO object detection** (boxes around people) underfit on my data. The game only needs a yes or a no, so a plain classifier won.
* **Cleaning the labels mattered more than any setting.** My audit found 15 percent of the test visitor labels wrong. Adding the pictures the model got wrong, checked by eye, took it from 90.3 to 91.8 percent.
* **Bigger was not better.** 25 cycles gave no gain, and the full-width MobileNetV2 scored lower (88.6 percent).

**Not working?**

* **Score stuck around 70 to 80 percent**: Look at the wrong ones in **Model testing**. Usually they are mislabelled. Fix the label, do not delete the hard ones.
* **Wakes up for posters or TVs**: Add more posters, screens and statues to `empty`, then retrain.
* **Training job is refused as too long**: Lower the training cycles. Personal projects have a 60 minute job limit.
* **Model will not load or is slow**: Check you built **Unoptimized (float32)** for **Linux (AARCH64)**.

***

## Step 6: Train the Riddle Keyword Spotter in Edge Impulse Studio

The gargoyle listens for six riddle answers: **shadow, pumpkin, mirror, candle, spider, scarecrow**. This step teaches a small model to hear them, all done in Edge Impulse Studio.

**Shortcut:** my public project [https://studio.edgeimpulse.com/public/1172323/live](https://studio.edgeimpulse.com/public/1172323/live) holds the trained model the gargoyle runs. Clone it and deploy it as in Step 4 if you only want it working.

**Get the clips ready**

1. Make one folder per label: `shadow`, `pumpkin`, `mirror`, `candle`, `spider`, `scarecrow`, plus `unknown` (other words, especially close ones like "handle" or "narrow") and `noise` (room sounds, music, crowds, no speech).
2. Each clip is one second long, 16 kHz, with the word somewhere in the middle. I cut mine from public speech datasets (Multilingual Spoken Words, Speech Commands, LibriSpeech) and added Piper synthetic voices for the rare words.
3. Keep a separate set of test clips from **different speakers** than the training clips. If one voice is in both, the test score is too kind.

**Create the project**

4. In Edge Impulse Studio, click **Create new project**.
5. Type the name `gargoyle-keywords`, choose **Personal**, and click **Create new project**.

![Creating the keywords project.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-7.1-create-project.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=b590d41cca628302117877052c540853)

**Upload the data**

6. Open **Data acquisition** and click the upload icon.
7. Upload each training folder with **Enter label** set to the folder name and **Training** selected.
8. Upload your test clips with **Testing** selected. Do not use the automatic split, or your speaker split is lost.
   * **You should see:** your clips listed with their labels. Mine had 16,522 training and 776 test clips. Studio shows a red warning for a 96 / 4 split. That is fine here: the test set is kept small and fixed on purpose.

**Optional, but it helps: record with the gargoyle's own microphone.** Plug the Boya BY-M1 into your computer, the same mic that goes in the statue. Studio can record clips from your computer's microphone, so in your browser pick the Boya as the microphone before you record. Record a few clips of each word in the room where the gargoyle will stand. Clips from the real mic in the real room teach the model how your setup actually sounds.

* On **Data acquisition**, click **Connect a device** and choose your computer. When the browser asks for the microphone, allow it and pick the Boya.
* In **Collect data**, set **Label** to the word you will say, **Sample length** to `1000` ms and the frequency to `16000` Hz.
* Click **Start sampling** and say the word once, clearly, in the middle of the second. Do 20 to 30 per word, at different distances and loudness.
* Record some clips of just your room with the label `noise`.
* Keep these clips in **Training**. The test set stays the clips from other speakers, so the score still tells you how well it hears strangers.

![Data acquisition with the eight labels.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-7.2-data-acquisition.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=5f6360eb66c008cf36ba22cd2728b376)

**Design the impulse**

9. Open **Create impulse**. Set **Window size** to `1000 ms`, **Window increase** to `500 ms`, **Frequency** to `16000` and tick **Zero-pad data**.
10. Click **Add a processing block** and choose **Audio (MFE)**.
11. Click **Add a learning block** and choose **Transfer Learning (Keyword Spotting)**.
12. Click **Save Impulse**.
    * **You should see:** 8 output features: candle, mirror, noise, pumpkin, scarecrow, shadow, spider, unknown.

![The impulse: 1000 ms window, 500 ms increase, 16000 Hz, zero-pad ticked, Audio (MFE) and Transfer Learning (Keyword Spotting).](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-1-create-impulse.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=0160ec105f602d154a79702e00d62fa2)

MFE turns sound into a small picture of which pitches are loud over time, close to how our ears hear. The keyword transfer block starts from a network that has already heard a lot of speech, so it needs far fewer clips than starting from zero.

**Make the features**

13. Open **MFE** and leave every setting at its default: **Frame length** `0.02`, **Frame stride** `0.01`, **Filter number** `40`, **FFT length** `256`. Click **Save parameters**. The keyword transfer block only accepts these defaults; when I tried longer frames or 32 filters, training was refused.

![The MFE block left at its defaults: frame length 0.02, stride 0.01, 40 filters, FFT 256.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-2-mfe-parameters.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=654d18378efa954ea5a42062cc0f7265)

14. Open the **Generate features** tab and click **Generate features**. Wait for it to finish.
    * **You should see:** a cloud of coloured dots in the **Feature explorer**. The words overlap a lot. That is normal for speech; the network sorts them out.

![Generate features: 16,522 training windows in 8 classes.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-3-generate-features.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=92a9039e60d0dad2fecffe5104abbdba)

**Train it**

15. Open **Transfer learning**. Click **Choose a different model** and pick **MobileNetV2 0.35**.
16. Fill in the settings:
    * **Number of training cycles:** `90`
    * **Learning rate:** `0.001`
    * **Training processor:** `GPU`
    * **Final layer:** `128` neurons, **dropout** `0.1`
    * **Data augmentation:** off. With the keyword transfer block, Studio's audio augmentation stopped my job with a Python error, so leave it off.
17. Open **Advanced training settings**: **Batch size** `64`, and tick **Auto-weight classes** so the big `unknown` group does not drown out the rare words.
18. Click **Save & train**. You can close the tab and come back.
    * **You should see:** about 95 percent on the validation set. Mine showed 94.8 percent. Retraining gave the identical score, so Studio's training is repeatable.

![Training: MobileNetV2 0.35, 128 neurons, 0.1 dropout, 90 cycles, learning rate 0.001, GPU. 94.8 percent on the validation set.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-4-training.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=3d616de340b845b959d3538de455f731)

**Test it**

19. Open **Model testing**, set **Model version** to **Unoptimized (float32)** and click **Classify all**.
    * **You should see:** a confusion matrix with an extra **Uncertain** column. Studio files any clip whose top score is below its threshold there and counts it as wrong, so the percentage on screen is lower than the real one.
    * **The fair number:** counting only the 569 clips from new speakers and taking the top score, this Studio-only model got **530 of 569 (93.15 percent)**, and the float32 .eim on the UNO Q gave the same 530, at 34.5 ms per window (median, no app running). The main error is `candle` heard as `unknown` (12 clips).

![Model testing in float32. The percentage on screen counts the Uncertain column as wrong.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-5-model-testing.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=0c61e21c7c7e9a606fa5524d3a65d440)

20. Open **Deployment**. Click the **Deployment target** box (it says **C++ library** at first), search for **Linux (AARCH64)** and select it.
21. Under **Model optimizations**, click **Select** next to **Unoptimized (float32)**, then click **Build**. Rename the file `keywords.eim` and install it as in Step 4, items 6 to 8.

![Deployment: Linux (AARCH64) with Unoptimized (float32) selected. Studio estimates 4 ms and 155.8K RAM for the network on the UNO Q.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-07-train-the-riddle-keyword-spotter-studio-6-deployment.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=5bc1aa6abb373810f765f7694c29a2d4)

**From model to game rule.** One window on its own can be fooled by a word that sounds close. In the game a keyword counts when one window scores above 0.5, and the gargoyle only listens while a riddle is open (and skips its first second, which still holds its own voice), so a stray word outside that time does nothing. I joined all 569 test clips into one 569 s recording, back to back in a random order, and played it through `keywords.eim` on the UNO Q with a 1 s window every 100 ms (4 GB board, app running). Single windows caught 299 of 306 answers (97.7 percent) with 96 false alarms in those 569 s of nonstop speech. Asking for 3 of 4 windows in a row caught 292 (95.4 percent) with 13 false alarms. The app uses single windows, since the gargoyle only listens while a riddle is open and a missed answer hurts more than a rare stray one.

**What I tried**

* **Clean test data first.** My October dataset had the same speakers in training and testing and scored 80.2 percent. With a proper speaker split the same kind of model scored 74.2 percent (422 of 569 new test clips), the honest number.
* **Longer training is not better.** The plain Studio classifier block at 200 cycles stayed at 85.8 percent (488 of 569). The keyword transfer block was the jump.
* **Other transfer models.** MobileNetV1 reached 82.8 percent on validation and Tiny Conv2D 84.4 percent on the test clips. MobileNetV2 0.35 won.
* **The EON Tuner** (Studio's automatic search) scored 65 to 76 percent on its first five trials.
* **More voices fixed "candle",** the hardest word in every run.

**Not working?**

* **Good in Studio, poor in the room**: Your clips are too loud or too clean. Match the levels to your board's microphone and mix in real room noise.
* **One word keeps winning**: It has far more clips than the rest. Balance the folders, or tick **Auto-weight classes**.
* **Training refused with a frame or filter error**: Put the MFE block back to its defaults (item 13).
* **Training stops with a Python error**: Turn data augmentation off (item 16).
* **Training job refused as too long**: Lower the training cycles. Free projects have a time limit per job.
* **Model will not load**: You built the int8 version. Rebuild with **Unoptimized (float32)**.

***

## Step 7: Train the Costume Model in Edge Impulse Studio

This is the bit that makes people laugh: the gargoyle noticing you came as a pirate. It is also the easiest one to get wrong, so there is one firm rule: **it only comments when it is confident. Otherwise it says something playful that claims nothing.** And it only ever talks about the costume, never about anyone's face or body.

**Shortcut:** my project is public at [https://studio.edgeimpulse.com/public/1172324/live](https://studio.edgeimpulse.com/public/1172324/live). Click **Clone this project** to get my photos, impulse and trained model, then jump to item 22.

**Get the images ready**

1. Make one folder per class. Mine are `batman`, `captain_america`, `iron_man`, `spiderman`, `superman`, `wonder_woman`, `pirate`, `princess`, `skeleton`, `witch`, `zombie` and `empty` (ordinary clothes or nobody). Each label is also the name of its line group in the voice bank, so if you add or rename a class, add lines with the same name.
2. Use photos of people in costume. I used public web photos (Wikimedia Commons, Flickr, Openverse) and cropped each person out.
3. Look at every photo yourself. Remove statues, figurines, shop mannequins, drawings, headless shop dresses and repeats.
4. Split off a test set and keep it fixed. Photos from the same photographer or party go all in training or all in testing. I split by a hash of the source, so the split never changes between runs.

**Create the project**

5. In Edge Impulse Studio, click **Create new project**.
6. Type `gargoyle-costume`, choose the project type and **Public**, and click **Create new project**.

![Creating the project. Any project type works for the data; training time is the catch, see item 16.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.1-create-project.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=4e72669adca73cc4e88215cce5a2e606)

**Upload the data**

7. Open **Data acquisition** and click the upload icon.
8. Upload each training folder with **Enter label** set to the folder name and **Training** selected.
9. Upload the test folders the same way with **Testing** selected. Do not use the automatic split, or your fixed test set is lost.
   * **You should see:** 970 items, split 81 % / 19 %: 784 training and 186 testing, in 12 labels.

![Data acquisition: 970 photos, 784 for training and 186 for testing, 12 labels.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.2-data-acquisition.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=86829bc1d7034b7f8c94d64f049f5b59)

**Design the impulse**

10. Open **Create impulse**. Set **Image width** and **Image height** to `224` and **Resize mode** to `Squash`.
11. Click **Add a processing block** and choose **Image**.
12. Click **Add a learning block** and choose **Transfer Learning (Images)**. Name it `costume`.
13. Click **Save Impulse**.
    * **You should see:** 12 output features, one per class.

![The impulse: 224 x 224 images, Squash, an Image block and a Transfer learning block called costume with 12 outputs.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.3-create-impulse.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=50e100442c014d2279c432a8e02f8336)

**Make the features**

14. Open **Image**, set **Color depth** to `RGB` and click **Save parameters**. Then open the **Generate features** tab and click **Generate features**. Wait for it to finish.
    * **You should see:** the **Feature explorer** with 12 coloured groups that overlap a lot. That is normal; the network sorts them out.

![The Image block set to RGB.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.4-image-parameters.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=d4be864b6969ec64675be6faa00f137f)

![Generate features: 784 training photos in 12 classes. The groups overlap a lot, which is normal for costumes.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.5-generate-features.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=5e3859d1b2cd4257fd5287717f394310)

**Train it**

15. Open **costume**. Under **Neural network architecture**, click **Choose a different model** and pick **EfficientNet**.
16. Fill in the training settings exactly like this:
    * **Training processor:** `GPU`. On a free personal project, jobs run on CPU with a 60 minute limit, and this recipe does not fit in it. Clone my project instead, or see "What I tried" for a smaller setting that does fit.
    * **Number of training cycles:** `40`
    * **Learning rate:** `0.0005`
    * **Model size:** `B2 - 7.7M params, 30.8 MB`
    * **Use pretrained weights:** ticked
    * **Freeze % of layers:** `70`
    * **Last layers:** `dropout: 0.3`
    * **Data augmentation:** `flip, crop, brightness`

![The costume block: EfficientNet B2, pretrained, 70 percent of layers frozen, 40 cycles, learning rate 0.0005, flip, crop and brightness augmentation.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.6-train-costume.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=3ba58264c1a29e5e234ff15411198dde)

17. Open **Advanced training settings** and set **Validation set size** to `15` percent, **Batch size** to `16`, and turn on **early stopping** with patience `6` and minimum change `0.001`.
18. Click **Save & train**. You can close the tab and come back.
    * **You should see:** **Accuracy 90.7 %** and **loss 0.28** on the validation set, float32. The validation set is only 15 percent of the training photos, so do not trust this number on its own; the test set in the next item is the real check.

![The training result: 90.7 percent on the validation set.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.7-training-result.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=b45ddb4804ab7c3666bae186c9f4fc52)

**Test it**

19. Open **Model testing**, set **Model version** to **Unoptimized (float32)** and click **Classify all**.
    * **You should see:** **88.17 %** with an **UNCERTAIN** column. Studio counts any answer under its confidence threshold as uncertain, not as right. Counting the top answer instead, my final model gets **92.5 percent (172 of 186 test photos)**, float32, in Studio.

![Model testing on the 186 held-out photos, float32: 88.17 percent in Studio's count, with low scores put in the UNCERTAIN column.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.8-model-testing.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=cb690941b0298db597034e2d2a28d72b)

20. Look at the weakest classes in the confusion matrix. On mine: skeleton 7 of 10 (two called pirate), witch 12 of 15, zombie 4 of 5. The rest miss one photo or none.
21. Check the int8 version too, if you are curious. On the validation set it scored the same as float32 here, but on this board float32 is faster (next item), so there is no reason to use int8.

**Build it**

22. Open **Deployment** and pick **Linux (AARCH64)**.
23. Under **Model optimizations**, look at Studio's estimate for the UNO Q.
    * **You should see:** float32 337 ms per picture, int8 537 ms and 86.02 percent. Faster and more accurate, so float32 it is.

![Deployment: Linux (AARCH64), Unoptimized (float32) selected. Studio estimates 337 ms per picture for float32 and 537 ms for int8 on the UNO Q.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-08-train-the-costume-model-8.9-deployment.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=bdf684cbf8c63d1ec91b2205d77b95db)

24. In the left menu of this Edge Impulse Studio project, click **Dashboard** (the first item) and scroll down to the **Download block output** table. There, download the **TensorFlow Lite (float32)** file of the transfer learning block (about 31 MB). Rename it `costume.tflite` and copy it as in Step 4, item 7. The app runs it with LiteRT, which `requirements.txt` installs.
    * **On the board:** 172 of 186 test photos, the same as Studio, and a median 362 ms per picture with the whole app running (2 threads, 4 GB UNO Q). The costume check runs once a second, so that fits.

**How the game uses it.** The costume model looks at most once a second, only while someone is there, on a picture borrowed from the camera model. The app cuts a body-sized box around the largest face first, because the model learned from photos of one person, not a whole doorway. Pictures stay in memory and are never saved. A costume line plays only if the score is 0.6 or more. Below that, the props model gets a turn (Step 8), and if that is unsure too, the gargoyle teases in general terms.

**What I tried**

All scores are the top answer on the same 186 test photos, float32, in Studio.

* **Standard MobileNetV2 160x160 1.0**: about 76 percent
* **EfficientNetV2B0 in expert mode (my own training script), 224 px**: about 167 of 186
* **Studio EfficientNet block B0, 90 percent frozen, 15 cycles, CPU (fits a free project)**: 163 of 186 (87.6 percent)
* **EfficientNet B0, 70 percent frozen, 40 cycles, GPU**: 169 of 186
* **Same with B1**: 172 of 186
* **Same with B2**: 174 of 186
* **B2 again, same settings, retrained**: **172 of 186 (final, the one in the screenshots)**
* **YOLO-Pro costume detector, four sizes**: best 157 of 186

Retraining the same B2 setup moved the score by up to 3 photos, so 172 and 174 are the same model as far as I can tell. The final one is done entirely in Edge Impulse Studio: every setting is a Studio field. More pirate, witch and princess photos fixed a few of those classes and broke a few others, so the photo count stayed at 970.

**Not working?**

* **Score stuck in the 70s**: Check the model is EfficientNet, not the default MobileNet, and that pretrained weights are ticked.
* **Training job stops at 60 minutes**: Your project has the free job limit. Use B0, 90 percent frozen, 15 cycles, or clone my trained project.
* **One costume is always wrong**: It needs more and more varied photos. Check its wrong ones by eye; they are often mislabelled.
* **Model testing looks much lower than validation**: Look at the UNCERTAIN column first, then count the top answers (item 19).
* **int8 build is slower than float32**: That is expected on this board. Use float32.

> Aside: Spider-Man was the easiest costume to learn. Nobody half-commits to a Spider-Man costume.

*So now a Batman walks up. The gargoyle spots the cape and opens with "Batman spotted! Gotham's riddles are easy, try mine." He shouts the wrong answer, and a lump of painted plastic cackles at the World's Greatest Detective and keeps the sweet.*

***

## Step 8: Train the Props Model in Edge Impulse Studio

Lots of people come in half a costume: a hat, a crown, a pair of silly glasses. When the costume model is not sure, this second model looks for something worn, so the gargoyle still has something to say.

It is an object detector, so it draws a box around each prop it finds. Five classes: `crown`, `eye_mask`, `glasses`, `hat` and `scarf`. There is no `none` class: no box means no prop.

**Shortcut:** my project is public at [https://studio.edgeimpulse.com/public/1160020/live](https://studio.edgeimpulse.com/public/1160020/live). Click **Clone this project** to get my crops, boxes, impulse and trained model, then jump to item 23.

**Get the images ready**

1. Collect photos of people wearing each prop. I used Open Images, Fashionpedia and Openverse (the last one for more crowns and eye masks).
2. Find the largest face in each photo with YuNet, the face finder from Step 4, and cut a square around it: 3.2 face heights wide, face centre 42 percent of the way down. The app cuts exactly the same crop on the board, so keep these numbers.
3. Draw a box around every prop in every crop. I started from the dataset boxes and from boxes suggested by an open-vocabulary detector (OWLv2), then checked every crop by eye and fixed or removed boxes.
4. Look at every crop. Remove dolls, statues, cartoons, props held in a hand or on a stand, and crops too small or dark to judge.
5. Split by photographer, so nobody's photos land in both training and test. Otherwise the test score flatters the model. Put the training crops in one folder and the test crops in another, each with its boxes in a `bounding_boxes.labels` file (Edge Impulse's box format) next to the images.

**Create the project**

6. In Edge Impulse Studio, click **Create new project**.
7. Type `gargoyle-props`, choose the project type and **Public**, and click **Create new project**.

![A new project called gargoyle-props. A Personal project is fine for the data; training needs a GPU, see item 18.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.1-new-project.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=beb8501d74fbf35a37027006cc130a0d)

**Upload the data**

8. Open **Data acquisition** and click the upload icon.
9. Select every file in the training folder, including `bounding_boxes.labels`, choose **Training** and click **Upload data**. Studio reads the boxes from the labels file. (I sent mine with a small upload script; the Studio uploader takes the same file.)
10. Upload the test folder the same way with **Testing** selected. Do not use the automatic split, or your fixed test set is lost.
    * **You should see:** 6,648 items, split 82 % / 18 %: 5,495 training and 1,153 test. Click any crop and its box shows on the right.

![Data acquisition: 6,648 head crops, split 82/18. Each prop has a box drawn around it.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.2-data-acquisition.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=d533037cd259df8f74be93997777440c)

**Design the impulse**

11. Open **Create impulse**. Set **Image width** and **Image height** to `224` and **Resize mode** to `Squash`.
12. Click **Add a processing block** and choose **Image**.
13. Click **Add a learning block** and choose **Object Detection (Images)**.
14. Click **Save Impulse**.
    * **You should see:** 5 output features: crown, eye\_mask, glasses, hat, scarf.

![The impulse: 224 x 224, Squash, an Image block and an Object Detection block with the five props.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.3-create-impulse.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=8fda275a16984196772d34c8ace1cf04)

**Make the features**

15. Open **Image**, set **Color depth** to `RGB` and click **Save parameters**.

![The Image block on RGB.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.4-image-block.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=bda4d2fd45a1078a1ee8c3e3c09d8560)

16. Open the **Generate features** tab and click **Generate features**. Wait for it to finish.
    * **You should see:** the **Feature explorer** with five colours mixed together. That is normal for raw pixels; the detector sorts them out.

![Feature explorer after Generate features. The props overlap a lot here, which is normal for raw pixels.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.5-feature-explorer.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=8699cdc643c90d07d2d6a4aea5742013)

**Train it**

17. Open **Object detection**. Under **Neural network architecture**, click **Choose a different model** and pick **YOLO-Pro**.
18. Fill in the training settings exactly like this:
    * **Training processor:** `GPU`. YOLO-Pro only trains on a GPU.
    * **Number of training cycles:** `100`
    * **Learning rate:** `0.001`
    * **Model size:** `small (6.9M)`
    * **Use pretrained weights:** ticked
19. Open **Advanced training settings** and set **Batch size** to `32`, spatial and colour augmentation to `medium`, and early stopping from epoch `50`.
20. Click **Save & train**. You can close the tab and come back.
    * **You should see:** the result card opens on **Quantized (int8)** and shows **0.00**. That is not a failed run: this model does not survive int8 (more below). Set **Model version** to **Unoptimized (float32)** to see the real score.

![YOLO-Pro small, 100 cycles, learning rate 0.001, on GPU. The 0.00 is the int8 view, which this model does not survive.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.6-object-detection-settings.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=15d6a9d79616e8e2d3436abf91171bf2)

When I tried YOLO-Pro on a free personal project, the job stopped with a GPU-only error. If that happens to you, clone my public project (the shortcut above) and carry on from item 23.

**Test it**

21. Open **Model testing**, set **Model version** to **Unoptimized (float32)** and click **Classify all**.
    * **You should see:** mAP\@50 around 0.8. Mine scored **0.82** on the 1,153 held-out crops. Red rows are crops where a box was missed or landed on the wrong prop.

![Model testing on the 1,153 held-out crops, float32: mAP@50 0.82.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.7-model-testing.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=9de513e2589c03c35ac9a884e4252983)

22. Scroll down to the metrics. mAP\@50 is the one to watch: it counts a box as found when it overlaps the real prop by at least half.

![The test metrics: mAP@50 0.82.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.8-test-metrics.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=16575232862dcf25785b8c024fc0dbe7)

**Build it**

23. Open **Deployment** and pick **Linux (AARCH64)**.
24. Under **Model optimizations**, click **Select** under **Unoptimized (float32)**, then click **Build**. The page selects int8 by default, so check this every time.
    * **You should see:** Studio's estimate for the UNO Q: float32 508 ms per frame, int8 917 ms.

![Deployment: Linux (AARCH64). Click Unoptimized (float32) before Build. The page selects int8 by default.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-09-train-the-props-model-9.9-deployment-float32.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=264eb08b2c79e673f53ed38289efcf81)

25. Rename it `props.eim` and install it as in Step 4, items 6 to 8.

**Use float32, not int8.** In Studio the int8 version scores 0.00 on validation for this model, so quantising breaks it. It is not even faster: Studio estimates 917 ms per frame on the UNO Q for int8 against 508 ms for float32.

On the board, one full props check (YuNet finding the face, cutting the crop, then the detector) takes **825 ms** (median of 10 runs on one test frame, 4 GB UNO Q, with the gargoyle app running). The app checks about once a second while someone is there, on its own thread, so the game never waits for it.

**My own score, per prop.** mAP is hard to feel, so I also scored each prop the way the game uses it: a found prop counts if its box lands on the right item. Picking a threshold per prop on the validation crops, the held-out F1 scores were hat 0.889, glasses 0.871, eye mask 0.863, scarf 0.848 and crown 0.769 (mean 0.848). Crown is the weak one: when it says crown it is right 94 percent of the time, but it misses about a third of them. A miss just means the gargoyle says something general. A wrong guess costs a laugh, not a sweet.

**What I tried**

* **A classifier first.** Five classes with `none`, MobileNetV2 at 160 x 160: 69.0 percent on 287 test images. Scarf and `none` were mostly guesses, so I switched to boxes.
* **FOMO.** Edge Impulse's tiny detector. The best reached a mean F1 of 0.70 on my test set.
* **Bigger input.** At 320 x 320 the same YOLO-Pro scored 0.864, a tie with 224 x 224, at twice the time: Studio estimated 1056 ms against 508 ms per frame. Every run from here on landed between 0.840 and 0.864, so more data, not a bigger model, is the next step.
* **Smoothing.** A prop stays on for 5 checks (about 4 s) after it was last seen. On my test sequences this cut false alarms in half (3.14 to 1.57 a minute) and stopped the label flickering, with no added delay.

**Not working?**

* **Every score is 0.00**: Model version is set to Quantized (int8). Switch to Unoptimized (float32).
* **Training will not start**: Training processor must be GPU for YOLO-Pro.
* **Props are found in Studio but not at the door**: The crop on the board must match the training crop. Check that `yunet.onnx` sits next to `props.eim` in `app/python/models/`.
* **Crowns are missed**: Add more crowns, worn on the head, in many styles. It needs more examples than hats.

***

## Step 9: Look Inside the 3D Model

Every part is in the repo under `hardware/print/`, ready to print, with `PRINT_PLAN.md` and `ASSEMBLY.md` next to them. This step shows what is inside, so the next steps make sense.

![Stone made see-through: the blue dispenser sits inside the head, under the spine.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-10-take-a-tour-of-the-3d-10.4-see-through.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=d0455af0f3126d1272ebeba29c3e03f4)

* **Size.** The finished statue, plinth included, is about 650 mm tall, 590 mm long (front to back) and 560 mm wide (wing tip to wing tip), measured on the final 3D model. That is the smallest size that fits the dispenser under the spine.
* **Eyes.** Only the visible front of each eye is clear: a thin dome with a dark slit printed through it. The lids around it are thick grey, so only the iris glows.
* **Third eye.** The camera hides in the middle of the forehead spiral. Its 13.9 mm lens slides into a 14.2 mm hole and holds the camera by itself.

![The third eye: the camera hole in the middle of the forehead spiral.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-10-take-a-tour-of-the-3d-10.8-face-camera-bore.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=438fafd1e54ebc51878101dc2e40f328)

* **Spine.** Each plate is a thin clear shell with a peg underneath that presses into a socket in the back, with a hole through for the LEDs.
* **Candy path.** The dispenser sits in the head under the spine, so no plate is covered. The chute runs down the throat and out over the tongue. The mouth is fixed open: no moving jaw near small hands.
* **Refill lid.** A lid in the top of the head lifts off. Its edge follows a carved crack, and magnets hold it shut.
* **Plinth.** Holds the electronics, two speakers behind small worn-looking holes, a service door and a cable hole for the charger.

![Exploded view of every print piece. Statue on top with the blue dispenser in the head, plinth tops, walls and door below.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-10-take-a-tour-of-the-3d-10.5a-exploded-viewport.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=cf95ef470604df72ef687088181651bd)

![From behind: eight clear spine plates, each with its own light.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-10-take-a-tour-of-the-3d-10.9a-back-render.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=d51940f43a9679689e46b69f56af560d)

***

## Step 10: Test Print the Eye and a Spine Plate

The eyes print into the head, one of the longest prints in this build. If an eye glows wrong, you lose the whole print. So test the risky parts small first.

1. Print one eye test piece with exactly the settings you will use for the head: 0.2 mm layers, the same grey and clear spools, clear only on the visible front of the eye. Clear filaments glow very differently, so test the spool you will really use.
   * **You should see:** a smooth clear dome, a crisp dark slit, and no grey streaks in the clear part.

![The eye test piece off the plate: clear cap, slit pupil and carved lids. Mine is in orange as a shape test.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-12-test-print-the-eye-12.1-eye-front.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=57d9147f14c243ddbba1fcd3054f3d57)

2. Print one spine plate in clear and its patch of back in any spare colour.
3. Press the plate into the socket.
   * **You should see:** the plate sits down on its ledge all the way round, no gap and no rocking. It needs a firm push, not a hammer.

![The spine test print: one clear plate pressed into its patch of back.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-13-test-print-a-spine-plate-13.1-plate-in-socket.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=411c933c1b26eb817f4a1ec0bac64ae9)

![Side view: the plate seated on its ledge, and the LED hole underneath.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-13-test-print-a-spine-plate-13.2-side-view.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=4f9bd53c12fb9d76f1c51ded7d71c8ae)

**Build a test light on the breadboard.** This is the same circuit as the final build, so it is good practice.

4. Wire **D5** on the UNO Q through the 330 to 470 ohm resistor to the eye board's **DIN**. Put the resistor at the eye board end and keep the data wire short, about 10 cm.
5. Wire the eye board's 5V and GND. Put the 1000 uF capacitor across 5V and GND next to it, striped leg to GND.
6. Wire the 3 strip pixels after the eye: eye **DOUT** to the first pixel's DIN, then DOUT to DIN along the three. Thread them up through the socket hole so they sit under the plate.
7. In App Lab, make a new app, paste this into its sketch and press **Run**:

```cpp theme={"system"}
#include <Adafruit_NeoPixel.h>
// Test light: D5 > 330 ohm > eye DIN, eye DOUT > 3 spine pixels (one plate).
Adafruit_NeoPixel px(10, 5, NEO_GRB + NEO_KHZ800);

// {eye, spine} colours for idle, listen, win, fail, the same as the game sketch
const uint8_t COL[4][2][3] = {
  {{255, 140, 0}, {120, 0, 255}},
  {{160, 255, 210}, {255, 110, 0}},
  {{0, 255, 0}, {0, 255, 0}},
  {{255, 0, 0}, {255, 0, 0}},
};

void setup() { px.begin(); }

void loop() {
  for (int m = 0; m < 4; m++) {
    for (int pct = 10; pct <= 60; pct += 10) {     // six brightness steps, 3 s each
      for (int i = 0; i < 10; i++) {
        const uint8_t *c = COL[m][i < 7 ? 0 : 1];
        px.setPixelColor(i, c[0] * pct / 100, c[1] * pct / 100, c[2] * pct / 100);
      }
      px.show();
      delay(3000);
    }
  }
  px.clear();
  px.show();
  delay(2000);
}
```

* **You should see:** amber, mint, green, then red in the eye, each getting brighter in six steps. The plate glows purple, orange, green, then red.

> **Safety:** this test runs from the UNO Q's own 5V pin, which is fine for one eye and one plate at these levels. Never run the full chain, the servo or the mist from it.

8. Push the eye board into the pocket behind the eye. Switch off the room lights and look from 1 m away, straight on, from the side and from a child's height.
   * **You should see:** only the iris glows, the slit stays dark, and you cannot count the seven LED dots. At the second step (20 percent, the cap in the game) it glows clearly in a dim doorway without glaring.

[Eye light test: the eye test piece lit.](https://www.youtube.com/embed/e3tWtQVRK2o)

Eye light test: the eye test piece lit.

[Spine light test: one spine plate lit in its socket.](https://www.youtube.com/embed/otnuoIim_1w)

Spine light test: one spine plate lit in its socket.

9. Leave both on the brightest step for 10 minutes, then touch them.
   * **You should see:** barely warm.

**Not working?**

| Problem | Fix |
| - | - |
| Light leaks through the lids | The grey around the eye must be at least 2 mm thick. Paint the inside of the pocket black. |
| You can count seven dots | Move the board 5 to 10 mm further back from the dome. |
| Nothing lights | Check the DIN arrow, the resistor, and that the data wire goes to D5. |
| Flicker or random colours | Shorten the data wire from D5 and put the resistor right at the eye board. |
| Grey streaks in the clear | Raise the purge (flush) volume for the colour change in your slicer. |
| Plate too tight | Sand the peg lightly with 240 grit. |

***

## Step 11: Build and Test the Candy Dispenser

One servo turns a one-pocket rotor under a tube of sweets. Each turn lets exactly one sweet fall down the chute, past an IR sensor that confirms the drop.

1. Measure one sweet with calipers. Mine (a wrapped eclair toffee) is 31 mm long, 13.2 mm thick and 53 mm long over the wrapper twists.

2. The print files are sized for this sweet. Pick wrapped sweets of about the same size: a much shorter sweet can drop two at a time, and a longer or thicker one will not fit the pocket.

3. Print the fit coupons in `hardware/cad/dispenser/stl/test/fit/` first. Each prints in minutes and tests one fit:
   * `fit_tube` into `fit_socket`: slides in with a light push, no wobble (0.2 mm per side);
   * `fit_collar` onto `fit_boss`: pushes on and stays on (0.1 mm per side);
   * `fit_servo`: the SG90 drops in gear end first;
   * `fit_rotor` onto the servo horn: presses on with no play.

4. If a coupon is too tight or too loose, change **X-Y hole compensation** (for sockets) or **X-Y contour compensation** (for pegs) in your slicer's quality settings by 0.05 mm, and print that coupon again.

5. Print the test rig from `hardware/cad/dispenser/stl/test/`: housing, rotor, servo plate, shelf, tube and long chute. The shelf tilts it 20 degrees, as in the statue.

![The test rig printed in spare orange PLA+. Colour does not matter here, only the fits.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-14-build-the-dispenser-prototype-rig-14.4a-test-print-parts.jpg?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=6bace63ddcff893c4ea9bfd381d45823)

6. Push the servo into the servo plate and fix it with the screws that came with it. Push the rotor onto the horn, but **do not** fit the horn screw yet (Step 15 sets the angle).
7. Drop one sweet into the tube and turn the rotor slowly by hand, from the load side, over the top, to the chute side and back. Repeat with 10 sweets, then with a full tube.
   * **You should see:** exactly one sweet per turn, sliding out of the chute by itself.
8. Print the statue dispenser from plate `04_plate_13_dispenser_grey.3mf` in `hardware/print/`. It is the same mechanism with a short chute; the throat and tongue carry the sweet the rest of the way.
9. Paint the inside wall of the chute opposite the side window matte black, so the IR sensor sees only the sweet. Fit the IR module at the window.

![The finished statue dispenser from the tube side. The tube top is cut to a curve so it fits under the head dome.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-19-build-the-final-dispenser-19.4-final-dispenser-tube-side.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=1f23522285ee9dd15ba68b099d41ea63)

![The same dispenser from the servo side: the SG90 in its plate, the housing in the middle, the IR rails on the chute.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-19-build-the-final-dispenser-19.5-final-dispenser-servo-side.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=b41c7d5f2c9b620f029b7ab79791f57f)

[Candy dispenser final test: sweets dropping on command from the UNO Q.](https://www.youtube.com/embed/8M4Au5D3Nuo)

Candy dispenser final test: sweets dropping on command from the UNO Q.

**What the first rig taught me.** The sweet hung in the pocket and the outlet. Every part on the sweet path got 3 mm more room, and the chute went from 35 to 45 degrees: at 35 the sweet rolled slowly, at 45 it slides. My first design used a stepper and a pocket wheel; one servo does the same job with fewer parts.

> **Safety:** once the servo is powered, keep fingers out of the rotor. It is small, but it pinches.

**Not working?**

| Problem | Fix |
| - | - |
| Two sweets come out at once | Your sweet is shorter than mine. Use sweets about 53 mm long over the twists. |
| Sweet turns sideways and sticks | Your sweet is narrower than mine. Use sweets about 13 mm thick. |
| Sweet stops in the chute | Sand the chute floor smooth and check the shelf sits flat. |
| Rotor catches the next sweet | Sand a small chamfer on the back edge of the pocket. |

***

## Step 12: Print and Assemble the Statue

![Every printed piece before assembly: head and body in grey, back panels with their spine sockets, eight spine plates in clear.](https://mintcdn.com/edgeimpulse/hJs6AcFNcwidZOeX/.assets/images/feed-the-gargoyle/step-00-supplies-s.2-printed-parts.png?fit=max\&auto=format\&n=hJs6AcFNcwidZOeX\&q=85\&s=d2be315799b6886b5421ebcdaa994caa)

1. Open the plates in `hardware/print/` in your slicer in the order of `PRINT_PLAN.md`: head, face, dispenser and spine first, then body, wings and plinth.
2. Print plate 01, the head, as one two-colour print: grey for the head, clear only for the eye fronts, exactly as in your eye test.

![The face fresh off the plate, eyes already in their sockets. The hole in the forehead is for the camera.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-15-print-the-statue-15.3-face.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=dc21f8d1fc5335fbbd32012904d89287)

3. Print plate 05, the eight spine plates, in clear.

![The eight spine plates in clear PLA+, next to the back panels they press into.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-15-print-the-statue-15.4-spine-plates.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=568ec23e5d95b0942b78f8537cfecf5f)

4. Print the remaining plates in grey. Any colour works for body and plinth parts because the primer and cement cover it, but keep everything around the eyes and LED pockets opaque.
5. Cut 1.75 mm filament into 12 mm pins. Push one into each hole on **one** side of every cut face.
6. Dry fit the whole statue with no glue, following `hardware/print/ASSEMBLY.md`.
   * **You should see:** every joint sits flat, no rocking, no gap. If a pin is tight, twist a 2 mm drill bit in the hole by hand.
7. Glue the joints in the same order: CA glue for short joints, epoxy for long ones. Mix epoxy for one joint at a time, tape each joint closed and let it cure.

![Masking tape, CA glue for short joints and five-minute epoxy for long ones.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-16-assemble-the-statue-16.0-glue-and-tape.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=b868f086e0cce20716e6fed460909ff2)

8. **Do not glue** the refill lid, the spine plates or the statue to the plinth. They come apart for service.
9. Turn the statue over and press the four heat-set inserts into the base with the iron at about 220 C, straight down, until flush.

> **Safety:** the iron and insert are hot enough to burn badly. Work on a heat-proof mat.

**Not working?**

| Problem | Fix |
| - | - |
| Piece lifts at the corners | Wash the plate with soap and water and add a brim. |
| Joint has a gap | Fill it with putty in Step 13. Gaps under 1 mm vanish under the cement. |
| Insert went in crooked | Press it straight with the iron while still warm. |

***

## Step 13: Turn Plastic into Stone

Paint alone always looks like plastic. A thin coat of real cement gives the grain, weight and cold feel of stone.

1. Fill every seam with putty, let it dry, and sand with 120 then 240 grit.
2. Take the lid off. Mask the clear eye fronts, every spine socket and ledge, the mouth, throat and tongue, and plug the camera, ear and speaker holes and the insert holes.
3. Brush on a thin coat of grey epoxy primer. Let it dry, then add a second coat.
   * **You should see:** one even grey, no filament colour showing.

![The stone coat kit: grey epoxy primer, waterproof PVA glue and a flat brush.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-17-prime-and-coat-it-in-cement-17.3b-primer-and-glue.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=52d298d9394c1c221e50ec3d05b76174)

> **Safety:** primer fumes are strong. Work outdoors or with good airflow, and wear a mask. Wet cement is caustic and the dry powder is harmful to breathe: wear gloves, glasses and a dust mask, and wash any splash off with plenty of water.

4. Mix fine cement with waterproof PVA and a little water to thick-paint consistency, about 2 parts cement to 1 part PVA. Mix only what you can use in 20 minutes.
5. Brush on a thin coat, about 1 mm, one section at a time, and dab it with the brush or sponge for a rough grain. Keep it extra thin in carved details.
6. Let it cure for 24 hours out of direct sun. Lightly sand the sharpest high points so nothing snags a hand.
7. Peel the tape and pull the plugs.
   * **You should see:** a spine plate still seats, the lid still drops in, and the camera and ear holes are clear.
8. Spray two light coats of matte clear sealer.
9. Weather it: a runny black wash wiped off the high points, a dry-brushed light grey on raised details, green and brown dabbed into the low spots. Keep every mark uneven, never the same on both sides. Seal again.
   * **You should see:** from 1 m away, no seams and no plastic shine.

**Not working?**

| Problem | Fix |
| - | - |
| Cement cracks or flakes | Too thick or too little PVA. Sand off the loose bits, recoat thinner with more PVA. |
| Details blurred | Pick the cement out with a toothpick while soft. Thin the mix next time. |
| Lid no longer fits | Sand the cement off the lid edge and the head edge. |

> Aside: the first time I touched the cured statue in the dark, I took my hand away rather quickly.

***

## Step 14: Wire Power, Servo, Sensor, Lights and Mist

Keep the schematic and pin map open while you wire. The full KiCad schematic is in `hardware/kicad/` in the repo.

![The full schematic.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-20-build-the-power-rail-safely-20.4-schematic.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=bedb04bd55c585e080c863fce0cc2ddb)

**14a. The power rail**

The gargoyle has **two supplies** that share only a ground wire. The board runs from the 45 W charger through the hub. The LEDs, servo and mist run from a separate 5 V rail. Servos and LEDs pull sudden bursts of current; on the board's supply those bursts made my board restart.

![Two supplies that only share a ground wire, so the servo, lights and mist never draw on the board's supply.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-20-build-the-power-rail-safely-20.5-power-rails.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=03de602ee098da5b4f402ceeea41dc89)

> **Safety:** keep both supplies unplugged while you wire. Plug in only when a step says so.

1. Wire the **kill switch** into the 5 V supply's positive lead, then the **fuse holder** after it. Fit the 2.5 A fuse.
2. On perfboard, make two bus strips, **+5 V** and **GND**. Solder the fused positive to +5 V and the supply's negative to GND.
3. Add one black wire from the GND bus to a **GND** pin on the UNO Q. Without the shared ground, the signals will not work.
4. Set the multimeter to continuity and touch +5 V and GND.
   * **You should see:** no beep.
5. Plug in the supply, switch on, and measure +5 V to GND.
   * **You should see:** 4.9 to 5.1 V. Switch off and unplug.

**14b. Servo and drop sensor**

![The pin map, for when the list blurs at 1 am.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-21-wire-the-servo-and-the-drop-21.5-pin-map.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=7e7cb0cbefb2c3ef4d0443727f912441)

| UNO Q pin | Goes to |
| - | - |
| D2 | IR module OUT |
| D4 | Mist MOSFET gate (through 100 ohm) |
| D5 | Eye LED data, through a 330 to 470 ohm resistor |
| D6 | Spine LED data, through a second 330 to 470 ohm resistor |
| D9 | Servo signal |
| GND | GND bus of the 5 V rail |

6. Servo: **brown** to GND bus, **red** to +5 V bus, **orange** to **D9**.
7. IR module: **VCC** to the UNO Q **3.3 V** pin (not the 5 V bus, so OUT never lifts D2 above 3.3 V), **GND** to GND bus, **OUT** to **D2**.
8. Power the rail and the UNO Q, then hold a sweet in front of the IR module.
   * **You should see:** the module's small LED on with the sweet there, off when it is gone. If not, turn its trimmer screw slowly until it reacts only to the sweet.

**14c. Eyes and spine**

The 38 LEDs run as **two chains**: the eyes on **D5** (left eye 7, then right eye 7) and the spine on **D6** (8 plates of 3, tail plate first). Data goes in at DIN and out at DOUT, pixel to pixel. Both data lines come straight from the UNO Q at 3.3 V, each through its own 330 to 470 ohm resistor.

![The spine parts: 24 single pixels cut from the WS2812B strip, sorted into eight groups of three, with red, black and blue wire.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-22-wire-and-test-the-eyes-and-22.1-spine-led-boards.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=51454682d1b65cadac641fc40a82aceb)

9. Cut the strip across the copper pads into **24 single pixels**, then sort them into **eight groups of three**, one per plate.
10. Within each group, solder short loops: 5 V to 5 V, GND to GND, DOUT to the next DIN. Use red for 5 V, black for GND and blue for data so you can check it at a glance.
11. Join the groups with longer wires, last DOUT of one group to first DIN of the next, with enough slack to reach the next plate opening.

![The spine chain soldered: eight groups of three pixels.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-22-wire-and-test-the-eyes-and-22.2-spine-chain-wired.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=461dad9c59668bb7e3bd4d9dae18dc19)

12. Lay the chain inside the back shell with **group 1 at the tail** and group 8 at the head. Cover each group with a small paper square and fix it with hot glue, so it can come out again.

![The chain glued inside the back shell, one group under each plate opening, tail at the bottom.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-22-wire-and-test-the-eyes-and-22.5-spine-chain-in-back.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=d462d6270e132826ef0444955d312508)

![The whole chain in order. The number under each plate is the meter level that lights it; plate 8 at 94 is the win.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-22-wire-and-test-the-eyes-and-22.6-led-chain.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=9bca9cf642cbf5b9454b8e0256cb6138)

13. Seat each eye board in its pocket behind the eye with a dab of hot glue. Chain them: left eye DOUT to right eye DIN.

![Both eye rings seated in their pockets, chained on one three-wire lead.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-22-wire-and-test-the-eyes-and-22.4-eye-rings-seated.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=4f4ebcb725c9f7479eeb0a1d149b3e32)

14. Wire **D5** through a 330 to 470 ohm resistor to the left eye's **DIN**, and **D6** through the second resistor to the tail group's first **DIN**. Put each resistor at the LED end and keep both data wires as short as the body allows. Leave the right eye's DOUT and the head group's last DOUT unconnected.
15. Solder the 1000 uF capacitor across +5 V and GND where power enters the chains, striped leg to GND. Feed 5 V and GND from the bus (not the UNO Q's 5V pin) to the start of each chain.
16. Open `app/sketch/sketch.ino` and check `PLATE_PX = 3`, for three LEDs under each plate.

**Why the brightness is capped and the redraw is slow.** The sketch caps the eyes at about 20 percent and the spine at about 70 percent: it looks better on stone, draws less current and keeps the plastic cool. With the spine at full brightness, the USB camera dropped off the bus on my 4 GB UNO Q during a full run, so leave the cap in place. On an earlier UNO Q build, redrawing an LED ring every 40 ms made every Bridge message time out; redrawing only on a change brought them back to 6 to 8 ms. Here the sketch only sends pixels when one changes, at most every 200 ms, and every colour change is slew-limited: no sudden flashes.

**14d. Mouth mist**

17. Hold the IRLZ44N with the writing facing you. The legs, left to right, are **Gate, Drain, Source**.
18. Solder the **100 ohm** resistor from **D4** to the Gate, and the **10 k** from the Gate to GND. The 10 k keeps the mist off while the board starts.
19. Connect Source to GND. Connect the mist board's **+** to the +5 V bus and its **-** to the Drain.
20. Put the disc on a wet wick in the water cup (damp, not under water), and the cup in the drip tray under the mouth, away from the boards, the mic and the sweets.

> **Safety:** never let the disc run dry and never let water reach the electronics. Empty the cup after every night.

The sketch protects the mist: one puff lasts 3 s at most, then it rests 6 s, it never runs while the gargoyle is listening, and the safety net turns it off. On the bench (4 GB UNO Q, real sketch) a second request 3 s after a puff was refused and a 3.5 s request was cut to 3 s.

**Not working?**

| Problem | Fix |
| - | - |
| Board restarts when the servo moves | The servo is on the board's power. Move it to the 5 V rail and check the shared GND. |
| IR LED always on | It sees the chute wall. Paint the wall matte black and turn the trimmer down. |
| LEDs show random colours | Check the DIN arrows, the data resistors and the shared GND, and shorten the first data wire. |
| Only some spine plates light | Check `PLATE_PX = 3` and the DOUT to DIN joints between groups. |
| Eyes light but the spine stays dark | Check D6 goes through its resistor to the tail group's first DIN, and the arrows point away from the tail. |
| Mist never starts | Check the MOSFET legs (G, D, S) and that the disc is damp. |

***

## Step 15: Load the Sketch, Set the Rotor, Test the Safety Net

The sketch is the Arduino program that runs on the microcontroller. Every value marked `CAL` at the top of `app/sketch/sketch.ino` is one you may tune for your build.

1. Copy the edited sketch to the board:

```
scp app/sketch/sketch.ino arduino@<board-ip>:/home/arduino/ArduinoApps/gargoyle/sketch/
```

2. Start the app. In App Lab, open it and press **Run**, or from the board:

```
arduino-app-cli app start /home/arduino/ArduinoApps/gargoyle
```

* The first start compiles the sketch and loads it onto the microcontroller. It takes a few minutes.
* **You should see:** slowly breathing amber eyes and a soft glow on the spine. With no models found, the app runs a practice mode with a pretend visitor, so you can check lights and voice first.

[Eyes of the gargoyle: both eyes in the head, breathing slowly through ember, amber, gold and red.](https://www.youtube.com/embed/W1CmieFCXxY)

Eyes of the gargoyle: both eyes in the head, breathing slowly through ember, amber, gold and red.

[The spine as a scream meter: the plates light up as the scream gets louder.](https://www.youtube.com/embed/5BPkbXfx2s0)

The spine as a scream meter: the plates light up as the scream gets louder.

[The spine as the riddle timer, when the answer is right and in time.](https://www.youtube.com/embed/FXMCLQzP1VQ)

The spine as the riddle timer, when the answer is right and in time.

[The spine as the riddle timer, when time runs out or the answer is wrong.](https://www.youtube.com/embed/BE0GlHVYUoI)

The spine as the riddle timer, when time runs out or the answer is wrong.

3. **Set the rotor.** With the app running, the servo holds the load angle (170 degrees). Pull the rotor off the horn, push it back on with the pocket facing straight up the tube, and now fit the horn screw.
4. **Run the drop test.** Stop the app and create the test switch:

```
touch /home/arduino/ArduinoApps/gargoyle/python/dispense.on
```

5. Load 10 toffees and start the app again. It drops one sweet every 4 seconds, up to 50, and stops if it jams.
   * **You should see:** each sweet out of the chute and `drop_confirmed` counting in the log. On my bench the drop was confirmed 1.2 to 1.5 s after each command.
6. Delete the switch when you are done: `rm /home/arduino/ArduinoApps/gargoyle/python/dispense.on`
7. **Test the safety net.** With the app running, pull out the board's USB-C.
   * **You should see:** within about a second, the rotor returns to load, the mist stays off and the lights go to idle.

**Not working?**

| Problem | Fix |
| - | - |
| Rotor turns the wrong way | Swap the `PADDLE_LOAD` and `PADDLE_DUMP` values. |
| Sweet gets flung out | Raise `SWEEP_MS` (3 ms per degree by default) so the rotor moves slower. |
| Sweet drops but no `drop_confirmed` | Adjust the IR trimmer and check OUT goes to D2. |
| Two misses, then everything stops | That is the jam protection. Clear the jam and restart the app. |

***

## Step 16: Fit the Dispenser, Camera, Mic and Speakers

**Dispenser and lid**

1. Route the servo and IR cables down through the neck first.
2. Lower the dispenser onto the locating pin and three posts inside the head, and screw it down with the three M3 screws.
   * **You should see:** it sits level with the chute lined up with the throat.
3. Stack all eight magnets and mark the top face of the stack. Glue four into the lid with the **marked** face up and four into the head tabs with the marked face down.
   * **You should see:** the lid snaps into place and lifts off with a fingertip. The head holds 5 sweets: one in the pocket, four in the tube.

**Camera, the third eye**

4. From inside the head, push the lens into the forehead hole until the case rests on the ledge.
   * **You should see:** from the front, only a dark dot in the middle of the spiral.

![The face with the camera lens fitted in the forehead. The third eye is open.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-15-print-the-statue-15.3b-face-with-lens.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=5bdd083b04b3b184a2c820a1f3bff85c)

**Microphone and speakers**

5. Fit the lavalier mic in the ear cavity with its foam windscreen, held by a rubber grommet, not glue, so servo buzz does not travel into it. Plug it into the USB sound card, and the sound card into the hub.
6. Glue each speaker on its tray in the plinth, facing the small worn holes. Connect them to the sound card output, left channel on the visitor's left.

**Fix the mic level once, then never touch it**

One mic does both jobs: the Boya in the ear. A single stream feeds the keyword model and the scream meter, so the two can never disagree about what they heard. The camera's own mic is not used; on my bench it clipped on the gargoyle's own laugh at full gain.

7. On the board, run `alsamixer`. Press F6, pick the USB sound card and set its mic capture to the maximum (28 on mine).
8. Press Esc and save the level so it survives a reboot: `sudo alsactl store`
9. Stop the app while you calibrate, so the mic is free: `arduino-app-cli app stop /home/arduino/ArduinoApps/gargoyle`

**Calibrate the scream meter**

The spine reads the ear mic every 0.2 s and maps the level to 0 to 100 between `FLOOR_DB` (empty spine) and `TOP_DB` (full spine) in `app/python/sensors.py`. A scream wins when it reaches the top plate on 3 readings in a row, so one bang or clap cannot win.

![How loud is loud enough. The line is the meter, the shaded band is my test screams, the dashed line is a win.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-26-fit-the-camera-microphone-and-speakers-26.1-scream-meter.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=31e1499756e2f90c3fe5b8ff61754583)

10. On the board, make a tiny level script:

```
cat > level.py << 'EOF'
import sys, wave, array, math, statistics
a = array.array("h", wave.open(sys.argv[1]).readframes(10**9))
n = 3200  # 0.2 s at 16 kHz
db = [20 * math.log10(max(1, math.sqrt(sum(x * x for x in a[i:i + n]) / n)) / 32768)
      for i in range(0, len(a) - n, n)]
print("quietest %.1f  median %.1f  loudest %.1f dBFS" % (min(db), statistics.median(db), max(db)))
EOF
```

11. With the gargoyle where it will stand and nobody talking, record 5 s of the room:

```
arecord -D plughw:CARD=Device,DEV=0 -f S16_LE -r 16000 -c 1 -d 5 quiet.wav && python3 level.py quiet.wav
```

12. Stand 1 m in front and scream as loud as you comfortably can for the whole 5 s:

```
arecord -D plughw:CARD=Device,DEV=0 -f S16_LE -r 16000 -c 1 -d 5 scream.wav && python3 level.py scream.wav
```

* **You should see:** the scream's loudest reading well above the room's median.

13. In `app/python/sensors.py`, set `FLOOR_DB` about 4 dB above the room's median, and `TOP_DB` a little below the scream's median, so a good honest scream fills the spine. Mine, in a full run on the 4 GB UNO Q: room -39 dBFS, screams -18 to -2, so `FLOOR_DB = -35` and `TOP_DB = -12`.
14. Delete the recordings: `rm quiet.wav scream.wav`

**Not working?**

| Problem | Fix |
| - | - |
| Wrong mic records | Card numbers swap between boots, so the app opens the ear mic by name, `CARD=Device`. `arecord -l` lists the names. |
| Talking fills the spine | Raise `FLOOR_DB` a few dB. |
| No scream ever wins | Lower `TOP_DB` a few dB. |
| No sound from the speakers | Run `aplay -l` and check the sound card is listed. |

***

## Step 17: Bring It to Life

1. Switch the app from practice mode to the real models:

```
touch /home/arduino/ArduinoApps/gargoyle/python/sensors.on
```

2. Start the app:

```
arduino-app-cli app start /home/arduino/ArduinoApps/gargoyle
```

* **You should see:** in the log, the camera starting, the keyword runner found, the visitor model loaded, then the game going idle.

![The app starting on the board: camera up, keyword runner found, visitor model loaded, game idle. The onnxruntime GPU warning is harmless.](https://mintcdn.com/edgeimpulse/luU0H9OUMqhI5fuW/.assets/images/feed-the-gargoyle/step-27-bring-it-to-life-27.1-app-start-log.png?fit=max\&auto=format\&n=luU0H9OUMqhI5fuW\&q=85\&s=86e561246b7d5521237eddad8e81e803)

3. Stand in front of the camera, one to two metres away.
   * **You should see:** after a little over a second, mint eyes, a greeting and a challenge.
4. Do what it asks: answer the riddle clearly, or scream.
   * **You should see:** on a win, green eyes, a puff of mist and a sweet down the tongue.
5. Walk away.
   * **You should see:** a goodbye, a 10 second rest, then sleepy amber eyes.

**What it costs the board** (4 GB UNO Q, measured once about a minute after start with an earlier version of the app: visitor, sound and keyword bricks plus the costume runner, camera at 10 fps, nobody in front): the camera model used about one of the four cores, the app about half a core, the audio models a quarter of a core, and 2.5 GB of 3.7 GB memory was still free. In a 30 minute run with stand-in camera and audio bricks and Gemma all busy, the board never restarted.

**For the curious:** the game is a plain state machine in `app/python/game.py` with no hardware calls. Run `python app/python/game.py` on your computer and its self-checks run.

**Not working?**

| Problem | Fix |
| - | - |
| "Failed to enumerate audio devices" | The mic must be named directly, as `plughw:CARD=Device,DEV=0`. Check names with `arecord -l` and see `app/python/main.py`. |
| No greeting, eyes stay amber | Check the camera is in the hub and `visitor.eim` is installed and runnable. |
| Greets but never hears you | Check the mic level (Step 16) and that `keywords.eim` is installed. |
| Still in practice mode | Check `sensors.on` is in `app/python/` on the board. |

***

## Step 18: Close It Up and Test Before the Night

1. Pass the charger cable through the hole in the back of the plinth and plug it into the hub.
2. Tie every cable away from the servo and the mist cup.
3. Lift the statue onto the plinth, line up its four inserts with the holes, and drive the M3 x 16 screws up from inside with the long hex key. One speaker covers a screw path: lift it out first.
   * **You should see:** the statue does not move when you push the top of its head gently.
4. Run this checklist before the big night:
   * a couple of visits in a row with no restart, counting wins, losses, wrong costume lines and missed visitors;
   * an empty doorway for an hour, counting false wake-ups;
   * music and chatter nearby, counting false riddle answers;
   * pull the plug in the middle of a drop: the rotor must park;
   * play with an empty tube: it must apologise for a jam, not grind away;
   * two hours non-stop: the board must not be too hot to touch.

In a short live test with only a fan running, I got two false "pumpkin" detections in 191 s, both on loud room noises, none from the fan (4 GB UNO Q, board mic, one window every 100 ms).

**On the night:** put the gargoyle where the forehead looks at adult chest height, the cauldron under the tip of the tongue, up to 5 toffees in the lid, the mist cup filled. Switch on the 5 V rail first, then plug in the board.

> **Safety:** wrapped sweets only. Keep the back door and cables out of reach of small children. Keep it out of direct sun: PLA+ softens at around 55 to 60 C. Empty the mist cup at the end of the night.

***

## Results

The table near the top has the headline numbers. A few more, all measured on the finished build:

* **Every outcome plays on the stone body:** right answer, wrong answer with hint, timer out, winning scream and a scream too quiet (videos at the top).
* **Board under full load:** with the camera, sound and keyword bricks running, the board stayed up at 3 and at 4 llama.cpp threads, and 4 threads gave no speed gain, so play uses 3.
* **Drop confirmation:** the IR sensor sees the sweet 1.2 to 1.5 s after the command (bench rig, real sketch).
* **Mist limits:** a second puff 3 s after the first was refused and a 3.5 s request was cut to 3 s (bench, real sketch).
* **Voice:** the 179 bank lines on the board with known text, transcribed with Whisper base.en on my PC: 18.7 percent average word error, median 12.5 percent, 58 lines word for word.

***

## Privacy and Safety

* Camera frames and sound stay in memory only long enough to be checked. Nothing is stored or sent anywhere, and it needs no network at the door.
* It never comments on a face or body. Costume lines play only when the model is confident.
* No moving jaw near small hands: the mouth is fixed open and the tongue is the slide.
* Wrapped sweets only.
* If Linux stops sending heartbeats for one second, the microcontroller parks the servo, stops the mist, darkens the spine and holds a dim glow in the eyes.
* No flashing lights: every LED change is slew-limited.

***

## What Went Wrong (War Stories)

* **A moving jaw:** a pinch point near a child's hand. Removed.
* **A weak charger:** boot loops once the camera was plugged in. Fixed with a PD supply and a separate 5 V rail.
* **LEDs redrawn every loop:** jammed the Bridge. Redraw on change only.
* **Mic at full gain on the wrong mic:** clipped screams. Fix the gain first, then collect data.
* **int8 models:** use the float32 builds. Every result here was measured with them.
* **The language model could not hold the character.** So it drafts, rules filter, and the board speaks only checked lines.

## Troubleshooting, the Short List

| If you see | Check |
| - | - |
| The board restarts when the camera or servo starts | The 45 W PD charger, and that the servo and LEDs are on the separate 5 V rail with a shared GND. |
| A model will not load or scores 0.00 | You built int8. Rebuild **Unoptimized (float32)** for **Linux (AARCH64)**. |
| Bridge calls time out | Something redraws the LEDs every loop. Redraw on change only. |
| Screams clip or the meter jumps | Mic gain is too high. Fix the gain once and check the peaks before collecting data or calibrating. |
| It wakes for posters or a TV | Add posters, screens and statues to `empty` in the visitor project and retrain. |
| Props never show up at the door | `yunet.onnx` must sit next to `props.eim`; the crop on the board must match the training crop. |
| The IR LED is always on | It sees the chute wall. Paint the wall matte black and turn the trimmer down. |
| Everything goes dim and the servo parks | The safety net. Linux stopped sending heartbeats; check the app log. |

***

## Conclusion

The gargoyle started as a way to make trick-or-treat at our door a little more fun and interactive. It turned into a small lesson in fitting real AI on one cheap board: a tiny model that is always awake, bigger ones that only wake when they are needed, and a language model used where it fits, before the night instead of during it.

The same pattern works for anything that greets people: a library mascot that asks a quiz question, a museum exhibit that hears a password, a shop window that reacts to a costume. All of it offline, nothing recorded, and a microcontroller that keeps it safe when the clever half falls over.

If you build one, tell me about it on the Edge Impulse forum. I want to hear what yours says to people.

***

## Files and Credits

* Code, CAD, print plates, schematic and every measurement: [https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle](https://github.com/Abhinavkrishna3211/Feed-the-Gargoyle)
* Public Edge Impulse projects: visitor gate [https://studio.edgeimpulse.com/public/1153004/live](https://studio.edgeimpulse.com/public/1153004/live), keywords [https://studio.edgeimpulse.com/public/1172323/live](https://studio.edgeimpulse.com/public/1172323/live), costume [https://studio.edgeimpulse.com/public/1172324/live](https://studio.edgeimpulse.com/public/1172324/live), props [https://studio.edgeimpulse.com/public/1160020/live](https://studio.edgeimpulse.com/public/1160020/live)
* Edge Impulse Studio, Arduino App Lab and the UNO Q bricks. Gemma 3 1B by Google with llama.cpp. Piper TTS with the en\_GB-alan-medium voice. YuNet from OpenCV Zoo. Public datasets listed in the repo.
