Skip to the content
PCBKitNew board
4 layers10 × 61 mmSpellcaster, the printed circuit board in 3D

🪄 A home automation magic wand

Size
10 × 61 mm
Copper layers
4
Thickness
1.6 mm
Parts
65
Nets
41
Pads
152
Tracks, vias
231, 59
Pours
4
Routed
Yes
KiCad
KiCad 7 (file 20221018)
Created
13 Aug 2023
Updated
1 Nov 2024

Overview

Spellcaster is an open-source printed circuit board by rbaron, from the rbaron/spellcaster repository on GitHub. It is a 4-layer board of 10 × 61 mm with 65 parts on 41 nets, routed with 231 tracks and 59 vias.

It is built around the LSM6DSL, B3U-1000P and 1N4148W, with the CR2032 among its other parts. Its parts include 16 capacitors, 4 resistors, 4 inductors, 2 ICs and 2 diodes. It belongs with the home automation and IoT boards and the nRF52 and nRF5x boards of this library.

Main components

4

README

README.md

spellcaster Demo

spellcaster is a home automation magic wand. Click on the thumbnail above to watch it in action.

How does it work?

An accelerometer and gyroscope are used to capture gestures ("spells"). Cast spells are then compared against previously stored ones. An action is triggered if there's a good match.

Different actions can be triggered. For example:

  • A BTHome.io Bluetooth Low Energy (BLE) packet can be emitted and handled in Home Assistant.
  • A Zigbee Cluster action, similarly handled in Home Assistant automations
  • A BLE-HID to simulate a key press on a computer, macro pad-style

In the "Software" section below, there are some firmware samples for each of these actions and more.

This blog post has a deeper dive into how everything works.

Project status

It sort of works, but there are caveats. Reliability and usability need improvement -- it's easy to hold it wrong. See "User interface" below. The code also needs the proverbial cleaning up.

Approach this project as a fun experiment. Expect fun and experimental support.

Hardware

PCB

The kicad/ directory contains the design and fabrication files. I used JLCPCB for manufacturing and assembly.

User interface

Casting spells

There is no on/off switch by design. To signal the start of spell, hold the wand horizontally flat. Once you start moving it, the gesture will start to be collected. To signal the end of spell, hold the wand horizontally flat again. Spells need to be between 500 milliseconds and 3 seconds in length.

Record mode

To store a new spell in slot S, press the A button S times and cast a spell as described above. If everything goes well, the LED will flash five times and you will be switched to replay mode.

In this video you can see five different spells being recorded:

spellcaster recording spells

Replay mode

This is the default mode in which spellcaster will live most of its life. Once a spell is cast, it will be compared to previously stored spells. If a good match is found, a vibration pattern is executed and an action will be triggered.

On false positives

The matching algorithm is optimized for something to happen. There is a low threshold for matching spells, and often two or more will be sufficiently matched. This depends on how similar spells are, but the best matching spell will always be selected. The idea is that, when we intentionally cast a spell, the correct one will almost always be selected, instead of -- sometimes -- none. On the other hand, previously unseen spells may trigger a false positive.

This is done to mainly prevent the sorry sight of a full grown adult waving a wand in the air in front of friends and family at a dinner party and nothing happening. Don't ask. A better solution is to further tune the spell matching algorithm to be more robust against these cases, while retaining the precision when the casting is intentional. Another idea is to add an invisible capacitive touch sensor to the handle, which would also allow for much deeper sleep modes. Something to be improved.

Deep sleep mode

If spellcaster is still for 10 seconds, it will enter the lowest power mode at around 65 uA. Most of which goes to the accelerometer, which lies semi-awake in a low power state waiting for movement. This can mostly likely be optimized further. Any movement will wake it up and into replay mode.

Software

There are a few sample firmwares in the repository. They are all written with Nordic's nRF Connect SDK. Most samples are adapted from the SDK's examples.

