Toy Keyboard Matrix Decode with the Pi Pico

I’m always on the look out for discarded music keyboards that I might be able to do something with, so when I came across this thrown out in the street I claimed it to take a look.

This shows how I used a Raspberry Pi Pico to decode the keyboard part and turn it into a basic MIDI controller, shown here linked to my MT32 Clumsy MIDI Program Changer and Filter.

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
  • One of the DIY MIDI Interfaces or Ready-Made MIDI Modules suitable for use with 3.3V microcontrollers.
  • Breadboard and jumper wires.
  • Some kind of MIDI device to plug it into.

The Hardware

The first task was to take the keyboard apart and work out what was usable.

IMG_4965

As you can see it was in a pretty sorry state, so at this point I completely abandoned any thought of trying to do something with the electronics (it’s always a bit of fun to take a look) and concentrated on the keyboard.

So the next step was to dismantle everything to allow me to clean the keyboard and take a look at the PCB and switches.

IMG_4966

I don’t know if you can see from this picture, but there is an immediate issue with the keyboard – there are no diodes, just switches.  This means that I won’t be able to protect against ghosting of keypresses – having “phantom” keys detected when multiple keys are pressed (for a detailed explanation of why this is an issue, have a read of this: Pi Pico MIDI Matrix Decode – Part 4).

But still, it looked like it would all be working order once cleaned and assembled, so I thought I’d go for it.  The “ribbon” cable to the keyboard was quite fatigued, and broke off pretty quickly, so I had to remove it completely and re-solder it back on.

I also added some header pins to the other end for easy connection to breadboards and so on.  I decided to solder the ends of the “ribbon” into some rounded, female header sockets.

Ribbon Headers

Then I had to work out how the matrix was decoded, although it was looking pretty obvious from the arrangement of the cables… I use the same method as described in Keyboard Matrix Decode to check.

As hoped, the 8-way ribbon was the set of “rows” and the 5-way ribbon could be considered the “columns” of the matrix, with the order of connectors matching the order of keys.  Each “column” served 8 keys allowing for a maximum of 8×5 or 40 keys to be decoded.  The keyboard itself covers three octaves plus an extra note, so 37 in total.

The Circuit

Toy Keyboard Matrix Decode with the Pi Pico_bb

Once the basic layout is understood the keyboard can be linked up to the Pico.  As the Pico has a ground for every four IO pins, I’d have to break up the connectors on the ribbon cables to connect directly, so as shown above, I used a breadboard and jumper wires.

One of my 3.3V friendly Ready-Made MIDI Modules was linked up to UART 0 TX and power for the MIDI link.

image1

The Code

The code is exactly the same as Pi Pico MIDI Matrix Decode – Part 3 with the appropriate pin definitions at the top as follows.

row_pins = [15,14,13,12,11,10,9,8]
col_pins = [20,19,18,17,16]

Find the original on GitHub here.

Closing Thoughts

The lack of diodes on the keyboard was disappointing, and you can hear the “ghosting” effect near the end of the video, but for a simple “free” (recycled) keyboard I’m still pretty pleased it was relatively easy to get going.

And it was nice to test it with my MT32 Clumsy MIDI Program Changer and Filter too.

Kevin

image2

2 thoughts on “Toy Keyboard Matrix Decode with the Pi Pico

Leave a comment