martinzw / THRII-direct-USB-pedalboard

A pedalboard that can send complete settings patches to a THRII guitar amplifier with direct USB-connection
31 stars 5 forks source link

Bluetooth LE Feasibility #5

Open bariskalem opened 1 month ago

bariskalem commented 1 month ago

Hi Martin,

Your detailed protocol document was extremely helpful to understand the SysEx. Thank you for that! I wanted to ask if you are aware of the feasibility of using BLE to send the SysEx data to the THR system.

I have an ESP32 devkit and using the ESP32-BLE-MIDI package to send SysEx to the amp. The idea is to create a preset selector pedal similar to a one available on the market; but cheaper. (see: AIRSTEP YT)

I'm sending over the following SysEx which I understand that they're acting like a handshake with the THR.

byte IDENTITY_REQUEST[]  = { 0xF0, 0x7E, 0x7F, 0x06, 0x01, 0xF7 };

byte VERSION_REQUEST[]  = { 0xF0, // Request THR Amp version
                            0x00, 0x01, 0x0C, // Line6 
                            0x24, // THRII
                            0x02, 0x4D, // THR30IIWireless
                            0x00, // A or B
                            0x00, 0x00, 0x00, 0x07,  //
                            0x00, // 1st bitbucket
                            0x01, 0x00, 0x00, 0x00, // OP
                            0x00, 0x00, 0x00, // FB
                            0x00, // 2nd bitbucket
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Type?
                            0xF7}; 

byte HEADER[]  = { 0xF0, 
                   0x00, 0x01, 0x0C, // Line6 
                   0x24, // THRII
                   0x02, 0x4D, // THR30IIWireless
                   0x00, // A or B
                   0x01, 0x00, 0x00, 
                   0x07, 
                   0x00, 0x04, 0x00, 0x00, 
                   0x00, 0x04, 0x00, 
                   0x00,
                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                   0xF7}; 

byte MAGIC_KEY[]  = { 0xF0, 
                      0x00, 0x01, 0x0C, // Line6 
                      0x24, // THRII
                      0x02, 0x4D, // THR30IIWireless
                      0x00, // A or B
                      0x02, 0x00, 0x00, 
                      0x03, 
                      0x28, 0x72, 0x4D, 0x54, // Magic key for 1.4.4.0.a
                      0x00, 0x00, 0x00,
                      0xF7}; 

Unfortunately, even after connecting to the amp and sending these SysEx, I don't receive any SysEx events back from the amp.

Although, I can see that the ESP32 successfully connects, the amp doesn't react when I send the following preset change SysEx:

byte PRESET_2[]  = { 0xF0, // Request THR Amp version
                     0x00, 0x01, 0x0C, // Line6 
                     0x24, // THRII
                     0x02, 0x4D, // THR30IIWireless
                     0x01, // A or B
                     0x0E, 0x00, 0x00, 0x0B, 
                     0x00, 
                     0x0E, 0x00, 0x00, 0x00,
                     0x04, 0x00, 0x00, 
                     0x00, 
                     0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
                     0xF7}; //                              ^  Preset 2

My code basically utilizes the examples from the ESP32-BLE-MIDI package to create a BLE MIDI Client and send SysEx.

I appreciate your time on this!

Best, Barış

martinzw commented 1 month ago

