Control-Surface icon indicating copy to clipboard operation
Control-Surface copied to clipboard

Bluetooth issues

Open JeffyOLOLO opened this issue 1 year ago • 3 comments

Hi, thanks for such powerful library/framework!

I'm building a MIDI keyboard using ESP32-S (the ESP32-Cam board) and want to use Bluetooth as an interface. But I encountered a few issues.

Testing environment:

  • Android 11 (MIUI Global 12.5.2)
  • Bluetooth MIDI Connect for pairing and checking connection (https://play.google.com/store/apps/details?id=bluetooth.midi.connect)
  • FM Synthesizer (https://play.google.com/store/apps/details?id=com.synprez.fm)
  • code is built using toolchain integrated into PlatformIO (toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5 in a build log)

Issues:

  1. Unstable connection Phone connects to the board from the second time. I do it using Bluetooth MIDI Connect. For the first time I connect and immediately the connection disappears, on the second time it connects successfully. But sometimes I need to repeat this algorithm several times to make it work.

  2. [ble2902.c:32] ble2902_get_value(): [MIDIBLE] Unexpected descriptor value length (0) error When connection is successful, there is this error in the log. But everything works, I can play notes. Sometimes it appears in the log during playing, but I couldn't find a pattern.

  3. Pipes don't work The board starts, but if I try to do any action it crashes, for example: If I try to press a button, it crashes and reboots. If I try to pair to the board, it also crashes with another error and prints a dump, I can attach it if you are interested. I didn't use any other interface except the usb debug one, so probably this is only a ble problem. The log for the button case:

Program Change   Channel: 1     Data 1: 0x12
Program Change   Channel: 2     Data 1: 0x1b
[  1150][E][ble2902.c:32] ble2902_get_value(): [MIDIBLE] Unexpected descriptor value length (0)
--------- I'm pressing a button -----------
Note On          Channel: 1     Data 1: 0x44    Data 2: 0x7f
Note On          Channel: 1     Data 1: 0x48    Data 2: 0x7f
Note On          Channel: 1
assert failed: xRingbufferReceiveFromISR ringbuf.c:1146 (pxRingbuffer)

Backtrace: 0x40083c89:0x3ffbf2bc |<-CORRUPTED

ELF file SHA256: edf8265d4500a574

Rebooting...

My code: This is the code that I used to reproduce the third issue, but if you comment out usbDbgMidi and pipes code, it will be the code that I used for issues 1 and 2. I can attach PCF8574.h code as well if you think it's important.

#include <Arduino.h>
#include <Wire.h>

#include <Control_Surface.h>

// Inherits StaticSizeExtendedIOElement<8>
// It's similar to MCP23017 code, but it uses read functions instead of write ones.
#include "PCF8574.h"

constexpr ArduinoPin_t I2C_SCL_PIN = 14;
constexpr ArduinoPin_t I2C_SDA_PIN = 15;

BluetoothMIDI_Interface bleMidi;
USBDebugMIDI_Interface usbDbgMidi = 115200;
// Create a MIDI pipe factory to connect the MIDI interfaces to Control Surface
BidirectionalMIDI_PipeFactory<2> pipes;

constexpr uint8_t OCTAVE = 4;
constexpr auto CHORDS_CHANNEL  = CHANNEL_1;

PCF8574 pcf;

NoteChordButton chords[3] = {
  { pcf.pin(0), {MIDI_Notes::Db(OCTAVE), CHORDS_CHANNEL}, Chords::Major },
  { pcf.pin(1), {MIDI_Notes::Ab(OCTAVE), CHORDS_CHANNEL}, Chords::Major },
  { 16        , {MIDI_Notes::Bb(OCTAVE), CHORDS_CHANNEL}, Chords::Major },
};

void setup() {
  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);

  Control_Surface | pipes | usbDbgMidi;
  Control_Surface | pipes | bleMidi;
  // Set up instruments
  Control_Surface.begin();
  Control_Surface.sendProgramChange({MIDI_PC::Rock_Organ, CHORDS_CHANNEL});
}

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

JeffyOLOLO avatar Jan 21 '23 16:01 JeffyOLOLO