Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 S2 and S3 support?? #18

Open
jhsa opened this issue Sep 6, 2022 · 36 comments
Open

ESP32 S2 and S3 support?? #18

jhsa opened this issue Sep 6, 2022 · 36 comments

Comments

@jhsa
Copy link

jhsa commented Sep 6, 2022

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

@lathoub
Copy link
Owner

lathoub commented Sep 6, 2022

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?)

@jhsa
Copy link
Author

jhsa commented Sep 6, 2022

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

@lathoub
Copy link
Owner

lathoub commented Sep 6, 2022

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

@jhsa
Copy link
Author

jhsa commented Sep 6, 2022

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

@jhsa
Copy link
Author

jhsa commented Sep 6, 2022

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.

@DonWT
Copy link

DonWT commented Jul 7, 2023

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.

@lathoub
Copy link
Owner

lathoub commented Jul 8, 2023

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

@DonWT
Copy link

DonWT commented Jul 8, 2023

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

@jhsa
Copy link
Author

jhsa commented Jul 14, 2023

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.

@lathoub
Copy link
Owner

lathoub commented Jul 14, 2023

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

@jhsa
Copy link
Author

jhsa commented Jul 14, 2023

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

@lathoub
Copy link
Owner

lathoub commented Jul 15, 2023

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

@DonWT
Copy link

DonWT commented Aug 19, 2023

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.

@jhsa
Copy link
Author

jhsa commented Aug 20, 2023

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

@DonWT
Copy link

DonWT commented Aug 20, 2023

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
Copy link

DonWT commented Sep 1, 2023

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);
}

@jhsa
Copy link
Author

jhsa commented Sep 1, 2023

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

@DonWT
Copy link

DonWT commented Sep 1, 2023

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

No, that works without the delay.

@jhsa
Copy link
Author

jhsa commented Sep 1, 2023

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 :)

@DonWT
Copy link

DonWT commented Sep 1, 2023

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.

@jhsa
Copy link
Author

jhsa commented Sep 1, 2023

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 :)

@jaca2300
Copy link

Or maybe just
while (!Serial) { }

@DonWT
Copy link

DonWT commented Sep 20, 2023

Or maybe just while (!Serial) { }

This does not work on ESP32 S3 boards.

@ssjimh
Copy link

ssjimh commented Apr 13, 2024

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

@DonWT
Copy link

DonWT commented Apr 13, 2024

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.

@ssjimh
Copy link

ssjimh commented Apr 14, 2024

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

@DonWT
Copy link

DonWT commented Apr 14, 2024

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.

@edo44
Copy link

edo44 commented Dec 11, 2024

Waveshare ESP32-S3 ZERO here

Examples compile correctly with Arduino IDE but using platformio I get this error

`CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-fh4r2.html
PLATFORM: Espressif 32 (6.9.0) > Espressif ESP32-S3-FH4R2 (4 MB QD, 2MB PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 @ 3.20017.0 (2.0.17)
  • tool-esptoolpy @ 1.40501.0 (4.5.1)
  • toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
  • toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 39 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- BLE-MIDI @ 2.2.0
    |-- USB-MIDI @ 1.1.3
    Building in release mode
    Compiling .pio\build\esp32-s3-fh4r2\src\main.cpp.o
    Building .pio\build\esp32-s3-fh4r2\bootloader.bin
    Generating partitions .pio\build\esp32-s3-fh4r2\partitions.bin
    esptool.py v4.5.1
    Creating esp32s3 image...
    Merged 1 ELF section
    Successfully created esp32s3 image.
    Compiling .pio\build\esp32-s3-fh4r2\libcc7\MIDI Library\MIDI.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLE2904.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLEAddress.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLEAdvertisedDevice.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLEAdvertising.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLEBeacon.cpp.o
    Compiling .pio\build\esp32-s3-fh4r2\lib86e\NimBLE-Arduino\NimBLECharacteristic.cpp.o
    In file included from .pio/libdeps/esp32-s3-fh4r2/USB-MIDI/src/USB-MIDI.h:26,
    from src/main.cpp:5:
    .pio/libdeps/esp32-s3-fh4r2/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 .pio/libdeps/esp32-s3-fh4r2/USB-MIDI/src/USB-MIDI.h:26,
    from src/main.cpp:5:
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:78:2: error: #error "Unsupported architecture"
    #error "Unsupported architecture"
    ^~~~~
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:129:2: error: 'EndpointDescriptor' does not name a type; did you mean 'NimBLEDescriptor'?
    EndpointDescriptor len; // 9
    ^~~~~~~~~~~~~~~~~~
    NimBLEDescriptor
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:158:2: error: 'IADDescriptor' does not name a type; did you mean 'BLEDescriptor'?
    IADDescriptor iad;
    ^~~~~~~~~~~~~
    BLEDescriptor
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:160:2: error: 'InterfaceDescriptor' does not name a type; did you mean 'MIDI_ASInterfaceDescriptor'?
    InterfaceDescriptor Audio_ControlInterface;
    ^~~~~~~~~~~~~~~~~~~
    MIDI_ASInterfaceDescriptor
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:164:2: error: 'InterfaceDescriptor' does not name a type; did you mean 'MIDI_ASInterfaceDescriptor'?
    InterfaceDescriptor Audio_StreamInterface;
    ^~~~~~~~~~~~~~~~~~~
    MIDI_ASInterfaceDescriptor
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:212:1: error: expected class-name before '{' token
    {
    ^
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:217:2: error: 'EPTYPE_DESCRIPTOR_SIZE' does not name a type
    EPTYPE_DESCRIPTOR_SIZE epType[2]; ///< Container that defines the two bulk MIDI IN/OUT endpoints types
    ^~~~~~~~~~~~~~~~~~~~~~
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:226:21: error: 'USBSetup' has not been declared
    int getDescriptor(USBSetup& setup);
    ^~~~~~~~
    .pio/libdeps/esp32-s3-fh4r2/MIDIUSB/src/MIDIUSB.h:228:14: error: 'USBSetup' has not been declared
    bool setup(USBSetup& setup);
    ^~~~~~~~
    *** [.pio\build\esp32-s3-fh4r2\src\main.cpp.o] Error 1`

