Arduino bluetooth MIDI to LED

First post in the community but probably not the last!

I am trying to setup a rather simple idea, preferably using a ESP32.
(I have a WROOM-32 edition)

I want to turn on 4 leds, each of one with a different midi note message.

I ended up using the tttapa Control surface library, starting with the first input example Getting Started

I refined the code to work with the BLE midi library, and with the integrated Arduino pins as suggested here arduino-midi-light-controller

here is the code:

// Include the library
#include <Control_Surface.h>

 
// Instantiate a MIDI Interface to use
BluetoothMIDI_Interface midi;
 
using namespace MIDI_Notes;
 
// Turn on a LED when receiving MIDI Note message
NoteLED leds[] = {
  {0, note(C, 4)}, // LED pin, address (note number, channel, cable)
  {1, note(D, 4)}, //
  {2, note(E, 4)}, //
  {3, note(F, 4)}, //
};
 
// Initialize the Control Surface
void setup() {
  Control_Surface.begin();
}
 
// Update the Control Surface
void loop() {
  Control_Surface.loop();
}

And here are the issues:

multiple instances of "Control Surface MIDI" device are created.
In the serial monitor, this message is on loop:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4916
load:0x40078000,len:16492
load:0x40080400,len:4
load:0x40080404,len:3524
entry 0x400805b8

Sometimes after reuploading the code over and over it works, only one instance of the device will show up, but the Arduino doesn't seem to receive any midi I send from my DAW.

Would be really glad if someone could help with this, maybe @PieterP :upside_down_face: ?

Hi, I can't seem to be able to reproduce the issues you describe on my end. Which version of the Control Surface library and of the arduino-esp32 Core do you have installed?

Although the boot log looks fine, keep in mind that GPIO 0 is a boot pin, so connecting other hardware to it may not be a good idea.

Hello, thank you for taking the time to have a look at this !

I installed the latest version of control surface on GitHub, 1.2.0 I presume?

I have managed to get a steady connection using this board in IDE:
uPesy ESP32 Wroom DevKit

Although each time I unplug and restart the ESP32 it creates a new device, I am able to connect and chose it as "midi to" in Ableton Live. But nothing happens when playing the midi notes

Changing the LED pin numbers, avoiding GPIO 0 didn't change anything unfortunately..

What should be the normal behavior of the esp32? All I have is a steady red light. GPIO 2 should at least blink the onboard blue led when receiving a corresponding midi message, right?

Thank you for your help :folded_hands:

Try the latest main version. 1.2.0 is quite old at this point.

Try adding a debug MIDI output and route the MIDI BLE messages to it, see e.g. Control Surface: MIDI Tutorial, and verify that you're actually receiving MIDI data.

It should turn on for high velocity note messages, off for low/zero velocity note messages. Also, the built-in LED pin depends on the specific board you're using.
When sending note messages, keep in mind that there are different conventions for the note numbers: Control Surface: MIDI_Notes Namespace Reference

I have added debug options to the code:

#include <Control_Surface.h>

// Instantiate a MIDI over USB interface
BluetoothMIDI_Interface midi_BLE;
// Instantiate a debug MIDI interface for debugging in the Serial Monitor
USBDebugMIDI_Interface midi_dbg;
// Instantiate the pipe to connect the two interfaces
BidirectionalMIDI_Pipe pipes;

using namespace MIDI_Notes;
 
// Turn on a LED when receiving MIDI Note message
NoteLED leds[] = {
  {1, note(C, 4)}, // LED pin, address (note number, channel, cable)
  {2, note(D, 4)}, //
  {3, note(E, 4)}, //
  {4, note(F, 4)}, //
  
};

void setup() {
    // Manually route MIDI input from the debug interface to the BLE midi interface,
    // and the MIDI input from the BLE midi interface to the debug interface
    midi_dbg | pipes | midi_BLE;
    // Initialize the MIDI interfaces
    BluetoothMIDI_Interface::beginAll();
}

void loop() {
    // Continuously poll all interfaces and route the traffic between them
    BluetoothMIDI_Interface::updateAll();
}

and I managed to have a bidirectional midi communication between the Arduino and midi monitor on my Mac. But noteLED doesn't do anything

I reinstalled the library from main just to be sure, still no worky :pensive_face:

I'm sure I missed something incredibly simple, just can't understand what.

I am trying to understand the nomenclature for NoteLED.. I changed MIDI_Notes::X(n) to MIDI_Notes::X[n] from my initial code. I tried Note-LED.ino, a basic NoteLED led {2, MIDI_Notes::C[4]}; so that builtin LED responds to midi key C4. I see in the serial monitor it receives Note On for 0x3c, but nothing happens :unamused_face:

The last program you posted does not initialize or update the actual Control Surface, it only updates the MIDI interfaces. Therefore, it won't update the LEDs etc.

Try this:

#include <Control_Surface.h>

// Instantiate a MIDI over USB interface
BluetoothMIDI_Interface midi_BLE;
// Instantiate a debug MIDI interface for debugging in the Serial Monitor
USBDebugMIDI_Interface midi_dbg;
// Instantiate the pipe to connect the two interfaces
BidirectionalMIDI_Pipe pipes;

using namespace MIDI_Notes;

// Turn on a LED when receiving MIDI Note message
NoteLED leds[] = {
  { 1, C[4] },  // LED pin, address (note number, channel, cable)
  { 2, D[4] },  //
  { 3, E[4] },  //
  { 4, F[4] },  //
};

void setup() {
  midi_BLE.setAsDefault();
  // Manually route MIDI input from the debug interface to the BLE midi interface,
  // and the MIDI input from the BLE midi interface to the debug interface
  midi_dbg | pipes | midi_BLE;
  // Initialize the Control Surface
  Control_Surface.begin();
}

void loop() {
  Control_Surface.loop();
}

Regarding the MIDI_Notes syntax: it doesn't matter. New versions of Control Surface simply use square brackets to avoid collisions with Arduino's F(...) macro.

Thank you @PieterP !!
I can confirm it works.
The only thing I can't figure out now, is why it creates a new midi instance each time I boot the esp32. It is named correctly (Control Surface MIDI) but it adds a new entry each time.


Anyhow, at least I can make it work :grinning_face:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.