I’d left the Pi Pico MIDI Matrix Decode project essentially working but with a ghosting multiple keypresses problem. I was just going to let it go, but then I decided I just couldn’t leave it there, so I had to take another look.
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:
- Getting Started with the Raspberry Pi Pico: Inputs and Outputs
- How to make a keyboard matrix
- Keyboard MIDI Matrix Decode and Pi Pico MIDI Matrix Decode – Part 2
- MIDI, MicroPython and the Raspberry Pi Pico
If you are new to microcontrollers, see the Getting Started pages.
- Raspberry Pi Pico
- One of the 3.3V compatible Ready-Made MIDI Modules; or
- 5-pin 180 DIN socket, 10Ω and 33Ω resistors
- 12x breadboard friendly switches
- 16 holes x 21 strips stripboard and jumper wires
- 12x 1N914 fast switching diodes
- MIDI module or sound generator (I used my Arduino MIDI VS1003 or VS1053 Synth)
In terms of my own circuit, I’ll try to describe the problem.
In the above diagram we can see what happens when the second keyboard is being scanned and a the first key is pressed whilst the first key on the first keyboard is also pressed.
Points to note:
- The first (yellow) column is disabled – in high impedance (high Z) mode; and the second (orange) column is set to a normal OUTPUT but set LOW, so we are scanning the second keyboard.
- All three “rows” are inputs with PULL_UP activated, so internally are connected to VCC, so will read HIGH if nothing else happens.
- The first switch on the second board connects the green row INPUT to the orange column, so it reads LOW.
- The keyboard thus correctly scans as there being one key pressed on the second keyboard.
Now consider the situation when there are two keys pressed on the first keyboard, but only one on the second.
Points to note:
- The first (yellow) column is still disabled – in high impedance (high Z) mode; and the second (orange) column is still set to a normal OUTPUT but set LOW, so we are scanning the second keyboard once again.
- All three “rows” are still inputs with PULL_UP activated, so internally are connected to VCC, so will keep reading HIGH if nothing else happens.
- The first switch on the second board still connects the green row INPUT to the orange column, so it reads LOW as expected.
- But now, we can see that the two switches on the first keyboard provide a path between the blue and green INPUTs via the two switches pressed on the first keyboard (the bright yellow path in the diagram).
- This means that whilst we are scanning the second keyboard, both the blue and green INPUTs will be read as LOW.
The consequence of this is that the second keyboard scan “sees” the rows associated with both the first two switches as LOW, and thus pressed, even though only one of the switches on the second keyboard is being pressed.
The way to fix it is to add some diodes to the “column to switch to row” path so that current can only flow one-way – there is no option for current to flow back through – in the above case – the second switch on the first keyboard, so ghosting will not occur.
If you are building this from scratch, you can see the circuit above. As a schematic, it looks like this.
In my case, as I’m retro-fitting diodes to the build from Pi Pico MIDI Matrix Decode – Part 2 I’ve broken the tracks on the underside of the boards and have added diodes “by hand”. You can see the breaks and the first two diodes soldered on in the photo below (along with my very dodgy soldering! Don’t ask what is going on, on the left hand side…).
No changes are required to the code for this to work fine now, so you can use the code from Part 3 quite happily.
This was one of those times that for the sake of simplicity I accepted a compromise (accepting that ghosting will occur) but then when reality hit decided I’d made the wrong call.
This shows how to retrofit a fix or, if you’d like to do it properly from the start, how to do so.
I don’t know if I’ll retrofit it to all four octaves yet. At the very least I need to get some more diodes to do them all!