Toy Keyboard USB Matrix Decode with the Pi Pico

I never really got back to looking at my “Toy Keyboard” – I wanted to do the same as the Vintage Phone – create a USB MIDI version with Circuitpython.  Well now I have.  Here is the result.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

If you are new to microcontrollers, see the Getting Started pages.

Parts list

  • Keyboard arranged as a key matrix.
  • Raspberry Pi Pico
  • Breadboard and jumper wires.

The Circuit

It is using the same hardware and circuit as before, but I decided I’d permanently attach a Pico to the keyboard to turn it into a USB MIDI keyboard, self-contained unit.

It needs two sets of digital inputs – eight on one side and five on the other.  As this will be a USB controller, no further IO is required.

To keep things small, I decided to use a “sawn-off pico” again and arranged things as follows.

ToyKeyboardUSBMIDI

You can see where the cut was made and how the 8+5 IO lines from the keyboard were soldered on.  Here is the final result for me.

IMG_5176IMG_5177

When all is complete, the Pico should get its power from the host over USB and will require nothing else other than plugging in.

IMG_5179IMG_5178

The Code

I’ve taken the code from the Micropython version and followed my notes from the Circuitpython USB MIDI version of the Vintage Phone project.  The result is a USB MIDI version of the keyboard matrix decoding now designed to support the connections described above.

The eventual pinout that worked for me is as follows – you’ll have to see what works for your own keyboard if you are following along.

row_pins = [board.GP11,board.GP10,board.GP9,board.GP8,board.GP7,board.GP6,board.GP5,board.GP4]
col_pins = [board.GP27,board.GP26,board.GP22,board.GP21,board.GP20]

I was initially having a few weird things going on – the MIDI information being transmitted over USB seemed to be several notes “out of date” compared to what was being played and there were lots of repeats.

After staring at the code for a while and deciding I really couldn’t see anything wrong, I decided to update both Circuitpython and the adafruit_midi library being used.  This fixed everything.  I’m wondering if I was using an incompatible version of the main runtime and the libraries.

Note to self: always download the latest runtime and library before starting a new project.

Find it on GitHub here.

Closing Thoughts

In the short demo video you can see the keyboard being used to drive my Zynthian synth simply by plugging it in over USB.

I still wish it was a slightly more up-market keyboard, in that I wish the circuit board had diodes for each key to prevent ghosting, but for a total cost of less than £4 this is now a great USB MIDI keyboard.

There are still some spare IO pins on the Pico, even though I cut some of them off!  So it might be worth adding a means to set the MIDI channel.

It should also still be possible to attach a serial MIDI interface if required as before, so I might update the code to allow to support either USB or serial MIDI, although the serial MIDI will require external power.

Kevin

One thought on “Toy Keyboard USB Matrix Decode with the Pi Pico

Leave a comment