MIDI USB on the Nano ESP32

@jhaimerl

My Chinese Arduino Nano ESP32 came a little while ago.

What did you buy? Was it one of the Waveshare boards?

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.

I raised this as a bug months ago and it has not been fixed or even acknowledged. The developer was not interested in even trying to compile that tiny program.

This one I got in a day.

https://a.co/d/ik22f9f

It just wasn’t your program- the Adafruit_tinyusb midi example doesn’t compile

@jhaimerl

It just wasn’t your program- the Adafruit_tinyusb midi example doesn’t compile

This was reported in May:

@ptillisch The Adafruit TinyUSB library for midi has been broken for months but jhaimerl prompted me to try my Arduino Nano ESP32 on the following code:

#include "USB.h"
#include "USBMIDI.h"
USBMIDI MIDI;

void setup() {
  Serial.begin(115200);
  delay(4000);
  Serial.println("\n\nStarting!!");
  MIDI.begin();
  USB.begin();
}

void loop() {
  Serial.println("note on");
  MIDI.noteOn(69,100,1);
  delay(1000);
  Serial.println("note off");
  MIDI.noteOff(69,100,1);
  delay(2000);
}

When I try to compile this code using the Arduino Nano ESP32
Arduino ESP32 Boards for my board then it fails with:
"Compilation error: USBMIDI.h: No such file or directory"

When I use the Arduino Nano ESP32 esp32 for my board then it compiles and runs correctly.

It would be really good to have a working USB midi board using the Arduino board especially as the TinyUSB library is no longer usable for midi. TinyUSB 2.40 was the last version that I have been able to use on the Arduino Nano ESP32, all of the versions since then have either failed to compile or failed to connect after an upload.

1 Like

Nice! I see it was added to the "esp32" boards platform in the 3.0.0 release:

The "Arduino ESP32 Boards" platform is a fork of the "esp32" platform, but unfortunately we haven't had the resources to keep it synced with the recent work on the "esp32" platform, so the fork is still at the 2.0.13 point in the "esp32" platform development history, some months behind the time when the USB MIDI support was added to the "esp32" platform.

Fortunately the "esp32" platform also supports the Nano ESP32 board, so the solution you discovered of simply using the latest "esp32" platform instead of the "Arduino ESP32 Boards" platform is perfectly valid.

1 Like

Hello dtone1,

So I have an ESP32S3-WROOM-1 and a Donner N-25 mini midi keyboard that I found on Amazon. I wanted to replicate your MIDI readings on my windows 10 machine, but when I tried to run your code, I got this message on my serial monitor:

ELF file SHA256: 7e7ed6e242a4c853

Rebooting...
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40378b7a
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x109c
load:0x403c9700,len:0x4
load:0x403c9704,len:0xb50
load:0x403cc700,len:0x2fd0
entry 0x403c98ac
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x42025c56  PS      : 0x00060830  A0      : 0x82001f00  A1      : 0x3fcebc30  
A2      : 0x00000000  A3      : 0x3fc94f3c  A4      : 0x3fc95054  A5      : 0x000000ff  
A6      : 0x3fc92124  A7      : 0x00000000  A8      : 0x00000001  A9      : 0x3fcebc10  
A10     : 0x0000005c  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x000000ff  A15     : 0x3fc95538  SAR     : 0x0000000b  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000002  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  


Backtrace: 0x42025c53:0x3fcebc30 0x42001efd:0x3fcebc50 0x42001a3d:0x3fcebc70 0x42004d8a:0x3fcebca0 0x4037d3f2:0x3fcebcc0

Now, what I did was I plugged in my MIDI keyboard to the left usb c port on the esp32, and I plugged in my COM port on my PC to the right usb c port. Is there anything hardware wise that I have to plug in? Or else, am I replicating your hardware setup correctly?

My main goal is to be able to play notes on my keyboard and process them to the esp32. Then from there, I want the esp32 to connect to a bluetooth speaker and output audio that way. Please let me know if you see any issues with this setup.

This section is for topics regarding, in support of, the Nano ESP32.

@jim_stuart

I hardly know where to begin in answering your post as what you are trying to do is very different from what I am doing and what my little code sample does.

When you say that you have an ESP32S3-WROOM-1 then I assume that you mean that you have one of the various Chinese development boards that incorporate an ESP32S3-WROOM-1 and that have two USB-C sockets. If so, then these boards are quite difficult to configure but more importantly you cannot connect two midi over USB cables to the two sockets.

