“Plays the theme song from Portal…., for those who are “Still Alive”. Features a customizable 3D print-in-place hinged box.
Wanted to do a project with the Pi Pico and thought a Music Box would be a good start. Made one in 2012 following the instructions on elm-chan and using an ATTINY45. Time for an update!
Effort/Level
Easy/Beginner Soldering required. About 2 hours assembly time.
3D print takes about 6 hours for the box. The “Aperture Labs” logo is a separate print in white material. You’ll need to paint the top of the letters. I used black hobby acrylic paint. There are options for plain boxes (no logo), too.
Or, you can get a wooden “craft box” and drill holes in it for speaker and USB connector. For the craft box, look for one at least 100mm L x 60mm W x 60mm H (4 in x 2.25 in x 2.25in). You’ll need a hole drill bit about the size of your speaker.
Cost
All costs USD.
About $30, not counting 3D print, or craft box. Also depends on what you have on hand.
The simplest and cheapest option shown below is no box, just the Pico, a speaker, a resistor and an Adafruit Amp, about $12 if you have some wire, a breadboard and a spare 5V power adapter on hand,
The “Full Portal” version, with Neopixels as a backlight, is around $30.
Research
I reviewed what was available and found some source material from Markus Gritsch, from 2012. Markus supplied a midi file for the Portal game song “Still Alive”. Did a little more searching around and found I could convert a midi file to a “music box” sound on the Music Box Maniacs site.
That meant that you could convert almostANY midi file to a music box song, given size restrictions for memory on the Pico. You have to stay below 1MB for code and files. If you wanted longer songs, you could add an SD card reader and play from there. Limited by the size of your SD card. I leave that for the interested student to figure out….
If you don’t like the mp3 version in the downloads, there are lots of different versions of Still Alive on Music Box Maniacs, available for download. Or, other songs you might like in a music box. The github download has plain and Portal-themed STL files.
Next question…There’s no I2S output on the Pico - could the Pico play audio? I found a very helpful article by Michael Thorne, Playing Sounds from the Raspberry Pi Pico using CircuitPython.. This was a “Maker’s Journey” tale of Michael discovering how to play a wav file on the Pico.
TL;DR: Adafruit to the rescue! Michael’s solution was based on Adafruit’s CircuitPython. CircuitPython already has libraries for the Pico that use PIO, “programmable input-output” to help play audio. The PIO functions use the new hardware on the Pico and a software “state machine” for absent hardware functions. For an introduction on PIO, see this blog post.
More digging and I found a CircuitPython example for playing mp3 files. I mashed up Michael’s code with the mp3 example and Ta-Da!, mp3 played out the speaker!
For extra effect, I added a backlit fade-in/fade-out with a Neopixel stick. Adafruit also had the code for that, in Logan’s Run Hand Jewel LED. I used a NeoPixel stick, so only needed to change the numpix to 8, and the pixpin to board.GP0. Note that I did get a little flicker, which I could not resolve. I think I had poor solder joints. [SIGH].”