Converting Piano Toy to MIDI Keyboard.

Dependencies:   mbed mbed-STM32F103C8T6 USBDevice_STM32F103

How to turn kids' old piano toy to a MIDI keyboard

Inspired by http://www.codetinkerhack.com/2012/11/how-to-turn-piano-toy-into-midi.html I did the same with a Blue Pill module using Mbed.

The old toy was capable to play only one tone at a time:
Zoom in
https://os.mbed.com/media/uploads/hudakz/minikeyboardtoy01.jpg



A bit of reverse-engineering was needed to re-use the original printed boards. The results are below.

Original PCBs with switches traced to the connector pins:

Zoom in
https://os.mbed.com/media/uploads/hudakz/keys.jpg Zoom in
https://os.mbed.com/media/uploads/hudakz/buttons.jpg

Schematic:

Zoom in
https://os.mbed.com/media/uploads/hudakz/schematic.png

Wiring:

https://os.mbed.com/media/uploads/hudakz/wiring.png



Then I replaced the original chip with a Blue Pill module and added a USB connector:
Zoom in
https://os.mbed.com/media/uploads/hudakz/minikeyboardtoy02.jpg

Works great when connected over an USB cable to a Linux Ubuntu 18.04 machine

Installed software:

  • Yoshimi: An excellent MIDI software synthesizer for Linux.
    Zoom in
    https://os.mbed.com/media/uploads/hudakz/yoshimi.png
  • Patchage: Provides a graphical interface to connect jack and midi inputs and outputs.
    Zoom in
    https://os.mbed.com/media/uploads/hudakz/patchage.png

How to use it:

  • Connect the Keyboard to the PC over an USB cable.
  • Run Yoshimi.
  • Run Patchage and connect the Mbed USB Audio MIDI 1 output to Yoshimi's input (drag Mbed Audio MIDI 1 over yoshimi input and drop)

https://os.mbed.com/media/uploads/hudakz/connection.png

  • To apply the changes close the Patchage!
  • On Yoshimi's toolbar click on Instruments and select Show Stored ...
  • Select a bank and click on the instrument you'd like to play.
    https://os.mbed.com/media/uploads/hudakz/instruments.png

Have fun :-)

