Update: Korg Microkey Air 37 Bluetooth MIDI Keyboard with Raspberry Pi4 and Buster

Last year, in https://mclarenlabs.com/blog/2019/01/15/korg-microkey-air-37-bluetooth-midi-keyboard-with-raspberry-pi/, I described how to compile a Bluetooth update for your Pi and how to connect a Korg Bluetooth keyboard to your Pi wirelessly. Raspbian “Buster” includes bluez-5.50. The code for version 5.50 includes support for Bluetooth MIDI, but it is not enabled in the “Buster” distribution. This article describes what I discovered in compiling bluez-5.50 for “Buster” and how I installed it to get Bluetooth MIDI working on my Raspberry Pi4.

A Pristine Buster System

Before we start, let’s look at what is installed where in a standard Buster system.

In /etc/init.d/bluetooth, we see

DAEMON=/usr/sbin/bluetooth

and we see that /usr/sbin/bluetoothd is a symbolic link to /usr/lib/bluetooth/bluetoothd.

We see that /etc/systemd/system/bluetooth.target.wants/bluetooth.service is a hard link to (same file as) /etc/systemd/system/debus-org.bluez.service. In this file we see

[Service]
...
ExecStart=/usr/lib/bluetooth/bluetoothd

So anything starting bluetoothd is starting /usr/lib/bluetooth/bluetoothd.

Compile Bluez from Source

Using the instructions from our blog article a year ago, get compile and install bluez but this time get bluez-5.50. Here’s a quick summary.

$ curl -OL# http://www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz
$ tar -xvf bluez-5.50.tar.xz
$ cd bluez-5.50
$ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental --enable-midi
$ make -j4
$ sudo make install

When you are all done, you will see another copy of bluetooth. This one is in /usr/libexec/bluetooth/bluetoothd. If we look in /etc/systemd/system/bluetooth.target.wants/bluetooth.service, we’ll see that the reference to the binary is updated to the new one. But it we look in /etc/init.d/bluetoothd, we’ll see that it is pointing to /usr/sbin/bluetoothd, which is a link to /usr/lib/bluetooth/bluetoothd, which is the old one.

We now have two copies of bluetoothd on our system and we need to sort it all out. Here is what I did.

$ pushd /usr/sbin
$ sudo mv bluetoothd bluetoothd.orig
$ sudo ln -s /usr/libexec/bluetooth/bluetoothd bluetoothd

Reboot and Pair

Now, if you reboot your system, you will get the new version of bluetoothd, with BLE MIDI enabled. Follow the instructions from before to disable SSP mode.

$ sudo hciconfig hci0 sspmode 0

and you should be able to pair your Korg Microkey Air 37 Bluetooth MIDI Keyboard with your Raspberry Pi4!

You can re-enable sspmode at this point if you want. The keyboard is already paired with the computer.


9 thoughts on “Update: Korg Microkey Air 37 Bluetooth MIDI Keyboard with Raspberry Pi4 and Buster”

  1. Hi!
    I tried the installation and successfully built bluez I think. However, when I tried to pairing Korg Microkey Air, I see the Pairing Failed error even if I set the sspmode 0. Do you have any idea to solve the issue? What I’m using for Raspberry Pi OS is 2021-01-11-raspios-buster-armhf.img

    Thanks!
    Masanao

  2. Unfortunately I’m not having much luck with building bluez 5.50 with midi. Configure works OK but when I try to make, i get the below output (running https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2021-05-28/2021-05-07-raspios-buster-armhf-lite.zip):

    CC monitor/analyze.o
    CC monitor/intel.o
    CC monitor/broadcom.o
    CC tools/rctest.o
    tools/rctest.c: In function ‘recv_mode’:
    tools/rctest.c:507:19: error: ‘SIOCGSTAMP’ undeclared (first use in this function); did you mean ‘SIOCGRARP’?
    if (ioctl(sk, SIOCGSTAMP, &tv) < 0) {
    ^~~~~~~~~~
    SIOCGRARP
    tools/rctest.c:507:19: note: each undeclared identifier is reported only once for each function it appears in
    make[1]: *** [Makefile:5842: tools/rctest.o] Error 1
    make[1]: *** Waiting for unfinished jobs….
    make: *** [Makefile:3278: all] Error 2
    pi@raspberrypi(rw):~/bluez-5.50$

    Any ideas?

  3. Add `#include ` to every file that is complaining about this error. From the errors you posted above, that file would be `rctest.c`. Do this for the next file(s) that has the same error. In my case for bluez version 5.48, I did this for `rctest.c` and `l2test.c`.

  4. Add “#include ” to every file that is complaining about this error. From the errors you posted above, that file would be rctest.c. Do this for the next file(s) that has the same error. In my case for bluez version 5.48, I did this for rctest.c and l2test.c.

  5. Guys I save ypu from being sarchastic, but maybe just on script without all prosa would others incredibly help. Furthermore it looks very cumbersome hacking c files with empty includes. It seems a total chaos to me, sry best regards

  6. The SIOCGSTAMP error is due to the fact that you are compiling an older version of bluez with current Linux headers. Get the latest bluez version source and it’ll compile fine.

Leave a Reply to northerntao 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.