Add tinyusb ESP/IDF component to Arduino Framework?

Is there a way to add the ESP/IDF tinyusb component (as a library?), so I could run code like this example: Example code for midi over tinyusb in the Arduino framework? If so could you point me to an example?

(I’m looking for a simplified midi response, the code I have hacked right now is using up too many processing cycles.)

Thanks

Greg

Per adafruit/Adafruit_TinyUSB_Arduino, the Arduino-ESP32 core is supported for the chips that have the needed USB hardware (ESP32-S2, ESP32-S3) and they do have MIDI examples. I’ve pulled them into PlatformIO with this little example project:

https://github.com/maxgerhardt/pio-esp32s23-midi-test1

That uses the standard latest stable 2.0.16 Arduino-ESP32 version. However, in the Arduino-ESP32 3.x alpha, the USB library was expanded to also included MIDI USB (see here). And since we can also use that in PlatformIO thanks to the Tasmota project, this sketch can also be compiled.

https://github.com/maxgerhardt/pio-esp32s23-midi-test2

Check if any of those fit your needs (or work at all). If those two fail to achieve the results you want, you can still use the “ESP-IDF plus Arduino as an ESP-IDF component” way to add TinyUSB into Arduino and run the (only slightly modified) reference tusb_midi_main.c code. See https://github.com/platformio/platform-espressif32/tree/develop/examples/espidf-arduino-blink for the platform reference.

Thanks for those examples, unfortunately they don’t seem to work for me or my ESP32S3 clone acting as a USB host with a USB B midi keyboard. I can get it to work old school with just <usb/usb_host.h> and reading the data packets and extracting midi info but I can’t seem to get anything with MIDI.h or USBMIDI.h to work.

Do you know when Arduino-ESP32 3.x might release officially?

Thank you

…but, the example you linked to is configuring the ESP32-S(2,3) to be a USB device, not a host. So that’s not the type of code you wanted to run at all? The ESP32 should be a USB host and read the USB MIDI it receives? And then do what, print them over serial?

Basically something like that. I’m connecting a usb b midi keyboard to the esp32s3 and reading the key values. Then I play the note using Mozzi on an I2S speaker. I also want to send the note via MQTT to a nodered app running on a computer. I have it working but the usb update is too slow and blocking and causing static on the speaker. Was hoping tinyusb might be faster and non blocking? Is this a reasonable approach? What do you think?

USB Host support in (Adafruit) TinyUSB is way more sparse than USB device support. There are some pointers in https://github.com/adafruit/Adafruit_TinyUSB_Arduino/issues/360 and https://github.com/hathach/tinyusb/pull/1627 and https://github.com/rppicomidi/usb_midi_host/tree/main, the code may be compatible for ESP32*.

Some generic USB host examples seem to be at

https://github.com/adafruit/Adafruit_TinyUSB_Arduino/blob/master/examples/Host/Simple/host_device_info/host_device_info.ino

https://github.com/hathach/tinyusb/tree/master/examples/host

But they are very barebones and don’t include MIDI USB decoding. Whether they’re faster than the ESP-IDF’s native library is also questionable.

Thank you,

Basically I have hacked this code: esp32-usb-host-demos/examples/usbhmidi/usbhmidi.ino at main · touchgadget/esp32-usb-host-demos · GitHub to read the midi info and I removed all the midi writing portions. Works great but I don’t think it is efficient with sharing processing time with other time sensitive tasks. Not really knowing much about the USB transmission process I’m not sure if there is a way to get this code to play nicer with Mozzi?