Go Down

Topic: Midi Hairless trouble on MAC (Read 831 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);
}


blabberbytes

#5
Jul 25, 2017, 02:06 am Last Edit: Jul 26, 2017, 04:04 am by blabberbytes
Okay so I successfully got the programs reading the midi. On ableton live it seems to work fine turning things on and off. The problem I am having is with Resolume Arena which is a video application. I set the midi to launch a clip but instead the video just stops. When i set the midi to Opacity or color, I can see the slider bar change with my heart beat but there's no actual change in the video. I'm wondering if you had any idea how to troubleshoot this. Thanks for all your help btw!

Code: [Select]
/* =================================================================================================
      Project: Arduino Heart rate monitor
       Author: Scott C
      Created: 21st April 2015
  Arduino IDE: 1.6.2
      Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html
  Description: This is a simple sketch that uses a Grove Ear-clip Heart Rate sensor attached to an Arduino UNO,
               which sends heart rate data to the computer via Serial communication. You can see the raw data
               using the Serial monitor on the Arduino IDE, however, this sketch was specifically
               designed to interface with the matching Processing sketch for a much nicer graphical display.
               NO LIBRARIES REQUIRED.
  =================================================================================================== */
#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. */

//MIDI_CREATE_DEFAULT_INSTANCE();

 int velocity = 50;//velocity of MIDI notes, must be between 0 and 127
 //higher velocity usually makes MIDI instruments louder
 
 int noteON = 144;//144 = 10010000 in binary, note on command
 //int noteOFF = 128;//128 = 10000000 in binary, note off command                                       

//==SETUP==========================================================================================
void setup() {
 //MIDI.begin(MIDI_CHANNEL_OMNI);
  Serial.begin(115200);                     //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);
      int note=60;
      MIDImessage(noteON, note, velocity);//turn note on
    delay(300);//hold note for 300ms
   
     
      //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);
      int note=60;
      MIDImessage(noteOFF, note, 0);//turn note off
    delay(300);//wait 200ms until triggering next note

      //Serial.println(0);                  //then send a low value to the computer via Serial communication.
    }
  }
}
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
  Serial.write(command);//send note on or note off command
  Serial.write(MIDInote);//send pitch data
  Serial.write(MIDIvelocity);//send velocity data
}

Grumpy_Mike

Well I know nothing about Resolume Arena but that code is sending note ON note off messages. How are you expecting it to:-
Quote
I set the midi to launch a clip but instead the video just stops.
I think you need to know what MIDI messages Resolume Arena is expecting. It would be unusual in my mind to use note on/off messages to launch a video, I would have expected a couple of CC messages would be used.

 
Quote
I can see the slider bar change with my heart beat but there's no actual change in the video
If the video is not being played that might be what would be expected.

blabberbytes

#7
Jul 26, 2017, 05:15 am Last Edit: Jul 26, 2017, 05:21 am by blabberbytes
Quote
Well I know nothing about Resolume Arena but that code is sending note ON note off messages. How are you expecting it to:-
So I removed NoteOFF and video does not play. I am using Midi Monitor and noticed when I map it to the clip, it starts to constantly send a signal. When I map it the R button (channel that turns red on/off) the button switching back and for that the rate of my heart but in Midi monitor it seems to be turning on/off at the same time. I attached to images of the two scenarios

Quote
I think you need to know what MIDI messages Resolume Arena is expecting. It would be unusual in my mind to use note on/off messages to launch a video, I would have expected a couple of CC messages would be used.
How would I go about doing CC instead of midi NoteON/OFF?? I've been looking and trying things to no avail. Thanks again mate.

Grumpy_Mike

Quote
So I removed NoteOFF and video does not play.
I thought the problem was it did not play anyway?

Quote
When I map it the R button (channel that turns red on/off) the button switching back and for that the rate of my heart but in Midi monitor it seems to be turning on/off at the same time.
That seems to say to me that when you just change the mapping in the VJ software the Arduino starts sending MIDI note OFF messages? That is impossible because their is no connection in that direction between the two.

Quote
How would I go about doing CC instead of midi NoteON/OFF??
A CC message is just like a note on message, it consists of three bytes :-

command, controller number, controller value

The command byte is is 0xB0
So something like this:-
Code: [Select]
void controlSend(char channel, char data1, char data2) {
  cmd = 0xB0 | channel;  // merge channel number with command
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}

blabberbytes

#9
Jul 26, 2017, 11:27 pm Last Edit: Jul 27, 2017, 12:20 am by blabberbytes
Hey thanks  Grumpy_Mike for all your help. In the MIDI settings I had output selected in IAC and that was creating a conflict for some reason. I shut that off and everything seems to be working great! Thanks!

ocsav

I'm not sure what I've red here...
There should be a prize for the most odd thread on the forum... nice... 8-D

Go Up