BLE MIDI controller with Jay-D

Hello to all.

I’m working on a mod for the Jay-D so we can use it as a MIDI controller.
I want to try the Bluetooth functionality and the first test code is working.
I used the ESP32-BLE-MIDI library https://www.arduino.cc/reference/en/libraries/esp32-ble-midi/.

My problem now is to have a working code to listen faders/encoders/buttons values change.
I tried to use classic Arduino coding like “Serial.print(analogRead(37))” since from the schematic one fader is connected directly to the analog pin 37 on the ESP32 but I don’t get anything on Serial Monitor.
This is the only working code that shows faders’ values on Serial Monitor.
But it doesn’t send those values thru MIDI protocol.

#include <Arduino.h>
#include <BLEMidi.h>
#include <CircuitOS.h>
#include <JayD.h>
#include <Loop/LoopManager.h>
#include <Input/InputJayD.h>

int valuePotLrec;
int valuePotRrec;
int valuePotMrec;
byte midiNote = 0;

void potentiometer_POT_L_moved(uint8_t value){
  valuePotLrec = value;
  midiNote = map(valuePotLrec, 0, 255, 0, 127);
  BLEMidiServer.noteOn(0, valuePotLrec, 127);  //Start sending Left fader value thru MIDI as a note
  delay(1000);
  BLEMidiServer.noteOff(0, valuePotLrec, 127);  //Stop sending Left fader value thru MIDI as a note
  delay(1000);
  Serial.print("POT_LEFT: ");
  Serial.println(valuePotLrec);
}

void potentiometer_POT_R_moved(uint8_t value){
  valuePotRrec = value; 
  Serial.print("POT_RIGHT: ");
  Serial.println(valuePotRrec);
}

void potentiometer_POT_MID_moved(uint8_t value){
  valuePotMrec = value;
  Serial.print("POT_MID: ");
  Serial.println(valuePotMrec);
}

void setup() {
  Serial.begin(115200);
  Serial.println("Initializing bluetooth");
  BLEMidiServer.begin("BLE MIDI JAYD");
  Serial.println("Waiting for connections...");
  JayD.begin();
  //pinMode(PIN_BL, OUTPUT); digitalWrite(PIN_BL, LOW);
  InputJayD::getInstance()->setPotMovedCallback(POT_L, potentiometer_POT_L_moved);
  InputJayD::getInstance()->setPotMovedCallback(POT_R, potentiometer_POT_R_moved);
  InputJayD::getInstance()->setPotMovedCallback(POT_MID, potentiometer_POT_MID_moved);
}

void loop() {
  LoopManager::loop();
  /*THIS IS THE MIDI THRU BLE LIBRARY'S EXAMPLE CODE
   * if(BLEMidiServer.isConnected()) {      
       midiNote = map(valuePotLrec, 0, 255, 0, 127);
      BLEMidiServer.noteOn(0, midiNote, 127);       // If we've got a connection, we send an A4 during one second, at full velocity (127)
      delay(1000);
      BLEMidiServer.noteOff(0, midiNote, 127);        // Then we make a delay of one second before returning to the beginning of the loop
      delay(1000);
}*/
}
1 Like

Hi @Feetrikki_Marcon,

thanks for your post! :slight_smile:

Our lead programmer will check your code and get back with the comments! :slight_smile:

Sincerely,
Monika from CM

1 Like

Hey there!

It seems you might be looking at the wrong schematic. All encoders, buttons, and sliders on the Jay-D are connected to the external Nuvoton co-processor, which sends input data to the main ESP32 processor via an I2C bus. This is why you can’t read the slider values directly with analogRead. You can find Jay-D’s schematics here.

Looking at the code I see an error in calling JayD.begin after BLEMidiServer.begin . JayD.begin turns off all peripherals to save power, including Bluetooth and WiFi. Placing that function call just after Serial.begin will make the MIDI BLE server work.

Hope that helps :slight_smile:
Filip

1 Like