A method to convert toy piano type keyboards to MIDI
No libraries, shift registers or opto-couplers needed!
See this video: https://youtu.be/ujRLEiPdv0Y
Also, this short video of the extended functionality: https://www.youtube.com/watch?v=RAbyoZBtSxY
For a MIDI Out circuit: https://docs.arduino.cc/built-in-examples/communication/Midi
The method is very straighforward, with code that can be easily debugged and is easy to read.
Download mini Piano MIDI.ino for a basic polyphonic MIDI solution for a 2 octave toy keyboard.
Download Yamaha PSR-77 MIDI.ino for a 4 octave basic polyphonic MIDI solution for the YAMAHA PSR-77.
Download SimpleMIDI.ino for an extended feature set for the 2 octave mini Piano - which adds pitchbend, modulation, octave shifting and patch selection controls.
In the case of the Schylling mini Piano with a 3x8 keyboard matrix, 3 Arduino pins are sequentially set Low (10, 11, 12) and 8 pins are read for changes (2 to 9). Other toy type keyboards will be very similar.
The code is quick enough with a standard Arduino Nano to offer full polyphony and little latency.
Full optimisation could include clever routines for the keyboard matrix and faster routines for other functions... this codebase is intended to help people start off on such roads :)
How to wire up is only a case of reading which pins are connected in the Setup function.
To make your keyboard run - Most toy keyboards have diodes separating each key, so changing pins 10, 11 and 12 to High rather than Low may work. A small amount of experimentation should allow discovery of the circuit path and any changes required.
An alternative codebase for the YAMAHA PSR-77 has been uploaded, to show how such differences can be made with a larger keyboard that has a diode matrix. In that keyboards version, pins 10 - 15 from the keyboard matrix have 10K resistors connected to +5V.
Microcontroller used : Arduino Nano V3
Extra components are 10K variable pots to A0 and A1 (+5V, input pin, Gnd to pot leg connections)
4x momentary buttons to A2, A3, A4, A5 (one leg connected to Gnd)
Any or all of the extra components can be omitted if using the extended functionality code (SimpleMidi.ino). Just connect any unused pins of A0 to A5 to +5V.