Requirements
The requirements were as follows:
- the box should be 3D printed (obviously); each of the six
segments should probably be printed separately as they would
be identical,
- the mechanism needed to be safe against little fingers,
- the whole thing needed to be sufficiently weatherproof to
survive [under the yew tree] outside in the front garden,
- the music would be the Camberwick Green music, transcribed
to run on Hazel's plinky-plonky,
- the thing that rises out of the musical box would need to
be changeable and also securely held in place,
- the musical box should run from a 12 V power supply,
- probably the most difficult part: the entire mechanism
must be reliable.
Initial Ideas
A day's musing led to an AliExpress
order for the following, total cost around £85:
- eight small
5 V stepper motors (24BYJ48-034): one for each
segment, one for the lifting platform and one for the music;
these should be relatively silent and as controllable as it
gets,
- eight stepper
motor driver boards (TMC2209 V1.3),
one for each motor; this stepper motor driver chip includes
stall detection hence should be able to be stopped when an
obstruction is reached,
- eight ESP32
boards, one for each stepper motor driver board; these
are Wifi and BLE enabled, hence no need for complex wiring,
- a
20 Amp, 3 channel, slip-ring to get power to
the rotating part of the box,
- vero board and 0.1" pitch socket strips with which to
mount the electronics.
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:
 |
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?
|
 |
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?
|
 |
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.
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.
Here it is under test:
It worked, the only issue was the size of the hole in the
middle.
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).
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.
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!
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.

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).
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.
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.
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:
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:
- create an object representing 1 mm of the length of
the punched strip (i.e. 41 mm wide, 1 mm long,
0.3 mm thick, i.e. just a few strands of 3D printer
filament thick),
- add an Array modifier to this object with Merge set to
0.0001; this is the punched strip template, I renamed it to
"_Punched Strip Template",
- make a copy of this object and name it "Punched Strip X
mm", where X is the length of strip required in millimetres
(e.g. 300), then hide "_Puncher Strip Template" to get it
out of the way,
- set the Array modifier to the size of strip you need in
millimetres-minus- one (so a 300 mm long strip would
need an array modifier of 299),
- apply this Array modifier; you now have a 300 mm
strip but with no tune,
- in preparation for the next bit, switch to Edit mode on
the strip, select the bottom left-hand corner, set the 3D
cursor there, switch to Object mode and set the origin of
the strip to the 3D cursor, then move the strip to be at the
world origin.
Punch it with notes:
- File -> Import -> Scaleable Vector Graphics the .svg file of
the tune: this will give you a collection containing a load
of curves that make the image; it will look like a smeared
thing (see first picture below): don't worry, that's fine,
- the origin of the imported curves will be at the world
origin, which is where your strip has its origin; to line
the imported tune up with your strip, set the 3D cursor to
world origin then select the entire imported curve
collection and rotate it by -90 degrees about the 3D
cursor in the Z axis (see second and third pictures below),
- with the curves still selected, scale them in the X/Y
axis until they fit the width of the strip; don't worry if
they go over the length when you do this (see first picture
on the second row below),
- in the Blender object selection box, select the curve at
the top of the imported SVG collection and, while looking at
the curves in the view port, scroll down the list until you
find the first curve that represents a note on the strip
(see second picture on the second row below); delete
everything in the imported SVG collection that is NOT a
note,
- you should now have all of the notes (see picture on the
third row below),
- select all of the notes and Object->Convert->Mesh,
- select the first not in the list, then SHIFT-select all
of the others and CTRL-J to join them into a single holy
mesh,
- switch to Edit mode, press A to select all vertices and
extrude the mesh in the Z axis: the notes should extend
through the strip below (see first picture on the fourth row
below),
- press A to select all vertices again and move them up on
the Z axis so that their tops are slightly above the strip,
i.e. they definitely go through it.
- this is a good time to check alignment: click on a part
of the lowest note, CTRL-L to select all of it and check
that its median position is exactly 6.5 mm from
the edge (see second picture on the fourth row below); if
not select all of the mesh and shift it to make it so,
- switch to Object mode, select the strip and add a Boolean
difference modifier with the extruded holes: this is the
tricky bit, the Boolean modifier often doesn't work
properly, select the punched strip and, if not all holes are
outlined in orange, you might need to CTRL-A apply all
transforms to both objects, you may need to move the holes
object up in the Z axis a little, or grab the punched strip
and jiggle it along the length axis a little, you may need
to Decimate the holes object to make it simple enough (I
used the fast-mode Boolean algorithm, decimated the holes
object by 0.3 and did a little length-wise jiggling), etc.,
- once the Boolean modifier can be seen to have worked on all
the holes (select the strip and all of the holes should have
an orange ring, see picture on the fifth row below), apply
it (see picture on the sixth row below) and hide the holes
object to get it out of the way,
Items added later:
- I later added a two-hole punch for holes in the belt to
allow access to screw holes in the mechanism, which needs to
be positioned somewhere on the side of the belt nearest the
winding handle and Boolean differenced with the strip,
- I also made a square punch to make a hole in the opposing
side of the belt which will be above a light sensor in the
final design; this needs to be positioned about 55 mm in
front of the first note (so probably at the end of the strip
by the time it becomes a belt) and Boolean differences with
the strip in order to stop the stepper motor once a tune is
completed.
Make it into a punched belt:
- switch to Object mode, select the punched strip and set
the origin to "centre of volume",
- move the 3D cursor to the origin of the punched strip;
this will ensure the curve about to be created has the same
origin,
- add a Curve -> Circle with radius matching the length
of the punched strip you require: 2πr is the circumference,
so a 300 mm punched strip would have radius
47.74 mm (see picture on the seventh row below),
- go to the Data tab for the curve and give it a resolution
that matches the number of millimetres of length (e.g. 300),
- select the punched strip and add a Curve modifier with
the circle you just added as the Curve object, then fiddle
with the axis settings until you get a belt shaped object,
- VERY IMPORTANT: make sure the music is the right way
around! Take a look at your original SVG file and
establish in your mind the difference in the note pattern at
the start versus at the end, then look at the pattern you
have on your punched belt and refer to the first image on
the last row below: if, like me, you have the end of
the tune being fed in rather than the start (so the Curve
modifier has curved the punched strip around the outside
rather than the inside), disable the Curve modifier for a
moment, rotate the punched strip through 180 degrees
about the appropriate axis, then re-enable the Curve
modifier and check again; the belt can be inserted either
way around of course but then you need to make sure that the
low notes are at the bottom.
- if you can see the join in the punched belt (see second
picture on the last row below) then select the Bezier circle
and scale it in the X/Y axis until the ends meet,
- apply the Curve modifier and, from 3D printing tools,
Solid -> Make Manifold (this should join the ends) to
complete the punched belt (see last picture below);
sometimes Make Manifold misbehaves, in which case it should
not be difficult to make the object manifold manually,
- export to .stl
at a Blender scale factor of 1000 (to get millimetres).
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.
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.
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.
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.
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.
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.

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:

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.