Committer:
hudakz
Date:
Wed Apr 08 17:47:23 2020 +0000
Revision:
0:75d307e38488
Child:
1:41d2a3984dd7
Converting Piano Toy to MIDI Keyboard.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:75d307e38488 1 #include "stm32f103c8t6.h"
hudakz 0:75d307e38488 2 #include "mbed.h"
hudakz 0:75d307e38488 3 #include "MidiKey.h"
hudakz 0:75d307e38488 4
hudakz 0:75d307e38488 5 DigitalIn a3(PA_3, PullDown);
hudakz 0:75d307e38488 6 DigitalIn a4(PA_4, PullDown);
hudakz 0:75d307e38488 7 DigitalIn a5(PA_5, PullDown);
hudakz 0:75d307e38488 8 DigitalIn a6(PA_6, PullDown);
hudakz 0:75d307e38488 9 DigitalIn a7(PA_7, PullDown);
hudakz 0:75d307e38488 10
hudakz 0:75d307e38488 11 DigitalInOut a0(PA_0, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 12 DigitalInOut a1(PA_1, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 13 DigitalInOut a2(PA_2, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 14 DigitalInOut b0(PB_0, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 15 DigitalInOut b1(PB_1, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 16 DigitalInOut b10(PB_10, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 17 DigitalInOut b11(PB_11, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 18 DigitalInOut c15(PC_15, PIN_INPUT, PullDown, 0);
hudakz 0:75d307e38488 19
hudakz 0:75d307e38488 20 /**
hudakz 0:75d307e38488 21 * @brief
hudakz 0:75d307e38488 22 * @note
hudakz 0:75d307e38488 23 * @param
hudakz 0:75d307e38488 24 * @retval
hudakz 0:75d307e38488 25 */
hudakz 0:75d307e38488 26 int main()
hudakz 0:75d307e38488 27 {
hudakz 0:75d307e38488 28 confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock)
hudakz 0:75d307e38488 29 USBMIDI midi;
hudakz 0:75d307e38488 30 MidiKey key[] =
hudakz 0:75d307e38488 31 {
hudakz 0:75d307e38488 32 MidiKey(midi, 53, a0, a5), // S1
hudakz 0:75d307e38488 33 MidiKey(midi, 54, a1, a5), // S2
hudakz 0:75d307e38488 34 MidiKey(midi, 55, a2, a5), // S3
hudakz 0:75d307e38488 35 MidiKey(midi, 56, b11, a5), // S4
hudakz 0:75d307e38488 36 MidiKey(midi, 57, b10, a5), // S5
hudakz 0:75d307e38488 37 MidiKey(midi, 58, b1, a5), // S6
hudakz 0:75d307e38488 38 MidiKey(midi, 59, b0, a5), // S7
hudakz 0:75d307e38488 39 MidiKey(midi, 60, c15, a6), // S8
hudakz 0:75d307e38488 40 MidiKey(midi, 61, a0, a6), // S9
hudakz 0:75d307e38488 41 MidiKey(midi, 62, a1, a6), // S10
hudakz 0:75d307e38488 42 MidiKey(midi, 63, a2, a6), // S11
hudakz 0:75d307e38488 43 MidiKey(midi, 64, b11, a6), // S12
hudakz 0:75d307e38488 44 MidiKey(midi, 65, b10, a6), // S13
hudakz 0:75d307e38488 45 MidiKey(midi, 66, b1, a6), // S14
hudakz 0:75d307e38488 46 MidiKey(midi, 67, b0, a6), // S15
hudakz 0:75d307e38488 47 MidiKey(midi, 68, c15, a7), // S16
hudakz 0:75d307e38488 48 MidiKey(midi, 69, a0, a7), // S17
hudakz 0:75d307e38488 49 MidiKey(midi, 70, a1, a7), // S18
hudakz 0:75d307e38488 50 MidiKey(midi, 71, a2, a7), // S19
hudakz 0:75d307e38488 51 MidiKey(midi, 72, b11, a7), // S20
hudakz 0:75d307e38488 52 MidiKey(midi, 73, b10, a7), // S21
hudakz 0:75d307e38488 53 MidiKey(midi, 74, b1, a7), // S22
hudakz 0:75d307e38488 54 MidiKey(midi, 75, b0, a7), // S23
hudakz 0:75d307e38488 55 MidiKey(midi, 76, c15, a4), // S24
hudakz 0:75d307e38488 56 MidiKey(midi, 77, a0, a4), // S25
hudakz 0:75d307e38488 57 MidiKey(midi, 78, a1, a4), // S26
hudakz 0:75d307e38488 58 MidiKey(midi, 79, a2, a4), // S27
hudakz 0:75d307e38488 59 MidiKey(midi, 80, b11, a4), // S28
hudakz 0:75d307e38488 60 MidiKey(midi, 81, b10, a4), // S29
hudakz 0:75d307e38488 61 MidiKey(midi, 82, b1, a4), // S30
hudakz 0:75d307e38488 62 MidiKey(midi, 83, b0, a4), // S31
hudakz 0:75d307e38488 63 MidiKey(midi, 84, c15, a3) // S32
hudakz 0:75d307e38488 64 };
hudakz 0:75d307e38488 65 size_t keyLen = sizeof(key) / sizeof(*key);
hudakz 0:75d307e38488 66
hudakz 0:75d307e38488 67 while (1) {
hudakz 0:75d307e38488 68 for (uint8_t i = 0; i < keyLen; i++) {
hudakz 0:75d307e38488 69 key[i].scan();
hudakz 0:75d307e38488 70 }
hudakz 0:75d307e38488 71 }
hudakz 0:75d307e38488 72 }