MIDI over Bluetooth

I sem to remember when bluetooth first appeared on the Pi ( 3?) the general consensus was turn it off. Don’t know how relevant that is in this 4 based world of hoover boards and jet packs… .

I’ve got a yamaha bluetooth MIDI thingy that simply sips it’s power from the MIDI out… :slight_smile: It feels and looks like cheating and I seem to remember proving it but not on a zynth.

Anyone know how to even enable the bluetooth on a Zynthian imaged pi?

Zynthian OS is built on Raspberry Pi OS so it should be similar to that!

I’ve just put together my new Zynthian v4 and I was very eager to make it work with MIDI over bluetooth.

Unfortunately it seems the bluetooth controller is not correctly detected on the RPi4. Even with the pi-bluetooth package installed I could not find any controller (using “hciconfig -a”). My suspicion is that this is due to some patching needed to the uart/serdev kernel drivers. Possibly this should work out of the box with Linux 5.5 (which has improved support for RPi4).

Anyway, I went ahead and used a bluetooth dongle instead, and this worked immediately out of the box. I could pair the device using bluetoothctl and then I was able to use it without any further configuration. (And it was paired automatically upon reboot!)

I might do some further testing to see if I’m able to activate the native bluetooth controller instead.

Edit: I should add that I recompiled bluez with the --enable-midi option.

4 Likes

Great! Good work! Please, document everything in script format, so we can integrate your work easily on the zynthian mainstream.

Regards!

1 Like

Absolutely, I’ll try to provide all the details, it would be great to have this preinstalled. :slight_smile: Btw, thanks a lot for the kit! It was quite a bit of fun to assemble!

Fine bit of research, another way of talking to the zynth!

But, fun eh…? Well fun has a price and right here is where one starts to pay . . . . :face_with_monocle: . . .

1 Like

Yes … my dear @wyleu, lately i find we haven’t enough :face_with_monocle: by here …
We want more :face_with_monocle: … newbies need some presion over his shoulders, or this magnificent tradition would be on risk of being lost!! God shall not allow this to happen!

I’m sorry sir, as you know the natives have been revolting for some time now, and in truth we’ve not managed to get past good in testing where the Brocoli boys are still breaking everything they touch. . .

I’ll chuck a couple of randomly chosen types off this evening but If Sir, didn’t release new kit, then perhaps Sir wouldn’t be having to deal with an influx . . .
would Sir…?

And that zynthian club lot are getting un-ruly, frankly it’s getting like an underground Bazaar down there, apparently some meeting took place in Clacton-On-Sea and fruit and encoders were exchanged. . . .

But worse than that Sir.

They ridiculed me! They laughed outwardly and noisily at the duopiano.ca and hinted my interest wasn’t honourable. . .
And all so we could connect bluetoothly to the two 44 note keyboards…

Sorry Sir,

Very Heavy, Very Humble.

4 Likes

For our newest members missing the occasional humouristic medieval cultural references, Blackadder should be more advertised:

:slight_smile:

1 Like

I did actually buy the duopiano as well, along with a Marshall Stockwell II. I was thinking of something very lightweight that works for traveling.
As for the assembly part, it was really a bit of fun even though there were quite a few steps. I was a bit worried about mounting the “zynductor”, but it worked out just fine. I also managed not to scratch the screen. :smile:

3 Likes

Well, I did find the core issue by inspecting config.txt:

# Disable Blutooth Support for HifiBerry compatibility with RBPi 4
dtoverlay=pi3-disable-bt

By removing this line the controller was detected without a problem.

Are you sure the bluetooth issues with HifiBerry also affects RPi4?

This thread seem to indicate that it does not:

Edit: it looks like we’re forcing bluetooth to use the miniuart since we’re also using this line:

dtoverlay=pi3-miniuart-bt

This may have implications in terms of baud rate and flow control. I’m also going to investigate if we’re able to use one of the main UARTs for bluetooth. It looks like some of the GPIO pins are reserved by the HifiBerry.

2 Likes

Just wanted to add that I’ve successfully paried a Bluetooth MIDI device on my custom Zynth with the onboard Bluetooth device using this guide (in case anyone else find it useful):

**Bluetooth service**

# Get the status of the Bluetooth service.
service bluetooth status

# If the Bluetooth service is not running, start it.
service bluetooth start

# Stop the Bluetooth service only if required.
service bluetooth stop

**Pairing a Bluetooth device**

# Once a device is paired it should automatically pair in future.

# Start the Bluetooth utility.
bluetoothctl

# Make sure the Bluetooth device is powered on.
power on

# Make sure an agent is running for the Bluetooth device.
agent on

# Start a scan for other Bluetooth devices in the area.
scan on

# Wait for the required Bluetooth device to be reported...

# Stop scanning when the required Bluetooth device is found.
scan off

# Attempt to pair the required Bluetooth device.
pair <dev>

e.g. <dev>=00:1D:A5:F7:FF:0D

# Pairing normally prompts for a password. Standard Bluetooth pairing passwords
# are: 0000 or 1234, try these if you are unsure of the password.

# If pairing fails or propt for password does not appear, try the following, and
# then try paring again.
agent off
power off
power on
agent on

