Raspberry Pi 3B as USB/Bluetooth MIDI host

Here are some instructions for setting up a Raspberry Pi 3B as a MIDI host for USB or Bluetooth musical equipment. The purpose is to build an as-simple-as-possible device with no user interface that can be switched on and off by simply connecting/disconnecting to/from a power source.

This has been tested on the following equipment: a Synthstrom Deluge, a Prophet 12, a Behringer Model D, a Behringer Neutron, an Elektron Analog Keys, a Kawai MP11, a Behringer DeepMind 12, a Novation Circuit, a Waldorf Blofeld Keyboard, an Arturia KeyStep and an iPad 5 with Moog System 15 App and GeoShred.

What we need

Easy instructions

The steps are the following:

  1. Download the RPi-midi SD image
  2. Download and install Etcher
  3. Use Etcher to flash the image to the microSD card
  4. Unmount the microSD and plug it on the Raspberry
  5. Make music!

Complete instructions

The steps are the following:

  1. Prepare the microSD card
  2. Install required packages
  3. Add read-only mode
  4. Configure boot and udev scripts
  5. Configure Bluetooth optional
  6. Configure the LCD display optional

Preparing the microSD card

Post-install packages

Configuring automatic MIDI connection

Enabling read-only mode

Once the setup is finished, it's advisable to make the raspberry read-only to avoid the possibility of microSD data corruption when powering off by unplugging it directly from the power source.


git clone https://gitlab.com/larsfp/rpi-readonly
cd rpi-readonly
sudo ./setup.sh

Once your setup is tested (try plugging and unplugging various MIDI devices, and test connection with the command aconnect -l), you can turn on readonly mode with the command ro. Now you can safely power off the unit by unplugging it from the power source.

In order to modify files, you can turn readonly mode off with the command rw. Just remember to put it back to ro before logging out.

optional MIDI Bluetooth setup

Bluetooth setup involves recompiling the standard GNU/Linux bluetooth stack bluez to enable optional support for the alsa audio toolset. Remember to switch to rw mode before performing the following operations, and to switch back to ro when finished.

git clone https://github.com/oxesoft/bluez
sudo apt-get install -y autotools-dev libtool autoconf
sudo apt-get install -y libasound2-dev
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev
cd bluez
./bootstrap
./configure --enable-midi --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var
make
sudo make install

You should now be able to test Bluetooth MIDI with sudo btmidi-server -v -n "RPi Bluetooth" (change RPi Bluetooth to anything you like) and by discovering Bluetooth MIDI devices with an app that supports that.

Create file sudo nano /etc/udev/rules.d/44-bt.rules with the following content:


ACTION=="add|remove", SUBSYSTEM=="bluetooth", RUN+="/usr/local/bin/connectall.rb"    

Reload udev configuration and daemon with the following commands:


sudo udevadm control --reload
sudo service udev restart

Create a startup file for starting btmidi-server as daemon: sudo nano /lib/systemd/system/btmidi.service


[Unit]
Description=MIDI Bluetooth connect
After=bluetooth.target
Requires=bluetooth.target

[Service]
ExecStartPre=/bin/sleep 6
Type=simple
User=root
Group=root
WorkingDirectory=/home/pi
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=btmidi
Restart=always
ExecStart=/usr/bin/btmidi-server -n "RPi-Bluetooth"

[Install]
WantedBy=multi-user.target

Enable the service:


sudo systemctl daemon-reload
sudo systemctl enable btmidi.service
sudo systemctl start btmidi.service    

Revert to readonly mode with command ro, and reboot (sudo reboot) to test that everything is working.

LCD for seeing active MIDI connections

I'm using a 128x64 1.3' OLED like this (any SSD1306 driver based OLED should work). This script is based on the Adafruit_Python_SSD1306 library.