DirectoryDescription
code/sclibGeneric spellcaster library. Handles spell casting, storing and signal processing. Used by all other samples.
code/samples/ble-bthomeMatched spell S trigger a BTHome.io action that is equivalent to S button presses. This can then be used by Home Assistant automations.
code/samples/ble-hidspellcaster pairs with your computer via BLE. Matched spell S trigger a BLE-HID action that simulates a key press following the configurable keymap.
code/samples/zigbeeMatched spells trigger Zigbee Cluster actions that can be used by Home Assistant automations. Unfortunately, the Zigbee specs don't define magic wand clusters, so the spellcaster.py ZHA Quirk needs to be installed. With it, matched spell on slot S appears to be a "dim light" command with step S. Yikes! (And it's not even the worst hack around here).
code/samples/ble-dumpDumps raw accel & gyro spells over BLE. The client.py connects to spellcaster and dumps the data to a file. This is how I collected the data for tuning the spell matching without cables getting in the way.

Building the samples

These are standard nRF Connect SDK projects with Zephyr RTOS, and the official docs apply. The b-parasite project uses a similar setup with a generic library and different samples, and the Wiki contains more details and alternatives.

Flashing the samples

The samples are flashed with ARM's usual SWD. The official docs also apply. The only caveat is the custom, slim 6-testpoint SWD pins on the PCB. It also happens to the the exact same as described in the b-parasite Wiki.

Data analysis

The data/ directory contains a bunch of Jupyter notebooks I used to tune the spell matching and some of the raw collected data.

3D printed case

fusion-case

The 3dprint/ directory contains the STEP files for a 3D printed case. It's okay-ish, but could use some love. The 3D printed springs lose some tension after a while, and so do the clamps that hold both halves together. On the bright side, there's no glue nor screws involved. You can watch a video of the full assembly process here.

License

Hardware

spellcaster hardware © 2023 by rbaron is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0). See deed.

Software

Software in this repository is licensed under the MIT license. See LICENSE_SOFTWARE.

Parts

65
QtyValueFootprintReferences
6TestPointTestPoint:TestPoint_Pad_D1.5mmTP1, TP2, TP3, TP4, TP5, TP6
5100nCapacitor_SMD:C_0402_1005MetricC5, C10, C12, C14, C16
412pCapacitor_SMD:C_0402_1005MetricC2, C3, C4, C6
310kResistor_SMD:R_0402_1005MetricR2, R3, R4
3G***kibuzzard-64E668FFkibuzzard-64E668FF, kibuzzard-64E668FF, kibuzzard-64E668FF
21uCapacitor_SMD:C_0402_1005MetricC9, C15
2B3U-1000PSnapeda:SW_B3U-1000PS1, S2
2G***kibuzzard-64E66915kibuzzard-64E66915, kibuzzard-64E66915
11.2pCapacitor_SMD:C_0402_1005MetricC8
1100pCapacitor_SMD:C_0402_1005MetricC11
110uHInductor_SMD:L_1206_3216MetricL4
115nHInductor_SMD:L_0402_1005MetricL3
11N4148WDiode_SMD:D_SOD-323D2
11kResistor_SMD:R_0402_1005MetricR1
11pCapacitor_SMD:C_0402_1005MetricC7
12.2nHInductor_SMD:L_0402_1005MetricL2
12N7002Package_TO_SOT_SMD:SOT-23Q1
132kCrystal:Crystal_SMD_3215-2Pin_3.2x1.5mmY1
14.7nHInductor_SMD:L_0402_1005MetricL1
14.7uCapacitor_SMD:C_0402_1005MetricC1
147nCapacitor_SMD:C_0402_1005MetricC13
1Antenna_ChipRF_Antenna:Texas_SWRA117D_2.4GHz_RightAE1
1CR2032Battery:BatteryHolder_Keystone_1060_1x2032BT2
1Crystal_GND24Crystal:Crystal_SMD_2016-4Pin_2.0x1.6mmY2
1G***kibuzzard-64E7063Ckibuzzard-64E7063C
1G***kibuzzard-64E666C8kibuzzard-64E666C8
1G***kibuzzard-64E666DBkibuzzard-64E666DB
1G***kibuzzard-64E666EEkibuzzard-64E666EE
1G***kibuzzard-64E66855kibuzzard-64E66855
1G***kibuzzard-64E70567kibuzzard-64E70567
1G***kibuzzard-64E70501kibuzzard-64E70501
1G***kibuzzard-64E66B38kibuzzard-64E66B38
1G***kibuzzard-64E7057Ckibuzzard-64E7057C
1G***kibuzzard-64E704EFkibuzzard-64E704EF
1G***kibuzzard-64E70C98kibuzzard-64E70C98
1G***kibuzzard-64E70B5Bkibuzzard-64E70B5B
1G***kibuzzard-64E705F6kibuzzard-64E705F6
1G***kibuzzard-64E666BFkibuzzard-64E666BF
1G***kibuzzard-64E666A5kibuzzard-64E666A5
1G***kibuzzard-64E66706kibuzzard-64E66706
1LEDLED_SMD:LED_0603_1608MetricD1
1LSM6DSLPackage_LGA:LGA-14_3x2.5mm_P0.5mm_LayoutBorder3x4yU2
1Motor_DCTestPoint:TestPoint_2Pads_Pitch2.54mm_Drill0.8mmM1
1MountingHoleMountingHole:MountingHole_2.2mm_M2_Pad_ViaH2
1Through holesConnector_Wire:SolderWire-0.5sqmm_1x02_P4.8mm_D0.9mm_OD2.3mmBT1
1nRF52820-QDxxPackage_DFN_QFN:QFN-40-1EP_5x5mm_P0.4mm_EP3.6x3.6mmU1

