Go Down

Topic: Midi Hairless trouble on MAC (Read 145 times) previous topic - next topic

blabberbytes

So I'm trying to get my heart rate sensor's data to control midi through Hairless MIDI. I'm on the newest MAC and created a IAC Driver under the audio midi setup utility. I'm on BAUD 9600 on hairless and in the Arduino code. I'm getting the "error: got unexpected data byte midi hairless" So the computer is getting the signal but something seems to be wrong. Its not able to connect to any midi software

Any ideas to what the trouble is?

Here's the code:

#include <MIDI.h>

#define Heart 2                            //Attach the Grove Ear-clip sensor to digital pin 2.
#define LED 4                              //Attach an LED to digital pin 4

boolean beat = false;                      /* This "beat" variable is used to control the timing of the Serial communication
                                           so that data is only sent when there is a "change" in digital readings. */

//==SETUP==========================================================================================
void setup() {
  //MIDI.begin(0);
  Serial.begin(9600);                     //Initialise serial communication
  pinMode(Heart, INPUT);                  //Set digital pin 2 (heart rate sensor pin) as an INPUT
  pinMode(LED, OUTPUT);                   //Set digital pin 4 (LED) to an OUTPUT
}


//==LOOP============================================================================================
void loop() {
  if (digitalRead(Heart) > 0) {           //The heart rate sensor will trigger HIGH when there is a heart beat
    if (!beat) {                          //Only send data when it first discovers a heart beat - otherwise it will send a high value multiple times
      beat = true;                        //By changing the beat variable to true, it stops further transmissions of the high signal
      digitalWrite(LED, HIGH);            //Turn the LED on
      Serial.println(1023);               //Send the high value to the computer via Serial communication.
    }
  } else {                                //If the reading is LOW,
    if (beat) {                           //and if this has just changed from HIGH to LOW (first low reading)
      beat = false;                       //change the beat variable to false (to stop multiple transmissions)
      digitalWrite(LED, LOW);             //Turn the LED off.
      Serial.println(0);                  //then send a low value to the computer via Serial communication.
    }
  }
}

PieterP

Why are doing a Serial.print to Hairless? Hairless expects MIDI packets, not ASCII text.
Why don't you use the MIDI library functions?
Please use [code][/code] tags when posting code or error messages.

Pieter

Grumpy_Mike

Code: [Select]
Serial.println(1023);               //Send the high value to the computer via Serial
This sends the hex values 0x31 0x30 0x32 0x33
Which is four bytes which in midi terms is a nonsense and the error message is correct their is an extra byte.

Also 9600 baud is way too slow, set them both the the fastest common speed.

blabberbytes

So what do I need to modify in the code to  send a midi note to my midi application? Sorry I'm a beginner.

Grumpy_Mike

You need to send three bytes to send a MIDI note.
1) The MIDI command to turn a note on in the top four bits of the byte and the channel in the lower four bits
2) The MIDI note number ( 0 to 127 )
3) The velocity or how hard the note is struck ( 0 to 127 )

Once a note is on you need to turn it of when it is time, this requires a different number in step 1 and the value in step 3 gives the after touch information.
Study this code, it will send random MIDI notes.
Code: [Select]

#define midiChannel (byte)0

// Start of code
void setup() {
 //  Setup serial
   Serial.begin(250000);    // set hiarless for this speed

}

//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127); // turn note on
    delay(200);
    noteSend(0x80, val, 127); // turn note off
   delay(800);
    } // end loop function
   
//********************* Functions ***********************************


//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}


Go Up