Surface Control Project : with esp 32 S2 mini ?

I am currently working on a project for a plug-and-play USB-C connected control surface for my Mac. The goal is to control the volume of my sound card via Totalmix using a KY040 encoder, and to add six buttons for shortcuts such as launching applications I will also use a OLED display.

Currently, I am using an ESP32 S2 mini but I am facing difficulties uploading the necessary libraries, including Control_Surface.h and HID-Project.h.

I'm reaching out to the community for help in choosing the most suitable chip for this project, considering MIDI, USB-C functionalities, and the requirement that the controller should be plug-and-play. If anyone has recommendations for a specific chip or insights on maintaining plug-and-play functionality, I would be extremely grateful for your shared experiences.

Thank you in advance for your valuable assistance!

Why this particular chip? It seems overkill for your project in terms of capabilities. It's also relatively new and there's a chance the libraries you mentioned may not have been adapted for this chip yet.

Why not choose a simple Arduino Pro Micro? (Don't confuse with Pro Mini)

1 Like

I don't have an ESP32 S2 to try it out, but it seems that USB MIDI support has been added for the upcoming release: Add USB MIDI support to libraries/USB by EleotleCram · Pull Request #8166 · espressif/arduino-esp32 · GitHub

You'll have to add the following to your additional board manager URLs in the IDE preferences:

https://github.com/espressif/arduino-esp32/releases/download/3.0.0-alpha3/package_esp32_dev_index.json

Untested:

#include <Control_Surface.h>

#if ARDUINO_USB_MODE
#error "This sketch should be used when USB is in OTG mode"
#endif

#include "USB.h"
#include "USBMIDI.h"

// This class defines how to send and receive MIDI data using your custom
// backend.
struct MyUSBMIDIBackend {
  // USB MIDI packages are 4 bytes.
  using MIDIUSBPacket_t = AH::Array<uint8_t, 4>;
  // Called once upon initialization.
  void begin() { backend.begin(); USB.begin(); }
  // Read a single packet. Return a packet of all zeros if there is no packet.
  MIDIUSBPacket_t read() {
    midiEventPacket_t packet{0, 0, 0, 0};
    backend.readPacket(&packet);
    return {packet.header, packet.byte1, packet.byte2, packet.byte3};
  }
  // Write a single packet to the output buffer.
  void write(MIDIUSBPacket_t p) {
    midiEventPacket_t packet{p[0], p[1], p[2], p[3]};
    backend.writePacket(&packet);
  }
  // Transmit the output buffer immediately.
  void sendNow() { /* not implemented */ }
  // No explicit call to sendNow is required.
  bool preferImmediateSend() { return false; }
  // The actual low-level USB MIDI backend provided by the core libraries.
  USBMIDI backend;
};

// This is the actual MIDI interface that makes use of the backend defined above.
struct MyUSBMIDI_Interface : GenericUSBMIDI_Interface<MyUSBMIDIBackend> {
  MyUSBMIDI_Interface() = default;
  using MIDIUSBPacket_t = MyUSBMIDIBackend::MIDIUSBPacket_t;
};

MyUSBMIDI_Interface midi;

void setup() {
  Control_Surface.begin();
}

void loop() {
  Control_Surface.loop();
}

See the following example for a bit more details about USB MIDI backends: Control Surface: Custom-USB-MIDI-Backend.ino

You right a pro micro is better for my project and more simple to code with. Sorry it's because im new to coding and i thought a esp 32 S2 was simpler. Thank you for your help !

Im gonna test that ! thank you ! does it make plug and play without other application on your computer ?

It should, yes.

Let me know if you encounter any issues.

One thing I didn't mention: You'll have to install the very latest version of Control Surface for this to work (the one I pushed yesterday).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.