Arduino-USBMIDI icon indicating copy to clipboard operation
Arduino-USBMIDI copied to clipboard

ESP32 S2 and S3 support??

Open jhsa opened this issue 3 years ago • 36 comments

Would it be possible to make this library work with the ESP32 S2 and S3? Both support native USB. Thanks

jhsa avatar Sep 06 '22 14:09 jhsa

I don't have the hardware, it crossed my mind, but hoping other would contribute - you? (What underlying lib from S2 or S3 can we use?)

lathoub avatar Sep 06 '22 14:09 lathoub

I believe this one can do it as well. But I do prefer the way you library handles the MIDI, based on the arduino midi library which is quite intuitive for a beginner like me. About the hardware, are you in Europe?

https://github.com/adafruit/Adafruit_TinyUSB_Arduino

jhsa avatar Sep 06 '22 15:09 jhsa

I’ll have a look at the Tiny-USB API (Yes, Europe based (Belgium))

lathoub avatar Sep 06 '22 15:09 lathoub

Cool, I am in Germany. Is there a way we can send Private messages here?

jhsa avatar Sep 06 '22 15:09 jhsa

The ESP32 S2 can do WiFi and native USB but it cannot do BLE Midi unfortunately. The ESP32 S3 should be able to do all of them. This board seems to be quite new and it is still a bit expensive. I am still waiting for it. I do have a couple ESP32 S2 Mino though.

jhsa avatar Sep 06 '22 16:09 jhsa

Is there anything new known about USB MIDI on the ESP32-S3?

I want to build a MIDI instrument that can switch between BLE MIDI and USB MIDI. I am hoping the S3 can do this.

DonWT avatar Jul 07 '23 14:07 DonWT

I did found this and looks promising (albeit USB only), but i never tried - can you try?

lathoub avatar Jul 08 '23 19:07 lathoub

I don't have an S3 right now but I will order one and give it a try.

DonWT avatar Jul 08 '23 23:07 DonWT

I am successfully using Serial, USB, BLE, and RTP Midi on an S3. All in the same project. For the USB I am using the library I have linked above. "TinyUSB" I do love the ESP32-S3 board by the way. Very versatile.

jhsa avatar Jul 14 '23 17:07 jhsa

Cool! Can you post the code on how to use TinyUSB with this lib?

lathoub avatar Jul 14 '23 17:07 lathoub

Cool! Can you post the code on how to use TinyUSB with this lib?

Well, I believe I use the "TinyUSB" library instead of this one, not "with" this one. Also, I think I am using the "TinyUSB" library because I couldn't make this one work at the time. Don't know if anything changed lately. But I can post how I use it. The following is just an example:

#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, MidiUsb);

// Create a new instance of the Arduino MIDI Library for serial
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, DIN_MIDI);

void setup() {
//************ USB MIDI init ***************
  TinyUSBDevice.setManufacturerDescriptor("My_Manufacturer");
  TinyUSBDevice.setProductDescriptor("iL9_USB");


  MidiUsb.begin(MIDI_CHANNEL_OMNI);

  MidiUsb.setHandleProgramChange(USB_ProgramChange);
  MidiUsb.setHandleControlChange(USB_ControlChange);
}

void USB_ProgramChange(byte channel, byte program) {
// Do whatever needs to be done when receiving Program Change.
}

void USB_ControlChange(byte channel, byte controller, byte value)
{
// Do whatever needs to be done when receiving Control Change.
}

void loop() {

MidiUsb.read();

}

And to send MIDI via USB:

MidiUsb.sendControlChange(Control, Value, Channel);  // To send Control change messages

MidiUsb.sendProgramChange(Program , Channel);    // To send Program change messages

The picture shows the Boards configuration I use to make it work.

ESP32-S3_IDE Configuration

jhsa avatar Jul 14 '23 18:07 jhsa

Looks like TinyUSB exposes a serial interface (rather than a USB device). Good to know Thx for the research

lathoub avatar Jul 15 '23 13:07 lathoub

I am successfully using Serial, USB, BLE, and RTP Midi on an S3. All in the same project. For the USB I am using the library I have linked above. "TinyUSB" I do love the ESP32-S3 board by the way. Very versatile.

Would you please tell me which board you are using.

DonWT avatar Aug 19 '23 13:08 DonWT

I am successfully using Serial, USB, BLE, and RTP Midi on an S3. All in the same project. For the USB I am using the library I have linked above. "TinyUSB" I do love the ESP32-S3 board by the way. Very versatile.

Would you please tell me which board you are using.

ESP32-S3 N16R8 It has two USB type C connectors.

https://www.aliexpress.com/item/1005004629274672.html?spm=a2g0o.order_list.order_list_main.355.23bb1802Wew09f

jhsa avatar Aug 20 '23 13:08 jhsa

Would you please tell me which board you are using.

ESP32-S3 N16R8 It has two USB type C connectors.

https://www.aliexpress.com/item/1005004629274672.html?spm=a2g0o.order_list.order_list_main.355.23bb1802Wew09f

Thank you.

DonWT avatar Aug 20 '23 14:08 DonWT

Here are my findings so far.

I am using a very similar board to jhsa - a cheap clone of the Espressif ESP32-S3-DevKitC-1 (note not the current version 1.1): https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1-v1.0.html

Arduino 2.2.1 with the following board settings:

image
Basically, the board has to be in USG-OTG mode.

Connected to the USB-OTG port on the board (labelled USB underneath the board), nothing on the USB to Serial port (labelled COM).

image

(Working with this board requires a lot of button presses so I brought out the Boot and Reset buttons to make it easier to use. I added a direct connection to D+ D- to see if that made any difference and it did not).

