Raspberry Pi Zero makes a xylophone play itself
When maker Stéphane (aka HalStar) set about building this self-playing xylophone, their goal was to learn more about robotics, and to get hands-on with some mechanical parts they had never used before, in this case solenoids.
They also wanted to experiment with Raspberry Pi to build something that reflected their love of music. This automated instrument, capable of playing hundreds of MIDI files, fits the brief.
Two factors constrained the design: Stéphane wanted to be able to do it all using parts from the local DIY store, and to use as many regular modules as possible. So, no breadboard or wires everywhere, and no custom PCB. Just something simple to assemble and neat.
Hardware
Raspberry Pi Zero WH is the teeny tiny brain of the self-playing xylophone. And its maker’s build details video very helpfully labels all the parts, where they sit, and what’s connected to what.

These three buttons select the tracks, set the tempo, and set the mode. Choose between playing all loaded tracks or just one. You can also decide whether you want all tracks to play on repeat in a loop, or stop after your selections have played through. A two-inch LCD screen shows you what’s going on.

The right notes
While there are thousands of MIDI files freely available online, very few of them could actually be played by the xylophone. With only 32 notes, the instrument is limited in what it can play without losing any notes. Also, even when a MIDI file uses just 32 consecutive notes, they might not be the same range of 32 notes as the xylophone has, so you need to transpose. Stéphane developed a tool in Python to filter out 32-note tunes from thousands of MIDI files and automatically transpose them so the xylophone can play them. And, yes, everything you need to copy this filtering and transposing function is on GitHub.

Now, Stéphane says that whenever friends or family visit their home, they’re curious and impressed to see this strange instrument play by itself. Sadly, we are not among Stéphane’s family or friends; fortunately, though, this project has an entire YouTube playlist, so we can still have a look and a listen to see it in action up close.
Wait, isn’t that a glockenspiel?
We know it’s technically a glockenspiel. Stéphane acknowledges it is technically a glockenspiel. But we are firm fans of their going down the xylophone route, because way more people know what one of those is. If you’re interested, the difference between a xylophone and the glockenspiel is the material used for the bars. A xylophone has wooden bars, whereas glockenspiel bars are metal.
5 comments
Mr Adrian Scarlett
Until recently, I was convinced the xylophone was metal and the glockenspiel wooden. It just doesn’t feel right the correct way
Raspberry Pi Staff Ashley Whittaker — post author
I was convinced of that too until I wrote this blog 🤷♀️ The word sounds seem to fit better to the materials the other way around. Weird.
Stéphane
Glockenspiel word seems to come from Germany: Glocke for bell, and Spiel for play. A Glockenspiel was a carillon, prior to designating that sort of metal xylophone. That said, I had never heard of Glockenspiel word before starting this project!
David Palmer
Xylon (ξύλον) is Greek for ‘wood’.
Xylem is a type of tissue found in wood. Xylography is wood cut printing. Xylitol, xylenes,… are chemicals derived from wood.
Glock pistols have metal in them, a wooden gun probably wouldn’t work as well.
Michael
Very nice work and sounds great !
Makes my own version look pale … ( https://youtu.be/SDbTFUB2cbM)
Comments are closed