Do you ever wanna pump up some tunes but you don't know how to play a MIDI file? Fear not, the PiicoDev Buzzer modules let you stack up multiple tones into a song. Find your MIDI, export it through a script, upload it and get grovin'!
Feel free to remix (pun intented) this project to your hearts content, if you have any ideas let me know down below!
What you'll need
- Some PiicoDev Buzzer Modules - you can only play one note at a time on each buzzer so size your system accordingly, theoretically, you could chain up to 16 for complex songs
- A PiicoDev Expansion board
- Some PiicoDev cables
- A Raspberry Pi Pico with soldered headers or you can solder your own
- A micro USB cable so you can interact with the Pico
- Something to hold it all together, I went with a 3D printed enclosure for the expansion board and 4 buzzers (no fasteners required), or if you wanna experiment with some other modules the PiicoDev Pioneers Platform
- A computer to export the file that the Pico needs - A Pi 4 will work as well!
Putting it together
Here’s where PiicoDev shines, it’s super easy to get everything together.
-
Move each of the DIP switches around into unique addresses - with 2 switches 4 addresses are possible. Even more with the solder pads on the back (2 more states that's 16 possible addresses!)
-
Connect your PiicoDev modules together, my daisy chain looked like this:
-
Then insert the Pico into the expansion board (the green one that tastes like Raspberries (please don't try to eat any of the Raspberry Pi's that you use in your projects)).
-
Whack all of the electronics into the case/platform of your choice
- Plug the USB cable in, let's flash some code!
First of all, we'll make 2 folders, one for the Pico and one for the code we'll run on a computer (a Pi 4 will work).
Head over to the Buzzer guide for the RPi Pico, run through the tutorial pop the code into the Pico folder that we created before and make sure all of the Buzzer modules work - just change the addr
argument buzz = PiicoDev_Buzzer(volume=2, addr=<YOUR ADDRESS HERE>)
Keep the PiicoDev code handy, we’ll need it later!
If you're unsure which addresses are being used run the following code in the REPL:
from machine import I2C i2c = I2C(0) i2c.scan()
- Head over to my GitHub to download the code for the BuzzBox, it leans on the Python-Midi-Analysis Repo that Cornerback24 crafted.
Unfortunately, this is script is too large to run on the Pico, that's why I have made it a program that you are able to run on a beefier computer. There is always the option to add the PiicoDev adapter for Raspberry Pi and export and play the audio from the one device, I opted to use the Pico so it's more accessible to Makers.
- To export a MIDI, download a .mid file, and put it in the Midis directory, load up the
MIDI2CSV.py
file and change thefile_to_convert
to the file that you wanna play, run the script, then upload the CSV along with theBuzzerBox.py
andmain.py
(you can overwrite the main file from the tutorial) from the Midi’s folder and move it to the same directory that you have the Pico files in, be sure to include the PiicoDev Unified and Buzzer modules as well.
- Upload all of the files to the Pico, just change the argument to the loadMusic function