One socket is labelled (maybe underneath the board) as COM and the other as USB. Only the port labelled USB can be used for USB midi. With a bit of hardware finagling, and a lot of software finagling, you might be able to add another USB port to the board that could support USB midi, but doing that is way above my pay grade!

I think that my answer so far probably means that you cannot do what you want to do with an ESP32S3-WROOM-1 development board.

You say:

My main goal is to be able to play notes on my keyboard and process them to the esp32. Then from there, I want the esp32 to connect to a bluetooth speaker and output audio that way. Please let me know if you see any issues with this setup.

You would need to implement a midi synthesizer on the ESP32 to achieve this - not a trivial task!

Have you considered simply plugging your keyboard into a phone running a synth app and then getting the phone to output to a bluetooth speaker?

Don.

Unfortunately, there is a nasty bug in the current version of the Espressif esp version 3.0.3 board manager which makes it pretty tiresome to use:

v3.0 couldn't keep the correct serial port with Arduino Nano ESP32 once RST button is pressed #10025

Hi @dtone1. v3.0 couldn't keep the correct serial port with Arduino Nano ESP32 once RST button is pressed · Issue #10025 · espressif/arduino-esp32 · GitHub is specific to an unusual method of uploading the user is resorting to as a hacky workaround instead of fixing some strange problem with their system:

https://github.com/espressif/arduino-esp32/issues/10025#issuecomment-2231449096

It can't upload through COM11 because "USB DFU" isn't working properly? (I can't see something like "2-5 USB DFU" with COM11 while there is with COM12):

Sketch uses 325557 bytes (10%) of program storage space. Maximum is 3145728 bytes.
Global variables use 30696 bytes (9%) of dynamic memory, leaving 296984 bytes for local variables. Maximum is 327680 bytes.
dfu-util 0.11-arduino4

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

No DFU capable USB device available
Failed uploading: uploading error: exit status 74

If you just do a normal upload via the serial port instead of all that stuff with grounding the B1 pin and doing an "Upload Using Programmer", then there should be no problem.

I just tried it out with the sketch you shared in post #28, with version 3.0.3 of the "esp32" boards platform, and the port number does not change after I reset the Nano ESP32 board. The MIDI messages are sent just as expected.

So are you doing a normal upload to the Nano ESP32 board, or are you using some alternative upload procedure?

@ptillisch I don't think that I am doing anything unusual. I used the standard 'Blink' sketch with an added Serial.println statement:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
  delay(2000);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
  Serial.println("Here");
}

I am using a 'bare' Arduino Nano ESP32 with no additional circuitry. I am using the Arduino IDE 2.3.2 on a Windows 11 computer.

Arduino ESP32 Boards by Arduino:

Compile and (normal) upload with the board set to 'Arduino Nano ESP32' using the 'Arduino ESP32 Boards' version 2.0.13

  1. Compiles and uploads OK, flashes LED and prints 'Here' every two seconds.

  2. Press reset and the board disconnects briefly then reconnects and works the same as in 1.

  3. Disconnect and reconnect the USB cable and the board restarts and works the same as in 1.

  4. Redo the compile and upload without going into boot mode and, again, it works the same as in 1.

All as expected.

esp32 boards by Espressif:

Compile and upload with the board set to 'Arduino Nano ESP32' using the 'esp 32 boards' version 3.0.3

  1. Compiles and (normal) uploads OK, flashes LED and prints 'Here' every two seconds.

  2. Press reset and the board disconnects and stays disconnected, LED flashes but no serial prints. Notifications say:
    Port monitor error: command 'open' failed: Serial port not found. Could not connect to COM4 serial port.
    Compile and upload now fails with:
    No DFU capable USB device available
    Failed uploading: uploading error: exit status 74

  3. (I needed to double press the reset button to get it to compile and upload.)
    Disconnect and reconnect the USB cable and the board restarts, the LED flashes but, again, it fails to connect so there are no serial prints. Same notifications as in 2. Again, I need to double press the reset button to go into boot mode before I can compile and upload again.

I can live with this for development because I want to use the new midi libraries in the Espressif board manager, but I hope that this behavior does not appear when Arduino migrates to the new Espressif board manager.

Great idea to eliminate the MIDI stuff as a potential factor!

I gave it a try, but was not able to reproduce the fault.

After you do this, if you open Arduino IDE's Tools > Port menu, is there a port listed for the board? If so, is the port labeled as "Arduino Nano ESP32" (e.g., "COM5 (Arduino Nano ESP32)"), or as "ESP32 Family Device" (e.g., "COM5 (ESP32 Family Device)"), or labeled as something else, or not labeled at all (e.g., "COM5")?