What works:

  1. The Adafruit TinyUSB midi_test at https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/examples/MIDI/midi_test/midi_test.ino with one modification: I needed to add a Delay(1000) call after the Serial.begin(115200), without this the sketch just hangs.

  2. This minimal sketch:

#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() { Serial.begin(115200); delay(1000); MIDI.begin(); }

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

What does not work:

Using the USB-MIDI Transport.

The same sketch modified to use USB-MIDI Transport: #include <USB-MIDI.h> USBMIDI_CREATE_DEFAULT_INSTANCE();

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

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

does not compile:

WARNING: library MIDIUSB claims to run on avr, sam, samd architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s). In file included from c:\Users\Don\Arduino\libraries\USB-MIDI\src/USB-MIDI.h:26, from C:\Users\Don\Arduino\ESP32-S3 Cheapo board\ESP32_S3_Kontinuum_USBMIDI_Test_using_transport\ESP32_S3_Kontinuum_USBMIDI_Test_using_transport.ino:1: c:\Users\Don\Arduino\libraries\MIDIUSB\src/MIDIUSB.h:18:2: error: #error MIDIUSB can only be used with an USB MCU. #error MIDIUSB can only be used with an USB MCU. ^~~~~ In file included from c:\Users\Don\Arduino\libraries\USB-MIDI\src/USB-MIDI.h:26, from C:\Users\Don\Arduino\ESP32-S3 Cheapo board\ESP32_S3_Kontinuum_USBMIDI_Test_using_transport\ESP32_S3_Kontinuum_USBMIDI_Test_using_transport.ino:1: c:\Users\Don\Arduino\libraries\MIDIUSB\src/MIDIUSB.h:78:2: error: #error "Unsupported architecture" #error "Unsupported architecture" ^~~~~

exit status 1

Compilation error: exit status 1

FWIW, the same sketch using the BLEMIDI Transport does work:

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

BLEMIDI_CREATE_INSTANCE("MIDI_CONCERTINA", MIDI)

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

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

DonWT avatar Sep 01 '23 09:09 DonWT

Try initialize the serial after the Midi.begin(). Do you still need the delay?

jhsa avatar Sep 01 '23 15:09 jhsa

Try initialize the serial after the Midi.begin(). Do you still need the delay?

No, that works without the delay.

DonWT avatar Sep 01 '23 15:09 DonWT

Try initialize the serial after the Midi.begin(). Do you still need the delay?

No, that works without the delay.

Perhaps one of those things that we aren't supposed to understand ;) Midi is also serial, so maybe the library doesn't like the fact that some other serial started before it tries to start its own serial. and I believe that even the baudrate is the same? I am just guessing of course, but at least now we know we don't need the delay :)

jhsa avatar Sep 01 '23 16:09 jhsa

I have found other situations on this and other ESP32 boards where I need to put in a delay after Serial.begin. For example in setup:

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

If I don't have the delay then that Serial.println does not happen, in this case a full 2 seconds is needed.

DonWT avatar Sep 01 '23 17:09 DonWT

I have found other situations on this and other ESP32 boards where I need to put in a delay after Serial.begin. For example in setup:

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

If I don't have the delay then that Serial.println does not happen, in this case a full 2 seconds is needed.

Yeah, same here, I also sometimes need to add some delays for stuff to work, specially on ESP32 :)

jhsa avatar Sep 01 '23 17:09 jhsa

Or maybe just while (!Serial) { }

jaca2300 avatar Sep 20 '23 14:09 jaca2300

Or maybe just while (!Serial) { }

This does not work on ESP32 S3 boards.

DonWT avatar Sep 20 '23 17:09 DonWT

Is there any outcome or resolution to this thread? It seems to have devolved to discussions of Serial operation.

I'm hoping to send and receive USB Midi on the Espressif ESP32-S3-DevkitC-1 N8R8

ssjimh avatar Apr 13 '24 16:04 ssjimh

Using the AdaFruit TinyUSB library as outlined above works but I have been having problems with the recent recent versions of TinyUSB library.

As of now I am still using version 2.40, anything later than that does not work for me using a Nano ESP32.

DonWT avatar Apr 13 '24 23:04 DonWT

Thanks DonWT, examples compile now without indecipherable error messages. (With V2.40 of the library.) Progress using Espressif ESP32-S3-DevkitC-1 board!

ssjimh avatar Apr 14 '24 02:04 ssjimh

I have experienced two different problems with the Tiny USB library versions after version 2.40.

One is the compile failures that you have seen. These are failures reported when the IDE tries to compile the library itself, not your code. The errors seem to be board dependent, the compile works fine with some boards and not with others.

The other problem is that, at least with my Nano ESP32, the Serial port is not re-established after the midi connection is made. Code is compiled, uploaded and makes the midi connection OK, but any Serial.print statements are ignored. I also have to reset the board into the boot loader before I can upload a new sketch.

Both problems seem to be hardware/board dependent. I have raised the issue on the TinyUSB GitHub but the maintainer only has an Adafruit Feather S3 and he says that he does not see these problems on that board.

Version 2.40 seems to work just fine on the boards that I have and I don't see any compelling reason to want to use a higher version of the TinyUSB library.

Oh, and one other thing. I am using a windows 10 box for development and I have found that the latency between it and my Nano Esp32 running the TinyUSB library is really bad. I can use it for debugging but it would be useless for playing a midi instrument. I don't know if this is because of Windows deficiencies or if it is something to do with the TinyUSB library. The Fourtyseven effects library is not the problem because I can use it for BLE midi connected to an old Android cell phone and that works well, (subjectively) it has low latency.

DonWT avatar Apr 14 '24 18:04 DonWT