Problem using Arduino Leonardo, midiUSB library and Ableton

Hello everyone ! :slight_smile:

I’ve a project with Arduino and Ableton since few weeks, I want to light on led strip with the fastLed library command by Midi message from Ableton.

I’m using the MidiUSB library but I doesn’t receive anything on the serial console. When I play or stop in Ableton I receive something but I can’t receive any note.

After many hours of reading and testing codes, I haven’t found any solution :’(

This is my code which is the basic code from MidiUSB.

#include <MIDIUSB.h>


const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}

int pitch_octave(byte pitch) { 
  return (pitch / 12) - 1;
}

void noteOn(byte channel, byte pitch, byte velocity) {

  Serial.print("Note On: ");
  Serial.print(pitch_name(pitch)); 
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.println(velocity);
}

void noteOff(byte channel, byte pitch, byte velocity) {

  Serial.print("Note Off: ");
  Serial.print(pitch_name(pitch));
  Serial.print(pitch_octave(pitch));
  Serial.print(", channel=");
  Serial.print(channel);
  Serial.print(", velocity=");
  Serial.println(velocity);
}

void controlChange(byte channel, byte control, byte value) {
  Serial.print("Control change: control=");
  Serial.print(control);
  Serial.print(", value=");
  Serial.print(value);
  Serial.print(", channel=");
  Serial.println(channel);
}

void setup() {
  Serial.begin(192000);
} 

void loop() {
  midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events

    case 0x9:
      noteOn(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch  
        rx.byte3         //velocity
      );
      break;

    case 0x8:
      noteOff(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //pitch
        rx.byte3         //velocity
      );
      break;

    case 0xB:
      controlChange(
        rx.byte1 & 0xF,  //channel
        rx.byte2,        //control
        rx.byte3         //value
      );
      break;

    default:
      Serial.print("Unhandled MIDI message: ");
      Serial.print(rx.header, HEX);
      Serial.print("-");
      Serial.print(rx.byte1, HEX);
      Serial.print("-");
      Serial.print(rx.byte2, HEX);
      Serial.print("-");
      Serial.println(rx.byte3, HEX);
  }
}

Any help would really be appreciated! Thanks a lot !

Edit : I've found and solved the problem, it's come from my Ableton and not Arduino, I'm sorry for bothered you.

Thanks for getting back with this information. Have a Karma point.

I did take a look at the code and couldn’t see much wrong with it other than you didn’t have a loop in the setup function that waited for the USB connection to become valid. That might delay it responding but only for the first second or so.