As promised beolw, I have now published the full article on this project. The construction has changed slightly, and the wiring is tidied up. The article contains full contstruction details and all the software.

There is also a link to a further piece played by the glockenspiel


I have long had an ambition to produce a musical instrument controlled by Sonic PI. Recently I dug a nearly 40 year old Glockenspiel out of the attic. We bought it for our Son when he was a young boy. Having blown away the dust, I had a think about how it might be controlled. My constructional skills are not great, but I do have a reasonable amount of Lego, and I played around with building a suitable hammer mechanism. I bought a couple of different solenoids from The PiHut, one a 5v model the other a beefier 12v device. In the event, the 5v device seemed to fit the bill. I drove it with a TIP120 power transistor, adding a protective diode, from a gpio pin using the GPIOZERO Led device driver and ti worked fine. I built up a line of 9 hammers, and tried them manually with the Glockenspiel. Fortuitously, the note spacing on the instrument fitted quite well the spacing set by the Lego. I decided to splash out and ordered a further 10 solenoids from The PiHut, together with an 8 channel open collector darlington chip featured on the AdaFruit site, and also stocked by The PiHut. I built this up and it worked! I decided to add two further “mobile” hammers utilising the two remaining solenoids, and used some TIP120 transistors to drive these as there wasn’t room for a further 8 channel device on my RasPio ProHat breadboard. (I used this because it plugs directly into the Pi and brings out the GPIO pins in a linear order making the wiring quite easy to accomplish. The solenoids were powered by a separate 5V 3A supply, separate from the Pi3 5v supply.
On the software side, I used a Python script which received OSC messages addressed to “/note” with a numeric parameter in the range 0 to 10. This was then used with the GPIOZERO LEDBoard command to pulse on one of the output pins (from 9->19). Each output controlled a separate solenoid.
On the Sonic Pi (3) side, it was merely a matter of mapping notes in the range :C6 to :E7 (plus :G5) to the numbers 0 to 10, and then sending the relevant number n using an osc message such as "/note",3
These were routed to the python script running on the same Raspberry Pi as Sonic Pi using:
use_osc "LocalHost",8000
Once that was done you could mix play commands with OSC commands for the relevant note, and get the Glockenspiel to play at the same time as Sonic Pi played other notes. The only other thing I had to do was to delay the OSC messages with a sleep rt(0.3) because there is a large inherent audio latency in the default Sonic Pi audio output channel. However it is constant, so with this delay you can keep the two in step.

I will write a fuller article on my blog shortly (and announce it here), with further constructional details and software.

In the meantime enjoy this full video:


good morning,

Congratulations ! i love your projects !