@DonWT
Copy link

DonWT commented Dec 11, 2024

|-- USB-MIDI @ 1.1.3

Is this the correct library? Version 3 of the ESP32 platform has its own USB MIDI library - which I have not been able to get working. Maybe you have picked this one instead of the Adafruit library.

@edo44
Copy link

edo44 commented Dec 11, 2024

|-- USB-MIDI @ 1.1.3

Is this the correct library? Version 3 of the ESP32 platform has its own USB MIDI library - which I have not been able to get working. Maybe you have picked this one instead of the Adafruit library.

It is this library

lib_deps =
  lathoub/BLE-MIDI @ ^2.2
  lathoub/USB-MIDI @ ^1.1.3

This setup works on the Arduino IDE but not in platformio.

What should I do with the Adafruit library?

@DonWT
Copy link

DonWT commented Dec 11, 2024

"What should I do with the Adafruit library?"

All I can say is to read all of this forum topic as it does discuss using the Adafruit library for USB MIDI.

For my own project, I am still using an old version of the Adafruit library (v2.40) and an old version of the ESP32 board manager (v2.0.17 -the last one before version 3 was released). I am hoping that one day the various incompatibilities will get sorted out.

I sometimes wish that I had used a Teensy instead of the ESP32 S3.

@DonWT
Copy link

DonWT commented Dec 11, 2024

@edo44

"Examples compile correctly with Arduino IDE"

Have you tried running the resulting code? I suspect that they will not work.

@edo44
Copy link

edo44 commented Dec 11, 2024

"What should I do with the Adafruit library?"

All I can say is to read all of this forum topic as it does discuss using the Adafruit library for USB MIDI.

For my own project, I am still using an old version of the Adafruit library (v2.40) and an old version of the ESP32 board manager (the last one before version 3 was released). I am hoping that one day the various incompatibilities will get sorted out.

I sometimes wish that I had used a Teensy instead of the ESP32 S3.

Wow so annoying. Thank you for the info.

edit: even the Adafruit library compiles correctly with Arduino IDE but not on platformio

@edo44

"Examples compile correctly with Arduino IDE"

Have you tried running the resulting code? I suspect that they will not work.

No I did not, I didn't receive the module I ordered yet.

@edo44
Copy link

edo44 commented Dec 11, 2024

@DonWT

In theory everything should work on Arduino IDE, it's a esp32 core issue and it was recently fixed with 3.0.7

adafruit/Adafruit_TinyUSB_Arduino#467 (comment)

@DonWT
Copy link

DonWT commented Dec 11, 2024

@edo44

In theory everything should work on Arduino IDE, it's a esp32 core issue and it was recently fixed with 3.0.7

adafruit/Adafruit_TinyUSB_Arduino#467 (comment)

But that is about the Adafruit library, not the library that you were trying to use:

lathoub/USB-MIDI @ ^1.1.3

@edo44
Copy link

edo44 commented Dec 11, 2024

@edo44

In theory everything should work on Arduino IDE, it's a esp32 core issue and it was recently fixed with 3.0.7

adafruit/Adafruit_TinyUSB_Arduino#467 (comment)

But that is about the Adafruit library, not the library that you were trying to use:

lathoub/USB-MIDI @ ^1.1.3

If with this library compiles without errors too then there's a good chance there will be no problems when I'm going to load the program onto the esp.

I will find out eventually when I will get the board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants