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.