# Once paired it should appear in the list of paired devices.
paired-devices

# You can now leave the Bluetooth utility and the device should be paired and
# ready for use.
quit

**Creating a serial device for use in the OBDII application**

# rfcomm associates the paired device ID with a serial device name.
rfcomm bind 0 <dev>

# The device it should create is:
/dev/rfcomm0

# To remove the serial device do the following if required.
rfcomm release <dev>

### Shouldn't need this command, force rfdevices to stop.
### rfkill list

**Unpairing a Bluetooth device**

# Start the Bluetooth utility.
bluetoothctl

# Unpair the Bluetooth device if required.
remove <dev>

# Make sure the agent is stopped for the Bluetooth device.
agent off

# Make sure the Bluetooth device is powered down.
power off

# Exit the Bluetooth utility.
quit

Source: Pairing Bluetooth Devices From A Raspberry Pi Command Prompt - Raspberry Pi Forums

9 Likes

This is really great, @sidor !

We have to integrate this ASAP. I just commited a few changes to the zynthian system configuration so your instructions can work without having to modify /boot/config.txt, etc.

Simply update your zynthian, reboot, and @sidor instructions should work.

Next step is integrating pairing process on UI, but it shouldn’t be too difficult given that most of devices use known/standard passwords and system is smart enough to manage that without prompting the user.

Thanks a lot!

3 Likes

Nice work! How is the latency?

Hello, I would like to try using this, is it in the stable branch, or should i switch to testing? I have many apps on the IPad waiting to be buzzed by zynthian!

If you can connect simple HID (Mouse/keyboard) devices
a mini remote might be enough to scroll through snapshots during a set.

I got a few key-fob remote shutter devices at a Dollar Store, probably being dumped at the near end of life of included coin battery.
This “Smart Lens” brand device has the shutter button which sends a Carriage Return, and 5 media control keys (like computer keyboards have) unfortunately the mapping table in the Zynthian web config page only accepts printable characters?

FYI these common media control devices generate these ASCII codes:

Function . . . . . . . . . . . . . . . ASCII
VolumeDown . . . . . . . . . . . 174 The volume down key.
VolumeUp . . . . . . . . . . . . . . 175 The volume up key.
MediaNextTrack . . . . . . . . 176 The media next track key.
MediaPreviousTrack . . . 177 The media previous track key.
MediaPlayPause . . . . . . . . 179 The media play pause key.

Those 5 keys might be enough to navigate through a preset sequence in the UI.

Amazon Wireless

Here’s an $8.65 example on Amazon
qiguch66 Bluetooth Multi-Media Remote Control Wireless Phone Bluetooth

Aliexpress offering Wireless Bluetooth Remote Control Car Steering Wheel for $4.88

I didn’t get far with Sidor’s Bluetooth configuration steps.
Which resemble a Pi forum post

I’ve had some success with MIDI over BLE. I’ve used the Yamaha UD-BT01 transmitter with wind controllers and running it through a RPi3 with FluidSynth.

I initially started using the RPi on-board BT with BluePy to connect to the Yamaha dongle. The latency was acceptable after tweaking the connection interval. Then Bluez came out with its MIDI over BT, so I gave that a try, thinking it would be better having the connection “built-in” to the OS. It turned out that the latency was significantly longer, and there wasn’t an obvious way of tweaking it, so I reverted to using BluePy.

Since then I’ve decided that a dedicated receiving device is a better option, and I’ve built one to feed serial MIDI to a DIN plug on my synth. I used an ESP32 controller for that. There were still some difficulties getting the connection interval to the minimum, but it was doable.

Now I’m thinking that the CME devices might be a better option. They have the “WIDI Master” and the “Core” chips, which, they say, negotiate the minimum connection interval.

In summary, MIDI over BLE works for me, but the inherent connection interval means it is not as fast as MIDI over USB cable. I suspect that there will be difficulties using the RPi on-board BT with the Zynthian metal case, so an external receiver is likely to be better.

My projects are here: https://gonzos.net/projects/

Gonzo

2 Likes

Hi @gonzoB! Welcome to Zynthianland. Thanks for sharing your insight and experience of MIDI over Bluetooth. It is very useful and interesting. The Raspberry Pi shares a serial port that it uses for Bluetooth communication which had the capacity to interfere with other functionality so it is disabled by default. (This hardware implementation changed on the RPi4.) There have been a few attempts to use MIDI over Bluetooth but generally the results have been unreliable which is bad for performers so we have tended to shy away from it. A reliable, robust, low latency, low power, wireless connection would be beneficial for the type of instrument you have demonstrated. Being able to play a lightweight wind controller without the burden of wires would be good

1 Like

I played around with MIDI over BLE myself (with a Yamaha MDBT01 BT/MIDI adapter), and discovered that one big factor in terms of latency and connectivity is the presence or absence of MIDI clock. In my experience the clock signal easily turns into a “denial of service attack” on the bluetooth link. And this does not only apply to the direction controller → receiver (Zynthian), but the other direction as well. So clock on the back link can slow down the MIDI coming from the controller because it keeps the buffers full and the BT devices busy.

1 Like