A deliberately simple, open-source box for recording mouse locomotion, built as a first step towards scalable behavioural phenotyping. About £1095 a box, six printed parts, half an hour to assemble.
Every part is either printed or bought off the shelf, nothing needs machining, and the printed parts need no supports. Simplicity is the point: a box that is quick to replicate, cheap enough to run in parallel, and hard to set up wrongly.
The box pairs video capture with rotary-encoder wheel tracking, using Harp for synchronised timestamping and Bonsai for control and acquisition. The aim is to pre-screen animals before downstream experiments, so behavioural differences show up early — improving experimental efficiency and reducing the number of animals needed later.
Four frames from a single session. The wheel is against the far wall; the mouse is tracked by centroid in both the arena and the wheel, under 850 nm light it cannot see.
- Video — continuous capture at 50 Hz for observation and offline analysis
- Wheel locomotion — cumulative running distance from a 1024 ppr encoder, sampled per frame
- One clock — the Harp board triggers the camera and timestamps the encoder, so the two streams share a time base rather than being aligned afterwards
| # | Part | Qty | Supplier | Cost (£) | Notes |
|---|---|---|---|---|---|
| 1 | PLA filament | 2 | Bambu Lab | 36 | 18 each |
| 2 | FLIR Blackfly S camera | 1 | DigiKey | 277 | BFS-U3-16S2M-CS |
| 3 | Rotary encoder | 1 | AliExpress | 18 | 1024 ppr version, see notes |
| 4 | Harp Behaviour Board | 1 | Open Ephys | 415 | Listed at €510 |
| 5 | Locking USB 3.0 Micro-B cable | 1 | Amazon | 18 | 5 m, straight connector |
| 6 | GPIO cable | 1 | DigiKey | 33 | Camera trigger. FLIR ACC-01-3010, Hirose HR10 6-pin, 4.5 m |
| 7 | Varifocal lens, 2.8-12 mm, CS mount | 1 | AliExpress | 12.49 | Manual zoom and focus, no IR filter |
| 8 | IR LED strip, 850 nm, 12 V | 2 m | AliExpress | 26 | Cut to length. Three walls need about 0.6 m |
| 9 | Mini PC, e.g. GEEKOM Air12 | 1 | Amazon | 240 | Meets the minimum specification below |
| 10 | M3 hex screw set, 6-14 mm | 1 | AliExpress | 9 | May be optional, see notes |
| 11 | RJ45 breakout | 1 | AliExpress | 2 | Gets the encoder wires into Port 2 |
| 12 | Screw terminal blocks, 5-way | 1 | AliExpress | 6.25 | Pack of 10. One terminates the encoder |
| 13 | 12 V power supply | 1 | AliExpress | 2.45 | For the IR LED strip |
Approximate total: £1095
Notes
- Encoder resolution — row 3 is sold in several resolutions off the same listing, and they are
indistinguishable in the product photographs. Choose 1024 ppr: the workflow ships with
CountsPerRevset to 4096, which is 1024 quadrature-decoded x4. Fit a different resolution without changing that value andWheelDistanceis wrong in every recording, with nothing in the data to say so. See Software. - Rotary encoder alternative — Omron E6B2-CWZ6C 360P/R 0.5M,
RS stock 215-8863, £216.14 exc VAT. Same NPN open-collector output and 6 mm shaft, but 360 ppr
rather than 1024, and about twelve times the price. Worth it only if you need a warranted part.
It needs
CountsPerRevchanged to 1440. - Screws — Omron encoders ship with an E69-2 bracket and three M3 x 10 Phillips screws, which may cover the encoder mount on their own. The assembly guide calls for three M3 x 8 mm hex screws and a 2 mm Allen key, so check what arrives before ordering row 10.
One machine per box runs Bonsai and writes the video. The GEEKOM Air12 in row 9 is the cheapest unit we have found that clears the bar, so its specification is the floor:
| Minimum | |
|---|---|
| CPU | 4-core x86, Intel N-series or PT7505 class |
| Graphics | Intel integrated graphics with Quick Sync, for the default video encoder |
| RAM | 16 GB |
| Storage | 512 GB NVMe SSD |
| USB | One USB 3.2 Gen 1 Type-A port dedicated to the camera |
| OS | Windows 11, for Bonsai and the Spinnaker SDK |
Three things to watch:
- No PCIe slot on a mini PC, so the camera runs from a built-in port rather than an expansion card.
- Intel graphics — the video is encoded by Intel Quick Sync, the hardware encoder in Intel's integrated graphics, which leaves the CPU free. On a machine without it, switch the encoder to x264 as described in Software.
- Storage — compressed video size depends on the scene and on sensor noise, so on gain. Measured on a textured scene, it was about 4 GB per hour at 3 ms exposure and 1 dB gain, and about 9 GB per hour at the shipped 10 ms and 5 dB; a plain arena comes in somewhat lower. A 512 GB disk holds 50 to 130 hours of recording. Uncompressed it would fill in under two hours, at the shipped 1440 x 1080 and 50 Hz. Binning 2 quarters all of these figures, at half the resolution in each direction.
Four steps, a couple of days of printing and half an hour of assembly.
| Step | What it involves | Guide |
|---|---|---|
| 1. Print | Six parts from five STLs in Assembly/Parts: arena, lid, camera holder, wheel, and the thumb screw twice. 15% infill, no supports, three plates on a standard Bambu Lab printer or equivalent. |
Assembly |
| 2. Assemble | Mount the encoder, fit the wheel to its D-shaft, clamp the camera in its holder with the lens, and line three walls with the IR strip. 20-30 minutes. | Assembly |
| 3. Wire | Camera to computer over locking USB, GPIO trigger and encoder to the Harp board. | Wiring |
| 4. Software | Install the Spinnaker SDK and FFmpeg, run Setup.cmd, open the workflow. |
Software |
Order matters: Bonsai cannot see the camera without the Spinnaker driver already in place.
- Spinnaker SDK 4.2.0.83 — download from Teledyne Vision Solutions. The version must match exactly; the download page defaults to the latest, so choose deliberately. An account is required, so this step cannot be scripted.
- FFmpeg — encodes the video. In a terminal, run
winget install --id Gyan.FFmpeg -e, then close the terminal so the next one sees it on PATH. This installs it for the current Windows account only; if more than one account records on this computer, run it from an administrator terminal with--scope machineadded. - Bonsai — run
Software\Setup.cmd. It downloads Bonsai and restores every package fromBonsai.config, and warns if Spinnaker is missing or the wrong version, or if FFmpeg is missing or cannot use Intel Quick Sync. - Open the workflow — start Bonsai, then File → Open →
Behaviour_Box.bonsai. Do not launch the workflow file directly: this project relies on compatibility patches.
Full detail, including camera settings, is in Software.
Configure the camera and experiment settings first — see Software. Then:
-
Clean the box with 70% ethanol or another disinfectant, and wipe it completely dry.
-
Connect the hardware, with the box still empty:
- 12 V power supply to the Harp Behaviour Board
- Rotary encoder to the Harp Behaviour Board (Port 2)
- IR LED strip power supply
- Camera USB cable to the computer
- Camera GPIO trigger cable to the Harp Behaviour Board
-
Open the Bonsai workflow. The camera preview only appears once the workflow is running, so it is checked after Start, in step 7.
-
Place the mouse in the box.
-
Fit the lid with the camera attached.
-
Minimise external light — turn the room lights off, or cover the box with black fabric (recommended).
-
Set the save directory, camera serial number, subject ID, session ID and trial length, then click Start. The camera preview starts updating about 5 s later: the Harp board only starts the camera's trigger pulses once the camera is ready. If no frame arrives within 15 s, Bonsai stops with "The operation has timed out." (see Troubleshooting). Bonsai has a black console window open beside it from launch, titled with the path to
Bonsai.exe; FFmpeg prints only errors there. Leave it open and do not type in it: closing it, or pressing Ctrl+C in it, closes Bonsai at once and ends the recording. -
Recording stops automatically at the trial length, saving a video and a CSV of the behavioural data. Bonsai itself keeps running, so press Stop before the next recording. The video can finish a few seconds after the CSV, longer on a busy computer: before closing Bonsai, wait until
ffmpeg.exehas gone from Task Manager, or the end of the last video is lost. -
Return the mouse to its home cage.
-
Clean the box before the next recording, checking the corners carefully — faeces are easy to miss.
- No live camera preview — check the locking USB 3.0 cable is connected, the correct Spinnaker SDK version is installed, and the camera serial number matches the connected device.
- "Cannot find driver CORMEM.SYS (memory allocator)!" each time the camera starts — Spinnaker is
searching for GigE cameras through Teledyne's GigE components (installed by an interactive
Spinnaker install), and their memory library needs a driver that only Teledyne's Sapera LT
installs. Bonsai waits on the dialog until someone clicks OK. The camera is USB3, so switch the
GigE search off once, with Bonsai and SpinView closed:
"C:\Program Files\Teledyne\Spinnaker\bin64\vs2015\SystemNodeConfig_v140.exe" EnumerateGEVInterfaces false. It persists across restarts (it is stored inC:\ProgramData\Spinnaker\Shared\GenTLSysReg.ini). To undo it, deleteGenTLSysReg.iniandGenTLIfReg.iniin that folder; running the same command withtruedoes not work. - Rotary encoder not responding — check the RJ45 connection to the Harp Behaviour Board and that the encoder is on the correct input pins.
- Recording stops at once with "The system cannot find the file specified" — FFmpeg is not installed, or not on PATH for this Windows account. Install it as in step 2 of Installing the software, then restart Bonsai.
- Recording stops with "Pipe is broken" — FFmpeg started but stopped encoding. At the start of a
recording, the black console window shows why, usually that Intel Quick Sync is unavailable on this
machine; run
Setup.cmdagain to check. Mid-session, someone probably typed in the console window (qstops FFmpeg). - Bonsai stops about 15 s after Start with "The operation has timed out." — no camera frame
arrived. The usual cause is the GPIO trigger cable between the camera and the Harp board (loose at
either end, or damaged); also check the camera's USB cable. The session folder holds only a
LogData.csvwith its header and no rows; delete it. Fix the cable, then press Start again. - Bonsai disappeared mid-recording with no message — the console window was closed, or Ctrl+C was pressed in it. The video up to that moment is kept and plays; the CSV loses its last second or so, and its final line may be cut short.
- Bonsai closed itself just after Stop — a rare crash while the camera driver shuts down (about once in 500 recordings in testing). Start Bonsai again. The CSV of the recording just made is complete, but its video may be missing its last seconds if ffmpeg was still encoding them.
- Preview or CSV window missing — reopen them manually, as below.
- Right-click the Logging node and select Show Default Editor...
- In the editor window, right-click the LogVideo node and select Show Default Editor...
- Right-click the SampleInterval node fed by Value.Image and select:
- Show Visualizer
- Bonsai.Vision.Design.IplImageVisualizer
- In the same LogVideo editor, right-click the SampleInterval node fed by the ExpressionTransform that builds each CSV row.
- Select:
- Show Visualizer
- Bonsai.Design.ObjectTextVisualizer
Both windows update five times a second rather than on every frame. Drawing all 50 frames a second takes CPU the recording needs, and the video and CSV still get every frame.
Tip
Do not close these visualizer windows by hand. Bonsai closes them when the workflow stops, and reopens them on the next run.
Released under the MIT License, which covers the printed design as well as the workflow and the documentation.
The five UclOpen packages in local_packages/ are redistributed under the BSD 3-Clause License and
the patched Bonsai.FFmpeg package there under the MIT License, and everything Setup.cmd downloads
stays under its own terms. See
THIRD-PARTY-NOTICES.md.

