{"id":348,"date":"2016-05-27T06:13:34","date_gmt":"2016-05-27T06:13:34","guid":{"rendered":"http:\/\/projects.gonzos.net\/?page_id=348"},"modified":"2025-07-27T22:09:25","modified_gmt":"2025-07-27T12:09:25","slug":"ble-midi-adapter-ud-bt01","status":"publish","type":"page","link":"https:\/\/gonzos.net\/projects\/ble-midi-adapter-ud-bt01\/","title":{"rendered":"BLE Midi Adapter &#8211; UD-BT01"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter\"><a href=\"https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"223\" src=\"https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01-300x223.jpg\" alt=\"udbt01\" class=\"wp-image-360\" srcset=\"https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01-300x223.jpg 300w, https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01-768x572.jpg 768w, https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01-1024x762.jpg 1024w, https:\/\/gonzos.net\/projects\/wp-content\/uploads\/2016\/05\/udbt01-730x543.jpg 730w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure>\n\n\n\n<p class=\"has-text-align-center\"><\/p>\n\n\n\n<p class=\"has-text-align-right\">Update 10 June&nbsp;2016<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Background:<\/h2>\n\n\n\n<p>Early in 2016 Yamaha released a couple of Bluetooth Low Energy MIDI adapters. The one that interested me was the USB model (UD-BT01) &#8211; I hoped it could be used with&nbsp;my USB-connected Akai EWI-USB wind controller. The EWI has a cable that powers it from a USB port and carries the MIDI messages to and from the synthesiser. The UD-BT01 is advertised as being only compatible with Apple MIDI products, but the attraction of being able to cut the cord to the synth was too strong &#8211; I bought one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Problems:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Bluetooth peripherals are coded to tell the computer\u00a0they connect to what type of device they are (e.g. mouse, keyboard, heart monitor). To date, only Apple has published a standard for sending MIDI over Bluetooth, and it applies to only Apple products, which\u00a0means that MIDI Bluetooth peripherals will not be recognised by non-Apple equipment. This is because the TYPE\u00a0of device (MIDI) is not recognised in the general Bluetooth standard (as opposed to the Apple spec). The UD-BT01 can be SEEN by other systems (Windows, Linux), but it won&#8217;t connect automatically. A custom program to connect is required.<\/li>\n\n\n\n<li>Bluetooth LE is still fairly young, and, while programming languages exist to handle the connections, the documentation is thin, and there aren&#8217;t many examples available to use as models.<\/li>\n\n\n\n<li>The details of how to connect to and get data from a &#8220;Designed-For-Apple&#8221; peripheral are not readily available, so there&#8217;s a lot of trial-and-error involved if you don&#8217;t have the information on this page.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Solutions:<\/h2>\n\n\n\n<p>I have worked out a way of connecting the Yamaha UD-BT01 to a Raspberry-Pi. It works pretty well. My <a href=\"https:\/\/gonzos.net\/projects\/ewi-pi\/\" target=\"_blank\" rel=\"noopener\">EWI-PI project<\/a> has all the programs, but here I want to just give the key ideas for others attempting to do the same.<\/p>\n\n\n\n<p>You need to refer to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.apple.com\/bluetooth\/Apple-Bluetooth-Low-Energy-MIDI-Specification.pdf\" target=\"_blank\" rel=\"noopener\">The Apple Bluetooth Low Energy MIDI Specification<\/a>. This gives the details of how the MIDI messages, including Sysex messages, are packaged.<\/li>\n\n\n\n<li>Ian Harvey&#8217;s <a href=\"https:\/\/github.com\/IanHarvey\/bluepy\" target=\"_blank\" rel=\"noopener\">BluePy<\/a>. This is the python interface for Bluetooth LE on Linux.<\/li>\n<\/ul>\n\n\n\n<p>To connect to the UD-BT01 you will need the Bluetooth address for your unit. They are all different. You can find out what the address is by using a computer or phone to do a LE scan when the adapter is powered up. When you have discovered the address&nbsp;you can then connect using BluePy. You need to connect in &#8220;random&#8221; mode. There are examples of how to connect in the BluePy on-line docs.<\/p>\n\n\n\n<p>To send to and receive data from the UD-BT01, you need information about the Bluetooth &#8220;handles&#8221;. A GATT scan will show that the handle for the MIDI data is decimal 26. What it won&#8217;t show you is that data needs to be sent to handle 27, and the handle for enabling notifications is 28. I don&#8217;t know if these are &#8220;standards&#8221; for BLE (sending is at data+1 and notifications is at data+2), but that&#8217;s what I found. To enable notifications, after connecting you need to send 0x01 0x00 to handle 27. When that is done the peripheral (server) will send a notification to the computer (client) each time new data arrives, and the computer then asks the peripheral for the data. BluePy\/Bluez does this automatically for you.<\/p>\n\n\n\n<p>During the connection negotiation process, the peripheral sends the computer &#8220;Peripheral Preferred Connection Parameters&#8221;. These are suggestions, and the computer can ignore them. In practice I discovered that the RPi produced high latency with the default set of parameters. I was unable to discover what those parameters were, but when I re-configured the connection using the Linux hcitool I got a good result. The command I used was:<\/p>\n\n\n\n<p>sudo hcitool lecup &#8211; -handle $HANDLE &#8211; -min 6 &#8211; -max 6 &#8211; -latency 0 &#8211; -timeout 500<\/p>\n\n\n\n<p>Where $HANDLE is the number of the computer&#8217;s connection handle (NOT the UD-BT01&#8217;s connection handle &#8211; they are different), &#8211; -min is the minimum connection interval (6 x 1.25msec = 7.5msec, the minimum for BLE), &#8211; -max is the maximum connection interval, &#8211; -latency is the number of intervals the peripheral can delay replying to the computer&#8217;s message, and &#8211; -timeout is the time that must elapse before a dead connection is re-established by the computer (500 x 10msec = 5sec). The min\/max\/latency settings I have used here give the minimum latency.<\/p>\n\n\n\n<p>To get the computer&#8217;s handle number, use:<\/p>\n\n\n\n<p>sudo hcitool con<\/p>\n\n\n\n<p>The UD-BT01 appears to have a 20-byte maximum message length. I don&#8217;t know if this is configurable during the &#8220;negotiation&#8221; process, but that&#8217;s what mine defaulted to. The Apple spec implies it can be changed. MIDI commands are 3 bytes long, and with the additional header and timestamp bytes (see the Apple spec), it means that a maximum of 4 MIDI commands can be sent per message. Your program will have to determine how many commands are contained in each message (it varies). In addition, Sysex commands&nbsp;can be sent. These can be long, and may be broken up into multiple messages, so as not to exceed the 20-char limit. See the Apple spec for details. Your program will have to determine if each message is a Sysex (third character is 0xF0).<\/p>\n\n\n\n<p>Header and timestamp bytes are added to the messages. For my particular application (live performance) they are not important, however, when sending header and timing bytes TO the UD-BT01, they need to meet the specification. The header byte actually contains part of the timing information (see the Apple spec), but has a minimum value of 0x80 (with a timestamp of zero), likewise the timing byte has a minimum value of 0x80. Successive timing bytes need to be increasing, so for the Sysex commands I have used the following sequence: 0x80 0x81 0x82 0x83 &#8230; This series need to be consistent only within each &#8220;batch&#8221; of Sysex commands. You can start from 0x080 again for the next &#8220;batch&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Interesting Stuff:<\/h2>\n\n\n\n<p>The Bluetooth connection to the computer is completely independent from&nbsp;the USB connection between the adapter and the instrument (EWI-USB in my case). You can unplug the instrument from the adapter, while&nbsp;keeping the adapter powered up, and then re-connect the instrument. It won&#8217;t affect the Bluetooth connection.<\/p>\n\n\n\n<p>The power required to run the adapter and my EWI-USB is really small. I have left the instrument powered up for a 24-hour period and used only 1\/4 of a 8000mAh battery pack<\/p>\n\n\n\n<p>The Bluetooth connection needs to be re-configured each time it starts. So, if the connection is lost for some reason, and then re-made, you will have to run the hcitool command (above) again. I have put this command in a batch file which checks the handle number to see if it has changed, and if it has (the connection has been re-made) it runs the command again.<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 10 June&nbsp;2016 Background: Early in 2016 Yamaha released a couple of Bluetooth Low Energy MIDI adapters. The one that interested me was the USB model (UD-BT01) &#8211; I hoped it could be used with&nbsp;my USB-connected Akai EWI-USB wind controller. The EWI has a cable that powers it from a USB port and carries the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-348","page","type-page","status-publish","hentry"],"blocksy_meta":{"page_structure_type":"type-3","styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/pages\/348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/comments?post=348"}],"version-history":[{"count":1,"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/pages\/348\/revisions"}],"predecessor-version":[{"id":2427,"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/pages\/348\/revisions\/2427"}],"wp:attachment":[{"href":"https:\/\/gonzos.net\/projects\/wp-json\/wp\/v2\/media?parent=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}