MIDI USB on the Nano ESP32

I would like to use the Nano ESP32 in a MIDI controller that I want to build so I am interested to know if it supports USB MIDI and BLE MIDI and, if so, what libraries does it use?

(I have another ESP32-S3 board and have been struggling to get USB MIDI working on that, BLE MIDI works just fine).

The nano can not appear as a midi device itself there is a complicated work around that ive heard of by formatting the chip or something in that area but id stick with leonardo-micro- zero and due or just any any 32U4 based board also the teensy boards are pretty nice with fast clock speed and should work with the same codes 95% of the time but don't take that as gospel i recommend ditching that board and going with one of the above

The original Nano (based on the ATmega328P) indeed cannot, but the Nano ESP32 can (in theory, at least, the software support might not be there yet).

Yes but in theory they all can but its twice as hard to get mega to work as hid then ESP32

This page dives into it a bit but its simpler then the mega where you flash the chip ive tried it and failed an went with leonardo instead and that felt like plug and play compared to trying to brute force something that isnt meant to work her is what i used to try to flash the mega GitHub - NicoHood/HoodLoader2: 16u2 Bootloader to reprogram 16u2 + 328/2560 with Arduino IDE
Its like yes but do you want to?

I have managed to get my ESP32-S3 dev board to talk USB midi using the Adafruit TinyUSB and FortySevenEffects libraries. The board has to be configured in OTG mode and a minor change made to the AdaFruit example code. I will post some code soon.

If the Nano ESP32 can be configured in OTG mode then I think this should work there too.

Currently the Nano ESP32 board definition is configured to always use the "USB-OTG (TinyUSB)" USB mode:

https://github.com/espressif/arduino-esp32/blob/2.0.11/boards.txt#L24146

nano_nora.build.usb_mode=0

Unlike other ESP32 boards, you don't see a Tools > USB Mode menu item in Arduino IDE when the Nano ESP board is selected. That is because support hadn't been added to the board definition for putting it in the alternative "Hardware CDC and JTAG" mode, so there would have been no point in adding a menu that only contained a single option. The USB Mode menu with both mode options will be available starting from the next release of the esp32 boards platform:

Please forgive this long post.

Here is a simple example of some code that works on my ESP32-S3 dev board:

#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>

// USB MIDI object
Adafruit_USBD_MIDI usb_midi;

// Create a new instance of the Arduino MIDI Library,
// and attach usb_midi as the transport.
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);

void setup() {
  MIDI.begin();
  Serial.begin(115200); // <<------ See note in forum post
}

void loop() {
  MIDI.sendNoteOn(69, 127, 1);
  Serial.println("Note on");
  delay(1000);      
  MIDI.sendNoteOff(69, 127, 1); 
  Serial.println("Note off");
  delay(1000);
}

The original Adafruit example had setup code like this:

void setup() {
  Serial.begin(115200);
  MIDI.begin();
}

Having these two statements in this order results in the code hanging at this point.

In general, there seems to be a bug in the ESP32 Serial code because if I want to use Serial.println() in setup then I have to put a delay after Serial.begin(), like this:

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("Starting...");

Anyway, back to the above example. I can monitor the midi output in Midiview on my Windows 10 machine:

One annoying behavior on my ESP32-S3 board is that the Windows COM port used for uploading (COM7 on my machine) is not the same as the COM port used for Serial.print calls (COM8) on my machine. This means that I always have to go into Boot mode before uploading, switch COM ports and then switch COM ports again to see the Serial.print calls.

Finally, here is an example of the same program using BLE midi:

#include <BLEMIDI_Transport.h>
#include <hardware/BLEMIDI_ESP32.h>

BLEMIDI_CREATE_INSTANCE("MY_MIDI_DEVICE", MIDI)

void setup() {
  Serial.begin(115200);
  delay(2000);
  MIDI.begin();
}

void loop() {
  MIDI.sendNoteOn(69, 127, 1);
  Serial.println("Note on");
  delay(1000);      
  MIDI.sendNoteOff(69, 127, 1);  
  Serial.println("Note off");
  delay(1000);
}

This code uses the BLE midi transport layer of the fortyseveneffects library, trying to use the USB transport layer yields a not supported message for the ESP32-S3.

I forgot to include my board definitions:

image

5 posts were split to a new topic: Questions about using USB MIDI for ESP32-based DJ controller project

I would really like to see the USB otg port work as a USB midi receiver. I have a synth design working with a different configuration with uhs2-midi but it would be nice to have it all on one instead. The midi callback system has been the best responsive for playing the keyboards. With 2 I2C ports running a couple of hundred 12 bit D/A converters. Audio path is 100% analog.

It would be even better if we could put a hub on it and add several MIDI controllers. I wish that the full USB implementation was published just as previous external ones are.

One thing that I have not been able to do is to get BLE MIDI working on Windows. My application works for USB MIDI to Windows and BLE MIDI to an Android Phone running the FluidSynth app so I do not think that the problem lies in my Arduino code.

I think that the problem is in how I have BLE MIDI set up on my Windows machine. I have tried two different BT dongles, one for BT 4.0 and one for BT 5.3. They both claim to support BLE and, AFAICT, they are configured correctly for BLE.