|

|
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.
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:

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:
- don't use GPIO 20 of an ESP32 - it is wired, within
the chip, to the RF, any attempt to do anything with it will
bring down comms; for some reason the boards I had purchased
brought out GPIO20 on one of their very few header pins,
gawd nose why,
- not very well documented but there is a blue LED on the
board that is wired to GPIO 8,
- I don't know why but the RF soon completely failed on the
first board I was using; my fault for buying the cheapest
things on the planet (£1.25 each delivered from China).
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:

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.
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...
 |
|
...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.
- The speed limitation of the 24BYJ48-034 motor comes
primarly from its 1:64 gear ratio: by experiment it needs 2
ms per step to rotate and settle, 64 steps,
64 * 64 * 0.002 = 6 seconds
per revolution max speed,
- the 16-pin dual-in-line ULN2003 is really huge these
days, too big for the space I have available,
- driving a converted-from-unipolar bipolar motor doesn't
allow me to use the TMC2209's stall detection feature: I
will have to forego that for the musical box doors,
- I will try other motors to drive the lift, the
plinky-plonky and possibly the rotation of the musical box
as a whole.
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).

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.
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).
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.
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.
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.
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.
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.
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.
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):
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:
- still able to access the inner parts when the doors are
on,
- the spindle adapters connecting the door motors to their
brass bars can now have a grub screw (couldn't get access to
insert one before),
- no need to print a large ASA structure (ASA can tend to
warp on large prints unless the environment is brought up to
40 Cish).
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:
- while testing I found that light from my workbench was
reaching the sensor on the bottom of the lift so I painted
the sensor-side of lift part 12 with the marvellously
matt Vallejo
matt varnish (matt black paint e.g. Humbrol 33
would also do); probably a prudent thing to do anyway,
- when I first tried the lift with the sides and top in
place I found that it overshot by a few millimetres; with
the sensors in place that was easily fixed by modifying the
same lift component to make the opening nearest the screw
begin a few millimetres further away from the screw,
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:
Zooming in on the faces:

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:
- what looked initially like black is actually a very dark
green: alternate sides have dark-green/orange backgrounds to
match an offset-alternate of dark-green and orange on the
doors above,
- all six designs are different but have predominantly
white, and maybe red, flowers,
- there is one odd-ball side which looks like it might be a
Buddha or some such.
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:
...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.
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.
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.
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.

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.
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:
- After three days of running the drive cog was quite badly
damaged (see picture below); I had already printed a spare
and it was easily changed but it had failed too quickly, it
was under too much stress: the base, running on cogs, was
still "a bit grindy", relying on the slip-ring for centring:
it would be better to experiment with using rollers rather
than cogs while supporting the centre around the slip-ring
with a bearing placed horizontally,
|

