Robot Glockenspiel

By Lucy Hattersley. Posted

This Robot Glockenspiel project strikes a chord for its clever use of Sonic Pi and LEGO to make sweet music, as David Crookes discovers

This robot Glockenspiel uses Raspberry Pi to bash out its own tunes.

Robots have already blown their own trumpet: Toyota developed a humanoid in 2004 which could play When You Wish Upon a Star by clasping the instrument in its hands and blowing air through its mouth.

Since then, we’ve seen robots play the drums and guitar; even going as far as recording an album. But now we’ve heard the results of a Raspberry Pi playing a glockenspiel and it’s been music to our ears. It’s all thanks to Robin Newman whose love of computers and music goes way back.

In the 1980s, Robin networked 24 BBC Micros and had them play parts of a Bach Brandenburg Concerto. “Today, 80 percent of my work with Raspberry Pi boards involves Sonic Pi,” he says.

Robot Glockenspiel controlled by Raspberry Pi

Robin got the idea for a Sonic Pi-controlled glockenspiel after seeing similar projects online that used an Arduino.

“Version 3.1 was a game changer because it allowed Sonic Pi to communicate with the outside world using either MIDI signals or Open Sound Control messages,” he explains. “It enables Sonic Pi to interact with Python-controlled devices and to interact easily with signals to and from the Pi’s GPIO pins.

I wanted to use the fact that it could control a glockenspiel and play itself at the same time to accompany the instrument.” Setting up Robin already had a glockenspiel. A 30-year-old gift to his son, it was languishing in his attic. As such, he sought to produce an easily constructed project that could be added to the instrument. The Pi, he envisaged, would control hammers to strike the glockenspiel’s metal bars and he decided to use solenoids as the actuators.

“I bought a 5 V, Adafruit-sourced solenoid and I already had a suitable power supply to hand,” he recalls. “I also had a power transistor and projection diode from an Arduino starter kit. I was able to connect them up to a GPIO pin and use the GPIO Zero LED command to switch it on and off.

Hitting the keys

This worked fine and so the question was how could this small movement be used to hit the keys.” It was then that he turned to LEGO. Hammer time Before the Pi was launched, Robin had spent a few years working with the LEGO EV3 system, mainly producing colour-sorting robots.

“After some experimentation, it turned out to be beautifully simple to produce a hammer mechanism out of LEGO which could then be driven by the solenoid, providing just the right kick,” he says. To do this, he had the LEGO hammers strike the notes from underneath, allowing gravity to return them to their resting position. “It’s important that the hammers strike the notes and then immediately move away from them so that they don’t dampen the sound,” he explains.

From then on, the software could work its magic. Robin wrote a Python script to drive the GPIO pins and therefore the solenoids, and he delayed the notes sent to the glockenspiel by 0.3 seconds. This compensated for the delay between the Sonic Pi playing a note and the note sounding in a speaker, allowing the Pi to accompany the glockenspiel without it sounding odd. “I’m now looking at a system of overhead hammers,” Robin reveals, keen to continue refining the project. “This will open up the range of glockenspiels that can be used.”

Step-01 Wire the Pro Hat

After grabbing a glockenspiel, Robin restricted the notes he’d use and accommodated the driver circuitry on a RasPiO Pro Hat. He used three TP102 Darlington power transistors. A breadboard was used to distribute signals to the solenoids.

Step1 Sonic Pi Glockenspiel

Step-02 Get out the LEGO

The hammers were built from LEGO and, by happy coincidence, the width of the basic hammer mechanism was three LEGO beams (or 24 mm). Since ten notes on Robin’s glockenspiel occupied 234 mm, it made for a good fit.

Step 2 Step1 Sonic Pi Glockenspiel

Step-03 Completing the setup

After wiring up the solenoids, Robin propped the glockenspiel on wooden blocks to allow the hammers to fit under the instrument. He used Sonic Pi to send OSC information to the Python script and specify the notes.

Step 3 Step2 Step1 Sonic Pi Glockenspiel

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.