@ptillisch I get this:

image

COM4 is the device that was connected. I tried connecting to COM7 but it failed with:

Port monitor error: command 'open' failed. Invalid serial port. Could not connect to COM7 serial port

A few days ago I tried to fire up the debugger, which did not work, but I wonder if doing so messed things up in some way. I have Esptool set as my Programmer, but I don't see a way to change this:

image

Could this be a problem?

I am thinking of reinstalling the IDE, maybe to the earlier version that does support the debugger for the Nano ESP32.

Added later:

I uninstalled 2.3.2 and installed 2.2.1 and get exactly the same results. I noticed that all of the IDE settings I had in 2.3.2 also showed up in 2.2.1 - which surprised me as I expected an uninstall to remove everything.

Also, I can repeatedly compile and upload without having to go into boot mode as long as I do not press reset or disconnect the USB cable.

@ptillisch One further thing I noticed is that Windows has a 'Safely Remove Hardware and Eject Media' icon showing in the taskbar when I reconnect the Nano ESP32. Clicking on this shows:

image

I am not trying to use the debugger but looking at this post of yours it seems that the IDE thinks that I am in debug mode:

8 posts were split to a new topic: Problems porting midi controller project to ESP32 board

I am still poking away at using MIDI USB on a Nano ESP32 and other ESP32 S3 boards.

Some observations:

  • I have found that the only reliable version of the Adafruit TinyUSB library that works for MIDI USB is version 2.40. This works really well for the Nano ESP32 (but see later) which uses a customized version 2 of the ESP32 board manager.

  • The 2.40 version of the Adafruit library does not work with an ESP32S3 board using the latest version 3 series of the ESP32 board manager.

  • The 2.40 library works with some ESP32 S3 boards when using a version 2 ESP32 board manager (I am using 2.0.17).

  • I did manage to get version 3.4.1 of the TinyUSB library working once against a version 3 ESP32 board manager (I used 3.0.7) but it was flaky and generated lots of compiler warnings when it did work.

  • (Here is the see later) Arduino are planning to moving to a customized version of the version 3 ESP32 board manager and I suspect that this will not work with version 2.40 of the Adafruit TinyUSB library.

So what to do then?

I hope that the Arduino dev team can find the time to make sure that some version of USB MIDI can be made to work on the Nano ESP32 going forward.

Hi there !
I read this post a few weeks ago before I started developing a solution involving fetching http calls to control remote MIDI CC sending. I don't know where your research is going but for my part everything works with the latest espressive 32 sources and the USB and MIDIUSB libraries. I use a Waveshare ESP32 S3 card from Ali Express and I simply bootloaded following the process described for the ESP32 S3 nano from Arduino. If you would like more details, I will be happy to help you.

@crossrec

Using Windows 11, IDE 2.3.4 and the esp32 board manager 3.0.7.

What happens for me when I use the Espressif sources and the USB and MIDIUSB libraries is that I can compile and run my test programs on both an Arduino Nano ESP32 and a Waveshare ESP32 S3.

Both boards work until I disconnect and then reconnect the USB connection. Then both boards change their COM port to another port that the board then fails to connect. Same thing with a simple reset. If I put the board into boot mode (double reset) and re-upload the test program then it will work again.

So,for me, this approach only works for development testing and not for a live use-case.

I have a couple of other ESP32 S3 boards and they behave differently again but none of them work reliably.

EDIT: Never mind! I saw @dtone1's example with USBMIDI. It works on Seeed Studio Xiao ESP32 S3.

Hey @crossrec,

Do you mind sharing a simple/toy example? I am trying get midi working with a Seeed Studio Xiao ESP32 S3 board.

This problem has been discussed over on the Espressif Github forum:

This solution worked for me. (You may have to try it a few times to get everything right, but once it is working then you are good to go).

  1. Set the board to be Arduino Nano ESP32 - it does not matter if you use the Arduino ESP32 Boards or the Espressif esp32.
  2. Jumper B1 to ground, press reset and the remove the jumper.
    
  3. Tools-> Burn Bootloader
    
  4. Compile the modified Blink sketch then Upload Using Programmer
    
  5. Press reset and change the COM port to the one in use now.
    
  6. The sketch runs and does not lose the COM port after a reset or power down/up
    

I can now recompile and normal upload and that now works OK.

2 Likes