Musical Box

This page last updated: 27 March 2026.

As a random Christmas stocking present in 2025, Santa brought Hazel a music box mechanism, henceforth referred to as "Hazel's plinky-plonky".  This turned out to be difficult to operate manually, so Rob motorised it.  Then there was a discussion of what form an Easter display for the front garden railway might take; we thought it might be nice to be able to change what was on display each day.  Combining the two, the obvious project to start in January 2026 was to make a "live" version of the Camberwick Green musical box:


 

The first occupant: Maxwell Walton's Shaun the Sheep from Sketchfab.

The sections below are:
The Blender files (with 3D printing instructions), scripts, source files etc. for this project are kept on Github.  Full and detailed assembly instructions can be found here on a sub-page.

Methodological note: since this was a complex development, when 3D printing throughout I began printing in PLA at 5% in-fill and often lowest detail, cutting out just the intricate parts in my 3D printer's slicer program and repeatedly printing/tweaking those parts to get them right without wasting time/plastic.  Only when I was sure everything was good did I switch to printing in the final ASA, probably 15% in-fill and, aside from the large parts, 0.1 mm step detail; ASA can tend to warp when printing large pieces without the print chamber or the room it is in being brought up to 40 C, which is a pain if you're sitting in it.

Requirements

The requirements were as follows:

Initial Ideas

