Arduino MEGA - Serial Out Midi

Hi,

ich will aus einem Arduino Mega einen Midicontroller bauen.

Ich habe bereits einen funktionierenden MidiController auf Basis eines Arduino Micro.

Der funktioniert so:
Tasten und Fadebewegungen werden gelesen und es wird eine MIDI Nachricht über Serial1 Out geschrieben.

TX1 (Pin5 am Midi Stecker) & 5V (Pin4 am Midi Stecker)hängen über einen 220Ohm Widerstand an der MIDI Buchse, GND am Pin2 der Buchse.

Wenn ich das auf den Mega übertragen will, werden an TX1 keine Midi Signale erzeugt, mein Midi-USB Wandler zeigt ebenfalls keine Eingangsignale.

#define SLIDER1_PIN A0
#define SLIDER2_PIN A1
#define SLIDER3_PIN A2

#define ENC1_SW_PIN 45
#define ENC2_SW_PIN 47
#define ENC3_SW_PIN 44
#define ENC4_SW_PIN 42


//NOTE SWITCHES
#define NOTE1_PIN 46 
#define NOTE2_PIN 48
#define NOTE3_PIN 50
#define NOTE4_PIN 52
#define NOTE5_PIN 49
#define NOTE6_PIN 51
#define NOTE7_PIN 53



byte valueSlider1CC;
byte valueSlider2CC;
byte valueSlider3CC;

byte epromvalueEncoderCC;
byte epromvalueEncoder1CC;

 
// defining constants for MIDI commands (First transmitted byte)
const byte playNote = 0x90;   // Note on
const byte pitchBend = 0x70;  // Pitch bend
const byte cc = 0xB0;         // Continous Controller
// ...for MIDI parameters (Second and third transmitted byte)
const byte midiMax = 0x7F;    // The highest possible parameter value (127 or 0b1111111)
const byte midiMin = 0;       // A zero, just giving it a fancy name here

const byte slidertolerance = 3;       // Noise Reduction for sliders to prevent joystick noise in center position


void sendCC(byte channel, byte controller, byte value) {
  Serial1.write(cc + channel);
  Serial1.write(controller);
  Serial1.write(value);
  
  Serial.print("CC");
  Serial.print("\t");
  Serial.print(controller);
  Serial.print("\t");
  Serial.println(value);
}

class Slider{
  /* This object allows to map slider input to a continous controller
   *  parameters of ctor:
   *  pin: The input pin to which the slider is connected
   *  CC_target: The CC that is being affected
   *  invert: set true for reversing the direction of a slider. Default is 'false'
   */
  private:
    int _pin, oldValue, newValue;
    byte _channel;
    byte _CC_target;
    bool _invert;
  public:
    Slider(int pin, byte CC_target, bool invert = false){
      _pin = pin;
      _CC_target = CC_target;
      _invert = invert;
      pinMode(pin, INPUT);
    }
    void update(byte channel){
      newValue = analogRead(_pin);
      if (newValue != oldValue){
        signed char sliderdelta = abs(oldValue - newValue);
        if(sliderdelta > slidertolerance){
        if(_invert){
          sendCC(channel, _CC_target, map(newValue, 0, 1023, 127, 0));
        }else{
          sendCC(channel, _CC_target, map(newValue, 0, 1023, 0, 127));
        }
        oldValue = newValue;
      }
    }
    }
};


byte readNote(byte startOctave) {
  byte buttons = 0;
  if (digitalRead(NOTE1_PIN) == HIGH) {
    buttons = 1;
  }
  if (digitalRead(NOTE2_PIN) == HIGH) {
    buttons = 2;
  }
  if (digitalRead(NOTE3_PIN) == HIGH) {
    buttons = 3;
  }
  if (digitalRead(NOTE4_PIN) == HIGH) {
    buttons = 4;
  }
  if (digitalRead(NOTE5_PIN) == HIGH) {
    buttons = 5;
  }
  if (digitalRead(NOTE6_PIN) == HIGH) {
    buttons = 6;
  }
  if (digitalRead(NOTE7_PIN) == HIGH) {
    buttons = 7;
  }
  return buttons;
}

void sendNote(byte channel, byte note, byte velocity) {
  Serial1.write(playNote + channel);
  Serial1.write(note);
  Serial1.write(velocity);
  
  Serial.print("note");
  Serial.print("\t");
  Serial.print(note);
  Serial.print("\t");
  Serial.println(velocity);
}

void sendPitchBend(byte channel, int sensorOutput) {
  int amount = map(sensorOutput, 0, 1023, 0, 16384);
  byte lsb = amount & 0b1111111;
  byte msb = amount >> 7;
  Serial1.write(pitchBend + channel);
  Serial1.write(lsb);
  Serial1.write(msb);
}

byte channel,
     newNote,
     oldNote;
     




void setup() {
  Serial.begin(9600);
  Serial1.begin(31250);
  analogReference(DEFAULT);
  pinMode(NOTE1_PIN, INPUT_PULLUP);
  pinMode(NOTE2_PIN, INPUT_PULLUP);
  pinMode(NOTE3_PIN, INPUT_PULLUP);
  pinMode(NOTE4_PIN, INPUT_PULLUP);
  pinMode(NOTE5_PIN, INPUT_PULLUP);
  pinMode(NOTE6_PIN, INPUT_PULLUP);
  pinMode(NOTE7_PIN, INPUT_PULLUP);
  pinMode(ENC1_SW_PIN,INPUT);
  pinMode(ENC2_SW_PIN,INPUT);
  pinMode(ENC3_SW_PIN,INPUT); 
  pinMode(ENC4_SW_PIN,INPUT);
  pinMode(SLIDER1_PIN,INPUT);
  pinMode(SLIDER2_PIN,INPUT);
  pinMode(SLIDER3_PIN,INPUT);
  


  newNote = 0;
  oldNote = 1;
  channel = 0;

  
  //Serial.println("CC INITIALISATION");
  //Serial.print("JoyX CC");
  //Serial.print("\t");
  //Serial.println("-----VALUE------------");
  delay(5000);

//MIDI CC VALUES
  valueSlider1CC = 11;
  valueSlider2CC = 12;
  valueSlider3CC = 13;
}

void loop() {
  
  Slider Slider1(SLIDER1_PIN, valueSlider1CC);
  Slider Slider2(SLIDER2_PIN, valueSlider2CC);
  Slider Slider3(SLIDER3_PIN, valueSlider3CC);
  Slider1.update(channel);
  Slider2.update(channel);
  Slider3.update(channel);

}

Kernproblem:
Auf Arduino Micro geht alles. Auf dem int. Serial Monitor kann ich die CCs und die Werte der Slider sehen. Auf Serial1 gehen korrekte MIDI Pakete an den Port (Anschluss siehe Attachment)

Auf dem Arduino MEGA funktioniert das nicht. Interner Serial Monitor zeigt zwar das gleiche, über den TX1 kommen keine Signale am MIDI-Port an.

midi.PNG