Korg Microkey Air 37 Bluetooth MIDI Keyboard with Raspberry Pi

Do you want to have even more fun with your musical Raspberry Pi? Use an external Bluetooth MIDI keyboard with it! For this project, you need to download and compile a new version of the Bluetooth drivers for Linux. If you don’t already have compilation tools installed, you’ll need those too.

We will tell you how to compile and install the necessary Bluetooth driver, and then describe how to pair a Bluetooth MIDI Keyboard.

Prerequisites

You should have a Raspberry Pi 3 with built-in Bluetooth adaptor and Raspbian Stretch OS.

Background

The Raspberry Pi operating system uses a Bluetooth Driver system called “BlueZ” (http://www.bluez.org/). Raspberry Pi Stretch ships with BlueZ Version 5.43.
BlueZ Version 5.48 added MIDI support as a built-in profile, but it is not enabled by default. MIDI support in Version 5.48 is still considered “experimental.”  We need to compile BlueZ Version 5.48 with experimental options and we also need to enable MIDI.

Build BlueZ Version 5.48 with MIDI

The information in this section has been reproduced from the article listed in the References section,  with the important difference that –enable-midi has been selected.  A special thanks to Max who shared how to compile and install BlueZ..
1. Check Current BlueZ Version.
1-1. Before starting, let’s check the current BlueZ version.

$ bluetoothctl -v

You should see version 5.43.
2. Install Dependencies
2-1. Update the package list.

$ sudo apt-get update

2-2. Install the dependencies. (updated 2019-03-20 to add libasound2-dev)

$ sudo apt-get install libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev libasound2-dev -y

3. Install Latest BlueZ
3-1. Download the latest version of BlueZ source code.

$ wget www.kernel.org/pub/linux/bluetooth/bluez-5.48.tar.xz

3-2. Uncompress the downloaded file.

tar xvf bluez-5.48.tar.xz && cd bluez-5.48

3-3. Configure.
Here is where our instructions differ from Max: We need to enable MIDI! Notice the “–enable-midi” flag.

$ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --enable-midi

3-4. Compile the source code.

$ make -j4

3-5. Install BlueZ

$ sudo make install

3-6. Reboot Raspberry Pi 3.

sudo reboot

4. Verify Update
4-1. Verify the BlueZ version by issuing the command below.

$ bluetoothctl -v

The result should be like this:

$ bluetoothctl -v
bluetoothctl: 5.48

At this point, your system has BlueZ 5.48 up and running, with experimental features and MIDI ready to go. Let’s pair a Bluetooth MIDI device now.

Pairing your Korg Microkey Air

First, turn on the Korg Microkey Air 37 keyboard. You should make sure you do not have the USB cable plugged into it.   To indicate that is in Bluetooth pairing mode, the indicator light will be flashing blue.

Use the Bluetooth panel widget in the top-right of the Raspberry Pi Desktop to add a new bluetooth device.

You’ll see a list of Bluetooth devices available for pairing. The Microkey Air should appear in the list.  Select it and press [Pair].  (Note: the gray bar in the photo is what you see when you hover over the Microkey Item – the string “8C:45:00:E7:A5:16” is the Bluetooth MAC address of the device.)

At this point, it’s likely that you will see that Authentication with the device has FAILED! This means that pairing was not successful. We’re going to fix this in the next step.

The Microkey Air needs a different mode of authentication. To set this mode we’re going to use the “hciconfig” command.
Use the command to set the bit to “0” (disabled).

$ sudo hciconfig hci0 sspmode 0

We’ve included a screenshot from our terminal showing how we used the command.   In the first command we query the current state of the “sspmode” (Simple Pairing Mode) bit and see that it is enabled.   Then we use the hciconfig command to turn it off.  The last line of the terminal screenshot shows us querying the new value of the bit and that it is now “disabled.”

When pairing is successful, you will see the alert below.  Pairing has completed successfully, but it may sound as if the device is not usable.  The alert is due to the the LXPanel Bluetooth widget which only knows about HID and AUDIO devices. It does not know what a MIDI device is, so it reports the message shown.
Next, we want to verify that the added Microkey Air is available for MIDI.

Confirm that the MIDI Device is Functional

You can use the aconnect command in a terminal to see the state of the MIDI system. If this all went well, the Microkey Air 37 will now be part of your MIDI system.  It can be used with any Raspberry Pi MIDI program … especially McLaren Labs Pi-Organ-Synth!

For more information about the aconnect command, read our earlier post here: /blog/2018/07/03/linux-midi-cheatsheet/

References

This article gave all of the steps showing how to install BlueZ 5.48 on Raspberry Pi.
https://scribles.net/updating-bluez-on-raspberry-pi-5-43-to-5-48/
The initial checkin for MIDI in BlueZ gave instructions on how to compile the driver with MIDI.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=5b8353e90e5bffd22e4c2cbc354b7c638c6bebd0
Read about the Microkey Air 37 here.
https://www.sweetwater.com/store/detail/microKAIR37–korg-microkey-air-37-bluetooth-keyboard-controller

6 thoughts on “Korg Microkey Air 37 Bluetooth MIDI Keyboard with Raspberry Pi”

  1. Hello,
    Thanks a lot for this information!
    Just a comment, I have a Raspberry PI3 B and and I did the installation from the SD card and something was missing during the installation: ALSA lib. I do not no much but after doing the 4 steps below I did the installation again and it was working as you mentioned.
    1- pip install mido
    2- sudo apt-get install libasound2-dev
    3- sudo apt-get install libjack-dev
    4- pip install python-rtmidi
    Thanks again
    Martin

    1. I’m glad to hear it worked for you. Since we needed to compile, the libasound2-dev package was probably a hard dependency.
      Thanks for sharing your experience and how you got it working. Someone else will benefit from your message!

  2. Many thanks!
    This isn’t related to Raspberry Pi, or microKEY, but the sspmode setting really helped with pairing a nanoKONTROL Studio on Debian Bullseye as well. Pairing still didn’t work in Gnome’s built in Bluetooth manager, but a full configuration (right click, configure) worked in Blueman. I guess both devices use the same or similar Bluetooth implementation, so they need sspmode disabled.
    Bullseye has Bluetooth Midi enabled, so no need to compile anything.
    Confirmed working by typing ‘aseqdump -l’ which lists connected Midi devices.

Leave a Reply to Tom Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.