Hi Bariş,I am on a holiday, so i can not check anything right now.Perhaps one hint:The usb cable must strictly not be connected to the PC, when trying to establish a BLE connection.Sounds obvious, but sometimes we struggle for stupid reasons...And i remember, that someone else already had successfully created a BLE Midi Sysex communication some time ago.Perhaps i find his posts in the history.Sunny greetings,Martin -------- Ursprüngliche Nachricht --------Von: Barış @.> Datum: 20.07.24 16:48 (GMT+01:00) An: martinzw/THRII-direct-USB-pedalboard @.> Cc: Subscribed @.***> Betreff: [martinzw/THRII-direct-USB-pedalboard] Bluetooth LE Feasibility (Issue #5) Hi Martin, Your detailed protocol document was extremely helpful to understand the SysEx. Thank you for that! I wanted to ask if you are aware of the feasibility of using BLE to send the SysEx data. I have an ESP32 devkit and using the ESP32-BLE-MIDI package to send SysEx to the amp. The idea is to create a preset selector pedal similar to a one available on the market; but cheaper. (see: AIRSTEP YT) I'm sending over the following SysEx which I understand that they're acting like a handshake with the THR. byte IDENTITY_REQUEST[] = { 0xF0, 0x7E, 0x7F, 0x06, 0x01, 0xF7 };

byte VERSION_REQUEST[] = { 0xF0, // Request THR Amp version 0x00, 0x01, 0x0C, // Line6 0x24, // THRII 0x02, 0x4D, // THR30IIWireless 0x00, // A or B 0x00, 0x00, 0x00, 0x07, // 0x00, // 1st bitbucket 0x01, 0x00, 0x00, 0x00, // OP 0x00, 0x00, 0x00, // FB 0x00, // 2nd bitbucket 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Type? 0xF7};

byte HEADER[] = { 0xF0, 0x00, 0x01, 0x0C, // Line6 0x24, // THRII 0x02, 0x4D, // THR30IIWireless 0x00, // A or B 0x01, 0x00, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7};

byte MAGIC_KEY[] = { 0xF0, 0x00, 0x01, 0x0C, // Line6 0x24, // THRII 0x02, 0x4D, // THR30IIWireless 0x00, // A or B 0x02, 0x00, 0x00, 0x03, 0x28, 0x72, 0x4D, 0x54, // Magic key for 1.4.4.0.a 0x00, 0x00, 0x00, 0xF7};

Unfortunately, even after sending these SysEx and connecting with the THR amp, I don't receive any SysEx back from the amp. My code basically utilizes the examples from the ESP32-BLE-MIDI package to create a BLE MIDI Client and send SysEx. I appreciate your time on this! Best, Barış

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

bariskalem commented 1 month ago

Hi Martin,

Thanks for the reply! I'll try it without the USB connection soon, and let you know. Do you mean that the BLE connection to the amp was made using your library?

Enjoy your vacation!

martinzw commented 1 month ago

Hi Barış,

there has been someone who built a pedal board with ESP32. But he did not send direct MIDI-Commands to THR30II but instead connected to the Android App via BLE:

https://github.com/radioactivetoy/BLEPedalboard

Looking at your Array definitions i think the first (IDENTITY_REQUEST) should be enough to provoke a reaction/answer from THR30II.

But i can not see, how you send this array as a SysEx message to the THR30II without your complete code.

As far as i have seen, the ESP32-BLE-MIDI package does not offer a "SendSysEx" - Method at all.

Can you send me your .ino?

bariskalem commented 3 weeks ago

Hi Martin,

I've also saw that project that connects to the Android App. Very interesting but I wanted to cut the middleman (the app) with my project.

In my initial issue post I've forgot to mention that I use the lathoub/Arduino-BLE-MIDI library to send SysEx data. This is the example that I've followed: SysEx_Send.ino

The following is my .ino

I'm using a M5StickC Plus2 devkit which provides commands to write text on screen and handle button presses.

// #include <Arduino.h>
#include <BLEMIDI_Transport.h>
// #include <hardware/BLEMIDI_Client_ESP32.h>
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
#include "M5StickCPlus2.h"

#define MIDI_DEVICE_NAME "LE_THRII"

BLEMIDI_CREATE_INSTANCE(MIDI_DEVICE_NAME, MIDI)

unsigned long t0 = millis();
bool isConnected = false;

// ----------- SYSEX -----------
const byte IDENTITY_REQUEST[]  = { 0xF0, 0x7E, 0x7F, 0x06, 0x01, 0xF7 };

byte VERSION_REQUEST[]  = { 0xF0, // Request THR Amp version
                            0x00, 0x01, 0x0C, // Line6 
                            0x24, // THRII
                            0x02, 0x4D, // THR30IIWireless
                            0x00, // A or B
                            0x00, 0x00, 0x00, 0x07,  //
                            0x00, // 1st bitbucket
                            0x01, 0x00, 0x00, 0x00, // OP
                            0x00, 0x00, 0x00, // FB
                            0x00, // 2nd bitbucket
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Type?
                            0xF7}; 

byte HEADER[]  = { 0xF0, 
                   0x00, 0x01, 0x0C, // Line6 
                   0x24, // THRII
                   0x02, 0x4D, // THR30IIWireless
                   0x00, // A or B
                   0x01, 0x00, 0x00, 
                   0x07, 
                   0x00, 0x04, 0x00, 0x00, 
                   0x00, 0x04, 0x00, 
                   0x00,
                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                   0xF7}; 

byte MAGIC_KEY[]  = { 0xF0, 
                      0x00, 0x01, 0x0C, // Line6 
                      0x24, // THRII
                      0x02, 0x4D, // THR30IIWireless
                      0x00, // A or B
                      0x02, 0x00, 0x00, 
                      0x03, 
                      0x28, 0x72, 0x4D, 0x54, // Magic key for 1.4.4.0.a
                      0x00, 0x00, 0x00,
                      0xF7}; 

// After this, THR should send the following acknowledgment message:
// F0 00 01 0C 24 02 4D 00 01 00 00 0B 00 01 00 00 00 04 00 00 00 00 00 00 00 00 00 00 F7

// PRESET CHANGE MESSAGE
byte PRESET_2[]  = { 0xF0, // Request THR Amp version
                     0x00, 0x01, 0x0C, // Line6 
                     0x24, // THRII
                     0x02, 0x4D, // THR30IIWireless
                     0x01, // A or B
                     0x0E, 0x00, 0x00, 0x0B, 
                     0x00, 
                     0x0E, 0x00, 0x00, 0x00,
                     0x04, 0x00, 0x00, 
                     0x00, 
                     0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
                     0xF7}; //                              ^  Preset 2

bool sent_handshake = false;

void setup() {
  Serial.begin(115200);
  while (!Serial);

  // StickC setup
  auto cfg = M5.config();
  StickCP2.begin(cfg);
  StickCP2.Display.setRotation(1);
  StickCP2.Display.setTextColor(ORANGE);
  StickCP2.Display.setTextDatum(middle_center);
  StickCP2.Display.setTextFont(&fonts::Orbitron_Light_24);
  StickCP2.Display.setTextSize(1);
  StickCP2.Display.drawString("Initialized", StickCP2.Display.width() / 2,
                              StickCP2.Display.height() / 2);

  // MIDI Setup
  BLEMIDI.setHandleConnected(OnConnected);
  BLEMIDI.setHandleDisconnected(OnDisconnected);
  MIDI.setHandleSystemExclusive(OnMidiSysEx);

  MIDI.begin();
}

void loop() {
  StickCP2.update();
  MIDI.read();
  if (isConnected && (millis() - t0) > 1000 && !sent_handshake) {
    Serial.println("SENDING HANDSHAKE");
    t0 = millis();
    MIDI.sendSysEx(sizeof(IDENTITY_REQUEST), IDENTITY_REQUEST, true);
    MIDI.sendSysEx(sizeof(VERSION_REQUEST), VERSION_REQUEST, true);
    MIDI.sendSysEx(sizeof(HEADER), HEADER, true);
    MIDI.sendSysEx(sizeof(MAGIC_KEY), MAGIC_KEY, true);
    sent_handshake = true;
    Serial.println("SENT HANDSHAKE");
  }  

  if (StickCP2.BtnA.wasPressed()) {
        if (isConnected && (millis() - t0) > 1000) {
            StickCP2.Speaker.tone(8000, 20);
            StickCP2.Display.clear();
            t0 = millis();
            MIDI.sendSysEx(sizeof(PRESET_2), PRESET_2, true);
            StickCP2.Display.drawString("Sent SysEx",
                                        StickCP2.Display.width() / 2,
                                        StickCP2.Display.height() / 2);
        }
        else {
          StickCP2.Speaker.tone(8000, 20);
          StickCP2.Display.clear();
          StickCP2.Display.drawString("Need connection",
                                        StickCP2.Display.width() / 2,
                                        StickCP2.Display.height() / 2);
        }
    }

}

// -----------------------------------------------------------------------------
// Device connected
// -----------------------------------------------------------------------------
void OnConnected() {
  isConnected = true;
  StickCP2.Display.clear();
  StickCP2.Display.drawString("Connected",
                                    StickCP2.Display.width() / 2,
                                    StickCP2.Display.height() / 2);
}

// -----------------------------------------------------------------------------
// Device disconnected
// -----------------------------------------------------------------------------
void OnDisconnected() {
  isConnected = false;
  sent_handshake = false;
  StickCP2.Display.clear();
  StickCP2.Display.drawString("Disconnected",
                                    StickCP2.Display.width() / 2,
                                    StickCP2.Display.height() / 2);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void OnMidiSysEx(byte* data, unsigned length) {
  Serial.print(F("SYSEX: ("));
  Serial.print(length);
  Serial.print(F(" bytes) "));
  for (uint16_t i = 0; i < length; i++)
  {
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

The behaviour of the ESP32 board is that it connects to the Amp (the library prints out the message that it connected) and then disconnects randomly after some seconds with no response in between (no sign of SysEx being actually sent or received). It then does a cycle of random connects and disconnects indefinitely.

However I should mention that I've successfully sent SysEx data with a similar example by connecting the ESP32 board to my MacBook.

martinzw commented 2 weeks ago

OK, that looks different....

I experienced similar problems, when i tried out on my own following your initial posting. (see Platformio-Code BLE_MIDI_test, which i upload here in a "experiments" folder). But I think, the missing answer is a problem of the BLE-libraries. To proof this, i modified an Example for BLE-MIDI-Programming in Windows for Visual Studio and got the THR30II to answer me, though i did the same like in the ESP32-BLE test code. I put that in the "Experiments" folder as well.

At the moment i experience additional problems with the latest THR30II firmware (1.45.0c). There the answer to the request for the symbol table does not work the same way than before. So my programs do not work any more with the latest THR30II firmware.

Martin

BuhJuhWuh commented 2 weeks ago

At the moment i experience additional problems with the latest THR30II firmware (1.45.0c). There the answer to the request for the symbol table does not work the same way than before. So my programs do not work any more with the latest THR30II firmware.

Oh, wow, that's frustrating. Thanks for the warning. I'll stay away from the updates!