On Windows I am using MIDIView as the initial recipient for MIDI messages, MIDIView logs the messages and passes them on to VMPK (Virtual MIDI Piano Keyboard) to actually play the sounds.

If I use USB MIDI on my Nano ESP32 connected to my Windows PC then all of the messages are logged by MIDIView and the sound played by VMPK. When I try to use BLE MIDI on my Nano ESP32, or on any other ESP32 boards that I have, then nothing shows up in MIDIView - the BLE MIDI messages are not getting through to MIDIView.

I think that I need some kind of virtual connector/wire between the BLE driver and MIDIView but I don't know what this might be.

Any suggestions?

Hi dtone1,
What ESP32-S3 module are (were) you using?
I have been trying to pick one that lets me use USB for MIDI, UART pins for RS-485 DMX lighting control, and setup a temporary WIFI to host a web-page that user can configure operating parameters. I have used Arduino Pro Micro successfully with USB MIDI and DMX, Teensy 4.1 with USB MIDI and DMX, and ESP32-WROOM for wifi/bluetooth (including MIDI). There doesn't seem to be one module that does everything I want...
Thanks!

@jhaimerl I am using an Arduino Nano ESP32 and this gives me MIDI over both USB and BLE. Despite the name, the Nano ESP32 is actually an ESP32-S3 which is required for MIDI over USB. An older ESP32, like a LOLIN D32, will only support MIDI over BLE.

I can't answer about your other usage of the USB but the Nano ESP32 uses the Adafruit TinyUSB library for accessing its USB port so reading up on this library may give you some answers.

However, I should warn you that more recent versions of this library have not been stable for me (and others) - I am still (happily) using version 2.40 of the library while the current version is 3.x.

1 Like

Great thanks!

You mentioned another board which I thought you had working before the Nano ESP32. Do you recall what the ESP32-S3 dev board was??? ( "I have managed to get my ESP32-S3 dev board to talk USB midi using the Adafruit TinyUSB and FortySevenEffects libraries...If the Nano ESP32 can be configured in OTG mode then I think this should work there too.")

@jhaimerl Early on I bought a couple of ESP32-S3 devkit boards off Aliexpress. They were basically no-name knock-offs of the Espressif ESP32-S3 devkit boards, not identical but close.

They were quite fiddly to use both physically and to configure in the Arduino IDE.

Hardware-wise, they are too wide for a breadboard and they had a CP2102 USB to UART chip on board for which you had find and install a driver. I remember having a lot of problems keeping track of which COM ports to use on my Windows machine and I also had to reconfigure COM drivers using Zadig.

Software-wise, you had to configure about a dozen parameters in the ESP32 board manager to get it to work.

I did get there in the end but it was a huge time waster.

I ordered a Nano ESP32 as soon as it was available and that has been very simple to use and to configure. Plus you get great support from Arduino on these forums. I have switched my project over to the Nano ESP32 and have not touched the ESP32-S3 devkit boards since then.

Thanks! Understood about Arduino support!

I am buying both a NanoESP32 and an Espressif ESP32-S3 dev board and comparing... The ESP32-S3 is 3/4 the price and no-name ones are less than half....

I like the Teensy 4.1 the best out of all MCUs, but it doesn't have wireless. (BTW support for Teensy seems even a notch up from Arduino to me) I am trying to avoid adding a display screen and buttons on my project. A hot spot that you could connect to with a configuration page seems the cleanest approach. Obviously an all-in-one processor would be best... I could always pair a second MCU with wireless capabilities (older ESP32's are <$9), but that makes upgrading significantly more difficult (either don't provide an update method for the wireless portion, or somehow put two USB ports on the side of the unit...). I guess I could always minimize the functionality in wireless portion and have the Teensy push that over...

Anyway, I greatly appreciate your response. I will probably be trying to get the USB MIDI operational next week on the NanoESP32 and the Espressif ESP32-S3...

@jhaimerl I agree with you about Teensy's support but I really wanted BLE MIDI.

Another board showed up recently based on the ESP32 S3R8 chip, a new chip with a much smaller footprint than the regular ESP32 S3. A Chinese board maker called Waveshare has released an "ESP32-S3-Nano" which they claim to be compatible with the Arduino Nano ESP32, see:

I have not tried one of these but the pinout looks to be the same, it does have a different antenna, not sure about the rest of the board.

My Chinese Arduino Nano ESP32 came a little while ago. I was able to get a couple simple programs working relatively quickly, but I can't get it to work with Adafruit_TinyUSB... Either your code or the example they provide... Keep getting a "CDC" related error on compile... I have tried the other option under the Tools menu ... USB Mode -> Normal Mode (TinyUSB) and Debug Mode (Hardware CDC). Both return same errors... This is the first compiler error in the long string:
/Users/josephhaimerl/Documents/Arduino/libraries/Adafruit_TinyUSB_Library/src/device/usbd.c:120:10: error: 'usbd_class_driver_t' {aka 'const struct '} has no member named 'name'
.name = DRIVER_NAME("CDC"),

I dropped back to Adafruit_TinyUSB 2.40 and used your exact code and NOW it compiles... Also tested that it works with Ableton Live....
Not sure why most recent Adafruit library causes compile errors.