I couldn't find a clear solution on the web so here it is, this is probably the easiest way to make a Serial MIDI to BLE MIDI adapter!
First you to install the Control Surface library
And use this code:
// To change the BLE device name modify the file:
// .\Arduino\libraries\Control_Surface\src\MIDI_Interfaces\BLEMIDI.hpp
// ( at line 22-> constexpr const char *BLE_MIDI_NAME = "Control Surface (BLE)"; )
#include <Control_Surface.h>
#include <MIDI_Interfaces/BluetoothMIDI_Interface.hpp>
BluetoothMIDI_Interface MIDI_BLE;
HardwareSerialMIDI_Interface MIDI_SERIAL = Serial;
MIDI_PipeFactory<2> pipes;
void setup() {
MIDI_BLE >> pipes >> MIDI_SERIAL; // all incoming MIDI from BLE is sent to Serial
MIDI_BLE << pipes << MIDI_SERIAL; // all incoming MIDI from Serial is sent to BLE
MIDI_SERIAL.begin();
MIDI_BLE.begin();
}
void loop() {
MIDI_BLE.update();
MIDI_SERIAL.update();
}
And that's it!
I only tried to convert Serial to BLE but it should work both ways.
For the hardware it is pretty simple, just follow the same concept that you would use to read/send MIDI data with an Arduino.
On the ESP32, RX is GPIO3 (U0_RXD) and TX is GPIO1 (U0_TXD).