Questions

How big is the Spellcaster PCB?

It measures 10 × 61 mm and has 4 copper layers, 1.6 mm thick.

What parts does the Spellcaster use?

65 parts, built around the LSM6DSL, B3U-1000P, 1N4148W and CR2032. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Spellcaster KiCad files?

From the rbaron/spellcaster repository on GitHub, at the commit this page was made from: the board is kicad/spellcaster.kicad_pcb and its schematic kicad/spellcaster.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the Spellcaster design in my own project?

Its repository states no licence, so its author keeps all rights: ask rbaron before reusing the design.

Similar boards

  • 6 layers53.3 × 101.6 mmMega2560plus, the printed circuit board in 3D

    Mega2560plus

    sneakylizard123-4/Mega2560plus

    Mega 2560+ is an upgraded version of the Arduino Mega 2560. It keeps the same form factor and pinout as the original so it still works with every Mega shield, but it adds an onboard sensor suite and an ESP32-S3…

    149 parts
  • 4 layers89.5 × 62.6 mmPenguin, the printed circuit board in 3D

    Penguin

    jeevan9s/penguin-bot

    intelligent hybrid robot

    165 parts1
  • 2 layers57.3 × 26.5 mmRemote, the printed circuit board in 3D

    Remote

    dshearer/lock2025

    16 parts
  • 2 layers208.8 × 396.9 mmFerris, the printed circuit board in 3D

    Ferris

    pierrechevalier83/ferris

    A low profile split keyboard designed to satisfy one single use case elegantly

    145 parts1.3k
  • 2 layers40.6 × 108 mmUseq1, the printed circuit board in 3D

    Useq1

    Emute-Lab-Instruments/uSEQ

    Hardware & firmware of the uSEQ Live Coding CV & Gate Sequencer

    172 parts44
  • 2 layers97.6 × 78.2 mmTired Seagull, the printed circuit board in 3D

    Tired Seagull

    klouderone/SeagullMacropad

    The Seagull Macropad is based off the Rhino Pad, that supports both MX and Choc switches. The Macropad features an aesthetic but functional diode layout, an encoder, and pads for a battery and battery switch for…

    38 parts31
  • 2 layers116.3 × 59.2 mmRhino Pad Board V2, the printed circuit board in 3D

    Rhino Pad Board V2

    klouderone/therhinopad

    The Rhino Pad is a compact Macro Pad tailored for Computer-Aided Drawing, with 13 keys and an encoder that can be programmed for any macro in your program.

    31 parts22