A day's musing led to an AliExpress order for the following, total cost around £85:
I already had a Raspberry Pi Zero 2W (which will be the WiFi access point for the ESP32's) and a PSU board.  The proposition (and the many open questions) were as follows:

Segment Proposition:
  • The lid for each segment is driven, through a length of brass bar, by a stepper motor that is mounted in the "skirt" of the musical box; you will notice from the picture above that there is a skirt which sticks out somewhat,
  • the skirt also holds the stepper motor driver board and the ESP32 board mounted on a piece of veroboard,
  • the lid has a lip on the rear-most side which should cause the motor to detect a stall when the lid has fully opened: all the software has to do is count a fixed number of steps backwards from the stall position to the "closed" position,
  • it may be a good idea to add a couple of pieces of spring steel on the inside of the box, near the top, to create a switch that is closed when the lid is fully opened, otherwise it is possible that someone could obstruct the opening of a lid and cause the platform rising inside the box to crash into it; should a "switch is not closed" situation be detected, that should cause the box to re-start itself, effectively recalibrating what "open" is.

Questions:

  • Can the skirt be wide enough for all this gubbins?
  • Will the attachment of (a) the brass bar to the stepper motor and (b) the lid to the brass bar, be robust enough to work reliably over repeated stall detections?
Platform Proposition:
  • The rising platform inside the musical box fills the hexagonal shape and rotates with it,
  • beneath the platform is a scissor-lift, driven by the same stepper motor and electronics arrangement as the lid opening mechanisms.

Questions:

  • Can the scissor-lift provide sufficient height and still be robust enough to lift the kind of objects that need lifting (whatever those are) without a stall detection in the stepper motor driver part way?
  • Does there need to be a lip somewhere for the rising platform to hit at maximum height in order for there to be good stall detection?
  • How does the platform interact with the lip at the backs of the lids: do the lips slip between the edge of the platform and the walls when the platform is at max height or does the platform need to stop below them?  Probably the latter as "sliding between" sounds like it might defy reliability.
  • How is the object that is being lifted held in place on the platform?
  • Where do the electronics for the scissor lift motor go?
Base Proposition:
  • There will be a static, round, base at groud level, the centre of which will anchor the slip-ring that passes power up into the rotating section,
  • the six segments will attach to a hexagonal base that holds the other end of the slip-ring,
  • the hexagonal base will include six rubber wheels that support it on the round base, allowing it to rotate freely,
  • somehow, a conventional low-RPM geared motor (like those used in the Christmas conveyor belts) will drive the rotation of the hexagonal base
  • a dummy winding key won't be included: there would be too much temptation to try to use it.

Questions:

  • Exactly how will the rotational motor engage with the hexagonal base; maybe it could also be mounted in the centre?  Need to receive the slip-ring to determine this.
  • Where will the Raspberry Pi Zero 2W, a power regulator and likely a PWM motor speed controller, or at least a relay to control power to the conventional rotational motor, be mounted?
  • Will the plinky-plonky be attached to this or separate?  Attached would be better, since the music should be integral to what is, after all, a musical box.
  • How will the plinky-plonky's musical score (and the plinky-plonky itself for that matter) be protected from the elements?

Lord knows how much of this will work.

Components

When the components arrived I made 3D models of the stepper motor, the ESP32 board and the stepper motor driver board in Blender.  Then I whipped-up the shape of the musical box and scaled it such that it could be printed, whole, on my 3D printer's print plate: just shy of 250 mm across.  With this done, I tried positioning the components within the base of the box, and they did indeed, just, fit.

Components
Box
Fit

Phew.

Doors

The shape of the rotating doors was somewhat tricksie to get right: in the TV series they were able to fudge it in the stop-motion, whereas I needed them to actually work.  I created what I thought would be a good shape and exported to .stl a test consisting of the top of the box, the doors and pegs to hold the doors in place (all at a Blender scale factor of 1000 to get real size in millimetres).  These I printed in PLA (5% in-fill, fastest speed, no supports) to check that they would work.

Blender
Ready to
                    print
Printed

Here it is under test:
 
It worked, the only issue was the size of the hole in the middle.

Hole Explanation

The minimum hole diameter would be the diameter of the brass bar, 4 mm.  But that was two-dimensional thinking, captain.  With a step in height and some creative use of depth inside the wall I tweaked the design to have an overlap, eliminating the central hole (supports now required when printing).

Overlap
Unholy
Open

That looked rather elegant I thought, particularly when open.  Next problem was that I had thought I would put a lip on the tip of each door to stop it and/or to trigger a switch of some form but there was no clear way to do that: the tip now lands just where the rotor arm for the next door comes along and the curve of the door has to go well past the wall of the box for the doors to fit tightly.  A bit like Tesla cars: overcomplicated doors always cause development delays.  Then inspiration struck: all I needed was a short notch sticking out of the end of each door, with a corresponding indent on the other side in order to tile.  This notch would catch on the rear edge of the door in front when a door was fully open.

Notch
Open

Not triggering an electrical contact, of course, but hopefully we won't need that since the door now has a stop at both extremes and the stepper motor driver hardware includes stall detection.
 
Note: it would have been possible to arrange the notches such that, when fully open, the doors formed that pleasing perfect circle (picture on the right further up), however I couldn't find a way to do that and also ensure that a door would always hit a stop even if the door ahead of it failed to fully open for some reason, there would always be a danger of it slipping past, so I stuck with safety.

Lift

The only other significant unknown was the lift.  Browsing Thingiverse I found Lifting Table by Michael Burger (original files here in case they disappear from the source).  It was very well described, unusually including detailed assembly instructions, and the lift expanded from 30 mm to 120 mm in height, not far off what I needed (internal box height currently 131 mm).  I decided to just build it to see how it behaved.

I threw it at the printer to print in PLA at highest (0.1 mm layer height) detail; not sure it needed that, but since I had an overnight run to spare it did no harm.  15% in-fill, and as Michael Burger says in his instructions, no supports required: marvellous!

Lifting
                    Table by Michael Burger
Ready to
                    print
Printed

It took less than an hour to build.  Here it is in action:
 
It was a very good design indeed and fitted easily inside the box outline I had printed for door testing.

Fit

The M6 screw I was using in the middle was not threaded all the way along, hence the rise in height was slightly short at just under 90 mm.  Ideally I would like to sink the lift into the base of the box, so that its platform was flush with the inside-bottom of the box when fully retracted, and have it rise the full 131 mm to the top, meaning I would need to get another 41ish mm of lift.  I didn't need any particular strength in the lift, of course: I tried disassembling it and pushing the scissor up to the highest it would go but that only got me another 30 mm (150 mm from 120 mm).

Extra Highest

Checking the fit inside the box, and accounting for the need to mount a stepper motor on the back to replace the handle, I had about a 22 mm gap available at the front.  The maximum height of the four triangles of the scissors was around 23ish mm (measured centre to centre 27 mm) in order to provide the overall 90 mm lift: I'd need another 10 mm on the height of each triangle (131 - 90 = 41, 41 / 4 = 10) to get my desired lift of 131 mm.  If I dumbly scaled everything up to achieve that increase, the strut length would increase by 26 mm (from twice 35 mm to twice 48 mm, see diagram below).  To keep the increase below the 22 mm available, say to a more comfortable 20 mm (i.e. the strut 92 mm long, 20 mm more than the existing "twice 36 mm") and achieve the same height, the scale factor would be 1.28 (92 / 72) and I would need to bring the rear edge of the slot back by 6 mm (√(452 -372) = 26, 26 x 2 = 52, whereas a base of 45 x 1.28 = 58); I thought that should be tolerable.

Margin
Triangles Scaling
                        up Scaling
                      down

I imported the Lifting Table files into the Blender file (at a Blender scale factor of 0.001, since Blender's native units are meters), made the modifications, including changing where the knob attached into a mounting point for one of the stepper motors, exported them to .stl again (at a Blender scale factor of 1000 to get 1:1 in millimetres) and printed/assembled them for another test.  Assembly now needed a 65 mm long M6 hex head bolt instead of a 45 mm long one; at these lengths they don't come fully threaded so an M6 die was applied to extend the thread (several times with the die tightened up to ensure a smooth run) and 3 mm was cut off the end to stop the bolt fouling the side of the box.  Oh and two M2.5 12 mm pan head screws to attach the stepper motor; these are in addition to the eight M3 10 mm and four M3 15 mm hex head bolts needed for the design by default.

Motor
Thread
Assembled

Note: later I made a circular hole in the base to let cables through from the slip-ring and a circular indentation in the underside of the top where I could glue a 20 mm diameter niodymium magnet to hold whatever is being lifted in position.  Neither of these holes is centred on the lift!  They are centred on the hexagonal space in which the lift is mounted somewhat offset.

Now of course, with the stepper motor in place I needed the stepper motor driver working before I could operate the lift.  But first, some music...

Music

The Camberwick Green music needed to be played on a plinky-plonky: I obtained one identical to the one that I had bought Hazel for Christmas from eBay.  Hazel transcribed the tune: first it had to be transposed into the key of C, then its range had to be reduce to fit the two octaves available (in the original tune the base and treble clefs are too far apart) and finally the timings had to be sorted: we thought that quaver spacings were about as short as we could go (but see later), which made the trill half way through the largest stumbling block.  Once she had an initial version of the tune she created an image of the punched strip, along with dimensions, as an SVG file:

Tune
Measurements

Note: treble clef sign by juicy_fish on Freepik.

I created a Blender file in which I followed a procedure along the lines of the one that made the conveyor belts for the Christmas display but now with hole punch extras (also described in pictures below).  Apologies for the verbosity but I thought it was important to document this bit comprehensively.  Note: the biggest belt I could successfully print on a Prusa MK4S was 620 mm long, 197 mm in diameter.

Create a strip of the right length:

Punch it with notes:

Items added later:

Make it into a punched belt:

Imported
Rotate
Rotated
Scaled
First note
Notes
ExtrudedDistance
Boolean
Boolean
                  applied
Curve
Direction
Meeting
                    [not] Punched
                    belt

During development printing was essentially in PLA at highest (e.g. 0.1 mm) detail, 100% in-full, no brim or supports.  However, with the vanilla print settings I found that, on the layers with many holes, the slicer program decided to move the head more optimally (see blue motion paths below) and, where it did so, print faults appeared.

Ready to
                  print
Printed Faults

Consulting on the Prusa forums, I was advised (thanks jan.d.slay) to reduce the print speed to a maximum of 30 mm/s and increase the fan speed to 100%, which fixed it.


To fit the belt to the plinky-plonky just for a quick try, I undid the two screws on the right, allowing the bracket that is holding the handle to be removed.  No need to entirely remove the bracket (or the screws for that matter), just angle the top of the bracket away from the rest of the machine enough to lift out the top roller, leaving the bottom roller in place (otherwise one has to get both rollers back into place afterwards, which is more difficult); don't lose the tiny washer on the end of the top roller!  The punched belt can then be eased into place [the right way around], sliding underneath the locating pin, the top roller slotted back into place and the screws tightened once more.  This is not how music is intended to be fed in (see next) but with the punched belt held in place by hand it is good enough for a quick tune-check.

Mechanism
Disassembled
Installed
Reassembled

For a proper installation the bracket and front rollers need to be removed entirely and then there are two more screws that release the rest of that same side.  The only problem is that, once the punched belt is slid underneath the sprung plate, you can't get at the screws to reinstall them, they are underneath the margin of the belt.  I worked around this by using the hole punch that came with the kit to punch two holes in the margin of the belt to get a screwdriver through.  All very ticklish but not impossible.


Part
                  disassembled
Blocked
Punched
Unblocked

The big question is, what did it sound like?
 
The main issue was that it was missing notes.  Initially I thought this was because of the accuracy of manual hole creation.  Having looked into the SVG format a little, I decided to spend a day creating a Python script that could be given a text file of notes and would produce the SVG file, dead accurate.  First I fed it just all of the notes in the scale, quaver spaced and printed a quick test strip.

Blender
Ready to
                  print
Printed
 
That was good: the issue with the last note was only because there was insufficient lead-out on the strip, it was being released as the last note was played.

I fed a text file of the tune that Hazel had composed into the script: there were at least four places where semiquaver spacings of adjacent notes were required and the last one in particular was going to be an issue as it was on the same note, so the two note circles would likely coalesce during printing, or at the very least be a weak spot.  In an attempt to accommodate this, I slowed things down by 3/4, increasing the distance between notes (the speed of rotation would have to increase to compensate) and reduced the hole diameter to 1.8 mm.

Notes Smaller
Printed

Would it hold?

 
Maybe a slight improvement but still missing notes.  It was only then that I understood the fundamental mechanical limitation of the plinky-plonky: the little cams on the lower roller (see picture below) catch on the holes to "ping" the note and the cam has to travel a quarter turn to do that, there being four prongs on each cam arranged equally.  The same note cannot be played again while the cam is rotating as there won't be a prong there to capture it, which leads to the fundamental "not more than once in a crotchet beat" note repeat limitation.

Cams

I updated the Python script to spot this and the situation occurred eleven times in the composition, mostly on the G in the first octave, which is of course the underlying beat of the tune.  The only fix for that was to decrease the speed scale factor when creating the belt to 0.25 (since there is in fact a semiquaver-distanced double G in the tune), hence increasing the space between notes, and quadruple the speed the plinky-plonky is cranked at.  However, then the belt would be at least 1232 mm in circumference, which would be somewhat unwieldy and would require a join since it would be larger in size than my Prusa MK4S 3D printer's print bed.  Removing the semiquaver and just halving the speed scale would fit and might be manageable.

This might not be the whole reason for the missing notes of course.  I decided to take a step back and created a belt of exercises, ones that did not contravene the crotchet repeat limitation, to test that everything was otherwise mechanically sound:

Exercises

Using all default parameters (2 mm hole diameter, speed scaling of one) I created a belt of these exercises, ran it through the plinky-plonky, videoed the cams in action and analysed the video note-by-note for errors :

 
The good news was that the errors were consistent and could be traced back to gunk from the printing process left in the hole, preventing a prong catching properly.  All I had to do was look for these holes and tidy them up with the hole punch supplied with the plinky-plonky.

Gunk
Punched

I removed the semiquaver and printed the tune again applying a scale factor of 0.5, belt circumference now just over 600 mm, ran it and watched the cams to be sure that all holes were clear, fixing any that were not.

Semiquaverless
Blender
Ready to
                  print
Printed
 
I checked with Hazel and I had transcribed some of her notes wrongly towards the end, which would explain why it sounded a little different there, text file corrected (and later there was a final version).  Enough for now, this problem was solved, onwards to motorisation.

Stepper Motor Control

The TMC2209 chip on the stepper motor driver board was controlled via UART, hence I had paired the ESP32 board with it to provide the control interface for each motor.  I needed to design a kind of stepper motor control unit, including both boards, which I could use with the all of the stepper motors.  Larger than that though, architecturally I wanted to achieve something like this:

Architecture

In words: a Raspberry Pi Zero W controls the musical box's rotation motor directly and provides a Wifi Access Point for eight ESP32s.  Each ESP32 talks over UART with a stepper stepper motor driver to control a stepper motor: one for the plinky-plonky, one for the lift and one for each door.  The communication between the Raspberry Pi and the ESP32s is as simple as possible: OTA software update, request start motor, request stop motor, indicate that motor has stalled, indicate that motor has stopped.  Putting this many wireless things in close proximity may cause issues of course: keeping the transmit signal strength very low, sequencing, retries etc. may be required.  However, the advantage is that Wi-Fi clients do not need to be wired to the Pi and so can be in the rotating part with just a two-wire slip-ring providing power.

First I needed a hardened Pi.  I used the Raspberry Pi Disk Imager to load the latest version [Trixie] of headless Raspbian onto an SD card and put that into a Raspberry Pi Zero W (1.1).  As I did with the Mother Hen, I followed the instructions here to make the file system read-only but this time I documented my process in pi_read_only_file_system.md in case the instructions should ever disappear from the source.  I tried to set the Pi up as a Wi-Fi access-point, which should have been a one-liner, only it turns out that in the latest Raspberry Pi OS (Trixie), any attempt to add security to a Wi-Fi access point fails: I created a Github issue and resolved to add security later through MAC address filtering.

I brought up one of the little ESP32 boards; a few things to note:
Anyway,  in a few days I had the ESP32 connecting reliably over Wifi to the Raspberry Pi Zero W and doing OTA updates if there was a later binary (software for the ESP32 (using ESP-IDF in C) and the Raspberry Pi (in Python) here).

Next I attached the TMC2209 stepper motor driver board's UART to the ESP32 and got that running.  It was at this point that I found the mistake I had made a month ago: I had purchased unipolar stepper motors, which cannot be driven from the TMC2209 chip.  D'oh.

Stepper motors are essentially of three types; I had purchased a load of the one on the right:

Types

It was Chinese New Year, no AliExpress for a few weeks, I had to find a way.  I found this YouTube video, apparently one of several, where a nice gentleman took the plastic casing off the back of a five-wire stepper motor and cut the PCB track that was joining the two centre taps to make it a bipolar stepper motor of sorts.  Easily done, noting to lever the case off from the cable/spindle end; the other end is where all the tiny wires are, you will likely break them if you insert a tool there.  When done there should be ~30 Ohms resistance between blue and yellow, ~30 Ohms resistance between brown and black, no other connectivity between those wires.  The red wire can just be desoldered.

Casing
Remove
Snip
Snipped

The problem was that the motor was designed to be operated on a half-coil basis and the resistance it presented to the driver on a whole-coil basis was high (30 Ohms per whole coil, versus just 8 Ohms for a NEMA17 stepper motor).  Also these motors were 64 steps per rotation with built-in 1:64 gearing: 4096 steps per rotation at full step resolution. The net effect was that the motors would not rotate quickly, no matter what step-rate I specified.  I tried supplying the motor drive direct from 12 V, rather than the down-regulated 5 V, but that didn't help: one revolution in 8 seconds, about 7 RPM, was as fast as it would go.  That would be fine for the doors, under 1.5 seconds to travel the required 60 degrees; I'd need to use a different motor for the plinky-plonky and the lift.

Then I tried to get the stall detection feature of the TMC2209 driver chip working and that was not able to provide stable results with the high-resistance stepper motor either.

Explanation: as a motor stalls, the back-EMF generated by its rotation drops.  This would normally cause the current in the windings driving the rotation to increase but the TMC2209's chopper driver actively limits current to a set value.  The TMC2209 detects the stall by sensing the extra effort required to regulate the current against the collapsing back-EMF.  However, high-resistance motors typically have high inductance, which slows down how fast current can change.  This makes both the TMC2209's current control and its stall detection like a walk through treacle: the signals are too sluggish and muddled to be useful, the TMC2209's control algorithms don't work.

Not necessarily a disaster, the motor's behaviour was such that it would just stop if it hit something, but ideally I would like to be able to detect a stall so that I could recover the situation.

I purchased a variety (there weren't many) of small bipolar stepper motors to try out, ones that didn't have to come from China.  While I was waiting for them to arrive I addressed what had been another worry, namely RF issues with devices so close together.  I bought a ten-way USB hub, ten male-to-male USB-C to USB-A adapters and plugged in ten of the ESP32 boards.  I flashed all of these boards with the current software version, then I made a version of code that would ping the Raspberry Pi access point forever (1000 bytes every 100 ms with a 1 second timeout), flashing the on-board blue LED every 10 seconds but switching the on-board blue LED on permanently if a ping was ever lost.  I uploaded this binary to the Raspberry Pi and reset all of the boards: they downloaded the new version (less than a second for a 1 Mbyte file) and updated themselves in pretty short order then sat there flashing away.  Having started them running at 20:00 on Saturday (I know how to party), 12 hours later on Sunday morning:
 
Good.  And I could tell that none had reset by looking at the Raspberry Pi log which showed that none of them had been in contact to check for a FW update, something they only do at boot; so a stability test of sorts as well.  Of course, this arrangement didn't include a load of small coils pulsing away.

The only small bipolar stepper motor I could obtain six of in shorter order and not-from-China was a really tiny one, just 8 mm in diameter and 10 mm long, very difficult to solder wires onto and gawd nose what the thread was on the fixing threads (is there an M1 thread?).  I measured the coil resistance at 22 Ohms, so not bad, but it was designed to operate at 3 V and the TMC2209 wouldn't work with a 3 V supply.  I tried it anyway at 5 V and it worked...

Tiny!
 
...but got rather hot.  Given how difficult it was to work with I decided I didn't want the hassle of mounting six of them.

It occurred to me that I should try driving the unipolar motors in the way god intended, i.e. with a ULN2003 driver board.  This is a very simple thing, basically four transistor drivers, four inputs, four outputs that one connects to the ends of each coil, the common centre of each coil connected to the supply voltage: it is up to the controller to roll the directions of the magnetic fields of each coil, such that the motor rotates, by controlling the four pins.  The ULN2003 is a traditional dual-in-line 16-pin IC, so the driver boards are a bit on the large side to be mounted underneath the rim of the Musical Box to operate the doors, but I could possibly employ the motors in rotating the musical box and maybe even driving the plinky-plonky, if they would go fast enough.  In those cases I would need to drive them from the non-real-time Pi but pigpiod came to the rescue with its gpioWave*() set of functions accessible from Python.  I created a Python script to try it out:
 
Conclusion: the 24BYJ48-034 motor converted to bipolar operation and driven by a TCM2209 really is the best approach for the musical box doors.
I had more luck with two other small-but-not-that-small bipolar motors, see picture below: the one on the left is a really slim, round, NEMA14 (36 mm x 12.5 mm) from stepperonline.co.uk (I thought Stepper Online was Chinese but they appear to have a UK web shop) which ran at a maximum speed of three revolutions per second (180 RPM), while the one on the right is the ridiculously cute NEMA8 (20 mm x 33 mm) from the Pi Hut which ran at a maximum speed of just under six revolutions per second (350 RPM), though is 3.7 V rated so got a bit hot when run at 5 V (but see below).

More steppers

Measured coil resistance was 17 Ohms and 6 Ohms respectively and, on a quick test, both looked as though the TMC2209's stall detection might work.  The really slim round NEMA14 one should be OK to power the lift, the mini NEMA8 I can use to drive the plinky-plonky and, since it was so cute, I ordered another to drive the rotation of the musical box.

In fact, after some deeper understanding of stepper motor operation, now mostly embodied in the software, below is a video of the lift being driven quite happily by the NEMA14; lift capacity, in case you were wondering, 40 baking beads or 90 gm.
 
The important part of my recent stepper motor understanding was that the rated voltage of a stepper motor is only meaningful in ye olde ULN2003 world: it is the DC voltage that would provide the rated current if you slapped a DC voltage across one of the motor's coils.  A lower value is better, 'cos that means a lower coil resistance and probably a lower coil inductance.  Once you get into the chopper-driver world,  3.7 V doesn't mean supply the stepper motor driver with 3.7 V; 24 V is more conventional.  Chopper drivers in the form of the TMC2209 and their ilk are designed to provide programmable drive currents to the motor windings irrespective of voltage, 500 mA in the case of this particular NEMA14.  Higher voltages give the chopper driver more flexibility: I needed to supply the TMC2209 board from the 12 V source voltage rather than a down-regulated 5 V.  Then all I had to do was understand how to program the TMC2209 to provide the required current, which was not straightforward at all (I had a few heated arguments with DeepSeek about it, DeepSeek even apologising for having skim-read the data sheet whereas I had read it enough times to have spotted a few of the important bits :-)).  Now done though.

Stepper motors sorted.

Rotation

Aside from the motor, this required two things: a slip-ring of the correct size and some gears.

The 20 Amp slip-ring I had originally ordered was a bit of a beast, fully 40 mm deep, which would require the musical box to be raised up in the air somewhat.  Since I would be providing plenty of mechanical support, I found a smaller slip-ring, just 16 mm deep.  As to the gearing, I fired up Gearotic, made myself a pair of standard gears with a 10:1 ratio and exported them to .stl.  I imported these into the musical box Blender file and scaled them such that the large wheel fitted nicely inside the base of the musical box (80 mm diameter inside the 138 mm diameter base, a scale factor on the imported .stl files of 0.00025); this made the small gear just over 10 mm in diameter.  I punched the centre out of the large wheel to make a ring and was hoping I could then figure out how to twist it in Blender so that the teeth would face upwards.

Slip-rings
Gearotic
Blender

I failed.  Instead I dumped the large wheel, went back to Gearotic, created a rack of length 120 teeth to go with the pinion, imported this into Blender at the same scale and, similar to when creating the belt for the plinky-plonky, used a Curve modifier with a Bezier Circle of the correct diameter to form the rack into a circle.  That kind of worked except that the complexity of the .stl object created by Gearotic caused considerable weirdness (see last picture below).

Rack
Complexity
Rack curved

I sliced off just one tooth from the rack, decimated it by a factor of 0.04 (i.e. 25 times less complex), making it possible to edit, bisected and then mirrored the tooth to make sure it was symmetrical, applied an Array modifer to get a rack, checked it against the original to be sure I had not made a mistake, then applied the Curve modifier with the same Bezier Circle (that had already been scaled correctly above).  No weirdness this time: phew.

Tooth
Decimated
Cleaned and
                  bisected
Mirrored
Arrayed
Checked
No weirdness

To make the teeth line up properly I applied the same Curve modifier to the pinion gear (re-boring the central hole afterwards to make it straight) then arranged three of the pinion gears symmetrically around the stand that was to go beneath the musical box, rotating on 20 mm lengths of 4 mm diameter brass bar supported by 4 x 8 x 3 mm bearings.  I ran off a test print,  the pinion gear and the circle of teeth printed in polycarbonate for hardness, the circle then glued into place with cyanoacrylate adhesive.

Curved
Ready to
                  print
Printed
Pinion

If you look closely the pinion gear is somewhat at the limits of the resolution of my Prusa MK4S FDM printer, it has printed a bit raggedy: I switched to printing those (at normal, 0.05 mm layer height) on my Prusa SL1S Speed resin printer in the Siraya Tech Build resin that I had found so useful when printing much tinier gears for the auto project.

Ready to
                  print
Printed
Better
Stand
Base
"coggy"

That worked but when the base was placed on the stand and rotated the motion felt kinda "coggy", not as smooth as I would have liked; I tried printing the circular rack on the resin printer as well, in two halves as it was too wide to print in one piece.

Ready to
                  print
Printed
Glued

And that was the business, a lovely smooth rotation.  It had been worth taking the time to get it right.

The last thing to do was to add the motor.  I tried fitting the cute NEMA8 stepper motor but its body length and shortish shaft meant that I would have to add a couple of gears between it and the rack to make the positioning work.  While playing with different stepper motors I had come across a PM15S (30 Ohm coil resistance, rated current 160 mA), which was only 15 mm in diameter and 12 mm deep, easier to fit.  I spent some time making a neat job of it, and it did work:

 
However, I worried whether the tiny motor would still be enough with a fully-loaded thing above it.  Weighing the various sample prints I had made of all of the parts that would need to rotate, it came to 700 gm, plus a thing to rise up out of the musical box, make it 800 gm, around two ingots of lead.  The poor little motor could take nothing like that.  Back to the drawing board, this needed a proper, unfortunately large (42 mm x 42 mm x 20 mm), NEMA17 stepper motor.  There was nothing for it but to let the motor lie outside the circumference of the musical box; of course the plinky-plonky was already separate, so there was some precedent, and to be more faithful I tried to make the spindle connecting the motor look a bit like the key that winds up the musical box.

Blender
Ready to
                  print
Printed

I ground quite an extreme flat into both ends of the 62 mm length of 4 mm diameter brass bar connecting the motor to the drive pinion, to meet a similar flat in the pinion gear and the spindle connector.  The spindle was held to the flat on the motor with a 6 mm long M3 hex grub screw.

Flat
Grub
Fitted

And finally, here it is running with the motor set to 500 mA (rated 1 A) and TSTEP 244 to revolve once in 10 seconds, as in the original video:
 

Sensors

I was initially planning to do without sensors but then I thought that, even with the best stepper motor control, the starting position of the belt in the plinky-plonky might shift over time.  I had a QRD1114 infra-red LED/sensor lying around and gave it a quick try in the Sparkfun application circuit:
 
That worked far better than I was expecting: with proper design of reflective and non-reflective surfaces the QRD1114 could provide a digital signal.  Here is the Sparkfun schematic update for 3.3 V logic (which the ESP32, and the Pi for that matter, use) and a sensor wired up: pins 2 and 4 common to ground and the 150 Ohm resistor nicely encapsulated in-line with 3 mm heat-shrink (subsequently I did the same with the 10 kOhm resistor):

Schematic Wired
Heatshrinked

I spent a day adding sensors to the lifting table (see the lifting table assembly instructions).

Then it occurred to me that I could, just, fit one of these sensors into the rim of the musical box and, with the right paint, detect door open.  I gave it a go (software version here):
 
Very happy with that.  Time to build the final thing.


Integration

And so to integration of all this stuff.  Printing instructions for the 3D printed parts, as well as the parts themselves, can be found on Github.  Assembly instructions I have moved to a separate page as they are quite detailed.

Assembly of the stand and the base were obviously the most tricky, many days of careful wiring and testing.  The most significant thing, though, was that I could not get the doors to work: one door would work but the moment I went to two they didn't move, and I couldn't tell why: all of the things I needed to poke at to investigate the problem were now hidden within the sides of the box.  Since I was thinking of using a separate layer for the decorative part anyway, something I could 2D print on photographic paper or some such, I removed the sides entirely and instead made support columns, which had lots of advantages:
Columns
Ready to
                  print
Printed

After all that, it turned out that the reason the door motors weren't working was that the TMC2209 does clever stuff (StealthGuard and StealthChop) to reduce noise and current consumption but those things don't work well at very low speeds, which is what I needed for the doors.  I did eventually figure it out, and then had to use the spreadsheet provided by the manufacturer to get a detailed configuration that brought the resulting cricket noise (now that all the Stealth had gone) down to a bearable fast tick.  Still, the physical design change was a good one, worth the detour.

A few changes resulted:

Note: when it was necessary to separate and then recombine the upper (i.e. rotating) part of the musical box from the stand, it was best to do so with the lift at a highish position: for instance, if the lift was running its up-down-from-boot sequence, cut the power when the lift was near the top; this way there was nothing in the way of the cables coming up through the slip-ring on reassembly, all you have got to do is look in the gap between the stand and the rest of the box to make sure the cables coming out of the top of the slip-ring do not get trapped.


Decoration

We only get one rather fuzzy look at each side of the musical box during the opening sequence:

1
2
3
4
5
6

Zooming in on the faces:

Zoom

All a bit fuzzy.  There were some tighter shots in the close-up of the "character of the episode" coming up out of the box that caught the very tops of the sides and suggested the following:

Then, while searching the internet for other views, we found Mark Adams' YouTube channel, on which he has a very short video that shows off his most excellent 3D design of a Robert Harrop Camberwick Green musical box (a few of which can be found on eBay).  In the video he not only showed the sides:

Adams

...but he included a link to a .zip file of the .stl files for use "as is" (copy here in case it disappears from the source).  My hero!  The important bits were the two designs for the sides, which are then painted in alternate background and foreground colours and a white/pink/yellow set of flower colours, making six different panels, and the scrolls for the slope at the bottom.  I imported these into Blender, modified them slightly to fit my form-factor and made panels of them with the decorative surfaces raised; that way they were trivially easy to paint.

Imported
Modified
Ready to
                  print
Printed

By this time I had also made a 1 mm thick wrapper that folded very nicely around the now open sides, no glue required to keep it in place.  This had to be printed in PLA as ASA just wasn't able to keep the thin sides straight enough (see picture below), so I printed the floral designs as 1 mm thick sheets of natural ASA (to take paint more easily) that I could glue on top; these will hopefully protect the PLA.  I followed the same principles when creating the rest of the decoration: separate thin sheets that could be held in place removably, allowing access for maintenance or allowing re-use if I ever needed to upgrade any of the more complex innards.

Paint-wise, on the background colours, for orange I had Hycote Peugeot Seville Rouge Sevillan spray paint from our local automotive shop, left over from painting the chicken (always sounds like an euphemism to me, probably any phrase involving a chicken does) and we chose Hycote Rover Brooklands green spray paint for the dark green.  Highlight colours were then white (Humbrol 34), BR signal yellow (Phoenix Precision Paints P134 (Dull), which I happened to have left over from the DMU project), red (Humbrol 60) and green (Humbrol 101), the latter two as used on the elves and the storm troopers.  I spent a happy day painting.

Wiggly Decoration
Painted

The large panels were attached to the black ASA wrap-around with sticky pads.  The trims with the semi-circles and the decorative plates for the slopes I was going to glue to the hexagonal strips you can see in the pictures above but the strips were a bit weak so in the end I made short bracket pieces to glue each individual semi-circular trim to the slope piece above it and attached the lot to the body with double-sided sticky tape: really need thin tape for this to avoid the trim fouling the opening doors.

Sides
Trim
Bracket
Decorated

Decoration done.

Running

Finally, there was running the whole thing.  I spent several long days on the software, creating a communications protocol between the ESP32s and the Raspberry Pi that carried commands to the ESP32s, responses and indications back from them, making sure that log messages from the ESP32s were copied to the Pi for visibility, all of this done over TCP sockets.  I learned a lot about how to use DeepSeek to write the bits that I didn't care about but that needed to exist, the "leg work": creating a parser to allow the protocol to be driven from Python on the Pi , capturing the log messages on the Pi, writing a rather spiffy web UI etc.  Unlike during the development so far, where I had separate images for the ESP32s, compiled differently, I could compile a single "production" image and differentiate operations at the Pi end.  Most importantly, the Pi could synchronise/orchestrate operations.

Web page

I needed to make the musical box look nice when things were coming up on the lift: I made a very thin flat hexagonal lifting plate to put things on that would hide some of the gubbins inside the lift (see also note below) and a 0.5 mm thick insert (thickness later increased, see note below) that would fit within the sides, between them and the lift, for the same purpose.  It is really quite important that this insert is not wiggly: you can see in the first picture below that the first one I printed was a tad wiggly, causing it to rub on the lifting plate and either make a horribly rasping noise or, potentially, stall the lift.

One lifting plate was printed for each thing that would come up out of the box; at first I glued a small magnet to the middle of it, aligned with the magnet on the underside of the top of the lift (later I stopped the gluing, another note to see below), then the thing to be lifted out was glued to the plate.  Hence the video at the top of this page.

Inside
Plate
Shaun

Notes On Running And Improvements For Next Time

A few faults occurred during the first week of running the musical box in the front garden railway during Easter 2026:

Damage

A couple of larger improvements came to mind after I had finished:


Back to Meades Family Homepage