The Bluefruit nRF52 BSP codebase is undergoing active development based on customer feedback and testing. As such, the class documentation here is incomplete, and you should consult the Github repo for the latest code and API developments:

BLEMidi is a helper class that adds support for sending and receiving MIDI Messages using the MIDI over Bluetooth LE specification. BLEMidi supports the full standard MIDI protocol (including SysEx messages), and it also can act as the hardware interface for the Arduino MIDI Library.


BLEMidi has the following public API.

// Constructor
BLEMidi(uint16_t fifo_depth = 128);

err_t     begin         (void);
bool      notifyEnabled (void);

// Stream API for Arduino MIDI Library Interface
int       read       (void);
size_t    write      (uint8_t b);
int       available  (void);
int       peek       (void);
void      flush      (void);

size_t    write      (const char *str);
size_t    write      (const uint8_t *buffer, size_t size);

Installing the Arduino MIDI Library

BLEMidi is easiest to use when combined with the Arduino MIDI Library by Francois Best, lathoub. You will need version 4.3.1 installed before continuing with the example code.

Next, select Communication from the topic dropdown, and enter MIDI Library into the search box. Click the Install button to install version 4.3.0 or higher of the MIDI Library.


The blemidi example demonstrates how to use the BLEMidi helper class with the Arduino MIDI Library. The example sends a looping arpeggio, and prints any incoming MIDI note on and note off messages to the Arduino Serial Monitor.

This example may be out of date, and you should always consult the latest example code in the Bluefruit52 example folder!

 This is an example for our nRF52 based Bluefruit LE modules

 Pick one up today in the adafruit shop!

 Adafruit invests time and resources providing this open source code,
 please support Adafruit and open-source hardware by purchasing
 products from Adafruit!

 MIT license, check LICENSE for more information
 All text above, and the splash screen below must be included in
 any redistribution
#include <bluefruit.h>
#include <MIDI.h>

BLEDis bledis;
BLEMidi blemidi;

// Create a new instance of the Arduino MIDI Library,
// and attach BluefruitLE MIDI as the transport.

// Variable that holds the current position in the sequence.
int position = 0;

// Store example melody as an array of note values
byte note_sequence[] = {

void setup()
  Serial.println("Adafruit Bluefruit52 MIDI over Bluetooth LE Example");

  Bluefruit.setName("Bluefruit52 MIDI");

  // Setup the on board blue LED to be enabled on CONNECT

  // Configure and Start Device Information Service
  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit Feather52");

  // Initialize MIDI, and listen to all MIDI channels
  // This will also call blemidi service's begin()

  // Attach the handleNoteOn function to the MIDI Library. It will
  // be called whenever the Bluefruit receives MIDI Note On messages.

  // Do the same for MIDI Note Off messages.

  // Set General Discoverable Mode flag

  // Advertise TX Power

  // Advertise BLE MIDI Service

  // Advertise device name in the Scan Response

  // Start Advertising

  // Start MIDI read loop

void handleNoteOn(byte channel, byte pitch, byte velocity)
  // Log when a note is pressed.
  Serial.printf("Note on: channel = %d, pitch = %d, velocity - %d", channel, pitch, velocity);

void handleNoteOff(byte channel, byte pitch, byte velocity)
  // Log when a note is released.
  Serial.printf("Note off: channel = %d, pitch = %d, velocity - %d", channel, pitch, velocity);

void loop()
  // Don't continue if we aren't connected.
  if (! Bluefruit.connected()) {

  // Don't continue if the connected device isn't ready to receive messages.
  if (! blemidi.notifyEnabled()) {

  // Setup variables for the current and previous
  // positions in the note sequence.
  int current = position;
  int previous  = position - 1;

  // If we currently are at position 0, set the
  // previous position to the last note in the sequence.
  if (previous < 0) {
    previous = sizeof(note_sequence) - 1;

  // Send Note On for current position at full velocity (127) on channel 1.
  MIDI.sendNoteOn(note_sequence[current], 127, 1);

  // Send Note Off for previous note.
  MIDI.sendNoteOff(note_sequence[previous], 0, 1);

  // Increment position

  // If we are at the end of the sequence, start over.
  if (position >= sizeof(note_sequence)) {
    position = 0;



void midiRead()
  // Don't continue if we aren't connected.
  if (! Bluefruit.connected()) {

  // Don't continue if the connected device isn't ready to receive messages.
  if (! blemidi.notifyEnabled()) {

  // read any new MIDI messages;


You will need to do a small bit of setup on your selected platform to connect to the BLE MIDI enabled Bluefruit52.

Click on a platform below to view BLE MIDI setup instructions for your device:

The arpeggio should automatically play once the Bluefruit52 is connected to your software synth. The video below shows the Bluefruit52 connected to Moog's Animoog on iOS.

Note: The board used in the video was a pre-release prototype. The production boards are standard Adafruit Black.

This guide was first published on Mar 11, 2020. It was last updated on Jun 25, 2024.

This page (BLEMidi) was last updated on Mar 08, 2024.

Text editor powered by tinymce.