|
- I had one "sloppy" door i.e. it would not completely
close or completely open because there was "give" in its
position; this turned out to be slop in the gear-box of that
24BYJ48-034 so I just swapped in a spare motor,
- I had two door failures which turned out to be due to 0.1
inch pitch connectors coming loose; not entirely sure what
to do about that as, at least the second one, did not seem
to be dragging against anything, it became disconnected
purely through vibration: maybe improving the quality of the
rotation would help?
- as mentioned above, the first insert I printed to go
between the lift and the side walls was a bit too wiggly
and, though it worked fine for two days, maybe making a bit
of a rasping noise bit no biggee, on the third day it began
stalling the lift every so often: in order to get a better
quality print I increased the thickness of the insert to 1
mm, removed the side at the non-motor end of the lift (to
give the lift sufficient room), so it was now a C-shape,
angled the sides outward somewhat so that they would want to
stay away from the lift and reprinted the insert using the
settings I had used when printing the music belts, so that
it came out a lot straighter: note to future Rob - more
generous tolerances please,
- I also realised that
the lifting plate was not able to lie flat on the bottom
because, when the lift was at its lowest position, the lift
motor stuck up slightly above the level of the lift platform
and this was causing the lifting plate to slide forwards,
engaging with the insert and stalling the lift; I did not
want to make a hole in the lifting plate for the motor as
that would look odd, and thickening the lifting plate by a
few millimetres so that it would go over the motor would
mean reducing the maximum height of the lift by the same
amount (to stop the lifting plate sticking up out of the top
and fouling the doors), which I also didn't want to do: I
even tried printing the plate in flexible
filament but that wasn't enough, maybe just cut it out
of black paper, needs more research...
- I found that if I had got
the position of the magnet that was glued to the lifting
plate slightly wrong (easily done as the magnet slammed into
place causing the cyanoacrylate adhesive to make an
immediate bond), the lifting plate could scrape along the
sides of the insert (you can hear the
scraping in the long version of the Easter 2026
video), worst case preventing the lift rising: while that
problem went away with the flexible lifting plate, I stopped
gluing magnets on anyway, there was no need, I just placed
one in position to hold the lifting plate down when
installing it, the magnet wasn't going to go anywhere,
- the lift sensors worked very well, being inside the box,
likewise the plink-plonky and door sensors, though in the
latter two cases one had to ensure they weren't in strong
light,
- the door sensors were less reliable: they would always,
without fail, stop a door in the open position but, while
the door was sitting there open, the sensor could flicker a
little, hence the software didn't put too much reliance on
the steady-state values of the door sensors.
A couple of larger improvements came to mind after I had
finished:
- I didn't put a sensor in the stand in order to get a
"reference position", thinking it wouldn't matter, but
actually it does: you want the figure rising from the
musical box to be looking in a specific direction when it
stops, which can only be done reliably with a sensor,
- not having a sensor that defines door-closed could be
fixed by adding another QRD1114 sensor, say half way between
the current sensor and the door pivot. Another
matt-black-followed-by-white strip could then be painted on
the underside of the door, in the opposite sense this time,
corresponding to the closed position: this would be very
useful indeed as, with the current design, we cannot be
completely sure the doors have closed,
- the design change
with the sides and then adding the insert
had eaten through my tolerances where the inside of the
musical box was concerned: it would probably be possible to
reduce the lift dimensions very slightly to get those
tolerances back.
Back to
Meades Family Homepage