Go Down

Topic: Missing data bytes while receiving MIDI [solved] (Read 671 times) previous topic - next topic

data_drink

Sep 14, 2019, 11:28 pm Last Edit: Sep 15, 2019, 01:31 am by data_drink Reason: 1st edit: added the attachment, was previously too large; 2nd edit: topic solved
Hello!

So, I just stared a project where I want to control a servo-motor with MIDI. I set up a MIDI-receiver circuit (see attachment) and connected it to my Arduino (the data-"output" to RX, 5V to 5V, ground to ground). Then I tried triggering the servo with different MIDI notes but that didn't work somehow. So I downloaded MegunoLink(can be used as a serial monitor @ 31250 Baud) to look what's going on and weirdly I am missing all the data bytes. (see below)

This is my code:

Code: [Select]
#include <Servo.h>

Servo myservo;

byte commandByte;
byte noteByte;
byte velocityByte;

byte noteOn = 144;

void setup() {
  Serial.begin(38400);
  myservo.attach(9);
}

void checkMIDI(){
  do{
    if (Serial.available()){
      commandByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();
    }
    if(commandByte == noteOn){
      Serial.print(commandByte, HEX);
      Serial.print(" ");
      Serial.print(noteByte, HEX);
      Serial.print(" ");
      Serial.println(velocityByte, HEX);
    }
  }
  while (Serial.available() > 2);
}

void loop() {
  checkMIDI();
}


and this is my output when pressing any note (in this case 5 notes successively):

Code: [Select]
90 FF FF
90 FF FF
90 FF FF
90 FF FF
90 FF FF


For outputting MIDI I tried my audio interface with Ableton, and directly from my MIDI keyboard so the problem (probably) has to be the circuit or the code.

Why do I receive only the command byte and nothing else? {

Grumpy_Mike

Quote
Why do I receive only the command byte and nothing else?
Because you look at the serial buffer and if it contains one byte you read three from it and two of them havent arrived yet. When you read an empty buffer you get a value of 0xFF.

So use :-
 
Code: [Select]
if (Serial.available() >= 3 ){

data_drink


Go Up