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.

Let me introduce you to Stéphane’s self-playing xylophone

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.

This extra video goes into more detail about the build process

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.

self playing xylophone hardware
There we are (#4) working away to make the xylophone play

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.

self playing xylophone track selection buttons
Twist and click to choose your settings

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.

self playing xylophone hero
In all its glory

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
Jump to the comment form

Avatar

Until recently, I was convinced the xylophone was metal and the glockenspiel wooden. It just doesn’t feel right the correct way

Reply to Mr Adrian Scarlett

Ashley Whittaker

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.

Reply to Ashley Whittaker

Avatar

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!

Reply to Stéphane

Avatar

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.

Reply to David Palmer

Avatar

Very nice work and sounds great !
Makes my own version look pale … ( https://youtu.be/SDbTFUB2cbM)

Reply to Michael

Leave a Comment