I’ve had a Micro:bit for a while now and recently found a “piano shield” from Keyestudio so thought I’d give it a go.
These are the key tutorials for the main concepts used in this project:
If you are new to the Micro:bit try the Micro:bit Getting Started pages.
Parts list
- BBC Micro:bit (available from the PiHut, Pimoroni, and others)
- Keyestudio Piano Shield
- Power and computer for programming
The Circuit
The piano module just plugs directly into the Micro:bit as follows. The keys are accessed via a driver chip (a TTP229 touch controller) using the I2C protocol – but we don’t need to know anything about any of that to use it. Helpfully it also includes a simple buzzer so we can start loading some code and making noises pretty quickly.
The Code
The Piano can be accessed using Python or with an additional module installed via the MakeCode editor. To get the piano running, there is a “Play Piano” block which can be installed as follows:
- From the Keyestudio wiki page for the Piano, select the “Download relevant data sheet and source code” link from the Resources section near the bottom.
- This takes you to a Google Drive location where you can select the “microbit code” folder.
- In that folder is a file called “KS0440.hex”. Select that and when prompted “there is no preview available” select “download”.
- Now in your MakeCode editor, select “Advanced” and then at the bottom of the menu “extensions”.
- At the bottom of the extensions page is a dark grey “Import File” box. Select this and you get a “choose file” option. Selecting this will prompt you for a file – so find and select the KS0440.hex file you downloaded previously.
- Now when you return to the MakeCode editor you should see a “Cokoino TouchPiano” section as follows with the appropriate blocks to use.
The simplest program is simply to use the “Play Piano” block in a forever loop as follows.
This program won’t really run in the Micro:bit simulator, but you can download it to your Micro:bit in the usual way.
Closing Thoughts
This is a simple add-on and once the block is loaded up it is quite simple to start making some beeps from the keyboard. It is possible to program it using Python code too which gives you more control over the board and there are a number of options for using the built-in full colour LEDs too.
There are several piano modules available for the Micro:bit. I quite liked this one as it looked relatively simple to use and quite small in comparison to others.
At some point I’ll investigate other options for music making with the Micro:bit.
Kevin