MIDI input problems ESP32

Hi.

I bought a ESP32 dev module for making a midi (DIN-5) to midi bluetooth device, the controller is a AKAI MPD32. The problems I have is that the incoming MIDI messages does not make any sense, I have tried various codes including my own but the incoming messages is always wierd. The code attatched is collected from a similar project using teensy. MIDI Library, For Communication With Musical Instruments Im not shure about the pullup on the uart pin, ive used 11k may that be too high for a 3.3v signal?

The code from the teesy MIDI test:

#include <MIDI.h>

MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI);

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
  Serial.begin(57600);
  Serial.println("MIDI Input Test");
}

unsigned long t=0;

void loop() {
  int type, note, velocity, channel, d1, d2;
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    byte type = MIDI.getType();
    switch (type) {
      case midi::NoteOn:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if (velocity > 0) {
          Serial.println(String("Note On:  ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        } else {
          Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
        }
        break;
      case midi::NoteOff:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
        break;
      default:
        d1 = MIDI.getData1();
        d2 = MIDI.getData2();
        Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
    }
    t = millis();
  }
  if (millis() - t > 10000) {
    t += 10000;
    Serial.println("(inactivity)");
  }
}

This code outputs such values as this when I press a note, occasionally it registers a note on or off, but it also occasionally does that when I turn any knobs (midi-cc)

Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=255, data = 0 0
Message, type=208, data = 0 0
Message, type=255, data = 0 0

Ive tried things such as two different optocouplers where at least one of them was too slow, Ive also tried attaching the midi+ directly into the esp32 UART2 pin (GPIO16) and inverting in HardwareSerial.h with no luck.

Reading the UART2 directly off gpio16 and sending to computer I do get results that does not indicate any noise etc.

void setup() {
  Serial.begin(115200);
  Serial2.begin(31250);
}

void loop() {

  if (Serial2.available()) {     // If anything comes in Serial1 (pins 0 & 1)
    Serial.write(Serial2.read());   // read it and send it out Serial (USB)

  }
}

Results hitting keys with notes C, C# then D

00 6E FF 00 73 0B
 00 6E FF 00 53 0B
 00 6A FF 00 33 0B

Hitting the C key 100 times it will always give the same “00 6E FF 00 73 0B” To me it seems like the ESP32 does not use the standard MIDI baud rate or something, mixing up the bits.

Any suggestions?
thank you…

You need to detail all your hardware and explain what is connected to what and what is sending the data...