Page 1 of 2

Arduinio Heart Rate Midi

Posted: Tue Jul 25, 2017 01:11
by 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 115200 on hairless and in the Arduino code.

Resolume is able to detect the midi but when I midi map the pulse to launch a clip the video just stops. Also when I map it to a slider like opacity, the slider moved up and down from 0 automatically to 100 erratically but the video does not change. Any suggestions?

Code: Select all

#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(noteON, 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
}

Re: Arduinio Heart Rate Midi

Posted: Tue Jul 25, 2017 17:24
by Joris
The first thing that I would do is use Midi Monitor to see what data is actually being sent by the Arduino.

Re: Arduinio Heart Rate Midi

Posted: Tue Jul 25, 2017 21:59
by blabberbytes
The first thing that I would do is use Midi Monitor to see what data is actually being sent by the Arduino.
So I downloaded Midi Monitor and this is what I got:
Midi Monitor
Midi Monitor
Any Ideas?

Re: Arduinio Heart Rate Midi

Posted: Tue Jul 25, 2017 23:39
by Zoltán
Check composition and clip trigger style, in piano mode your clips will stop if they receive a note-off.
Képernyőfotó 2017-07-26 - 0.36.28.png
clip right click menu:
clip right click menu.png

Re: Arduinio Heart Rate Midi

Posted: Wed Jul 26, 2017 00:32
by blabberbytes
Check composition and clip trigger style, in piano mode your clips will stop if they receive a note-off.
Thanks, this is actually helpful for midi attributes with sliders such as opacity and what not. But for launching clips the same thing happens, it just freezes and video doesn't launch. I've tried setting different delays, I was thinking maybe resolume was receiving too much data? Thoughts?

Re: Arduinio Heart Rate Midi

Posted: Wed Jul 26, 2017 01:27
by Oaktown
Why don't you use a MIDI CC and send values of 0 & 100 instead of a MIDI note on or off?

Edit: I meant to say values of 0 & 127

Re: Arduinio Heart Rate Midi

Posted: Wed Jul 26, 2017 04:26
by blabberbytes
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:
clip launch
clip launch
R Button
R Button
Why don't you use a MIDI CC and send values of 0 & 100 instead of a MIDI note on or off?

Edit: I meant to say values of 0 & 127
How would I go about doing CC instead of midi NoteON/OFF?? I've been looking and trying things to no avail. Thanks everyone.

Re: Arduinio Heart Rate Midi

Posted: Wed Jul 26, 2017 10:50
by Joris
Holy crap dude, you're sending around 500 midi messages per second. Do you also have output to the IAC bus enabled in Resolume or something?

Re: Arduinio Heart Rate Midi

Posted: Wed Jul 26, 2017 20:26
by blabberbytes
Holy crap dude, you're sending around 500 midi messages per second. Do you also have output to the IAC bus enabled in Resolume or something?
That was it! Turned off output and that solved my issue. Thanks everyone!

Can someone explain to me what was happening? Still confused a bit.

Re: Arduinio Heart Rate Midi

Posted: Thu Jul 27, 2017 09:51
by Joris
MIDI feedback.

When you enable MIDI output, you essentially say that you want to output all the changes you receive. This is how you get controllers with LED pads to light up, or get motorized faders to respond correctly.

So when you send a message via IAC port 1, Resolume changes the mapped parameter, because you have output enabled, it then also outputs that via MIDI, but because you selected the same port as you're using for input, it sends it to itself again, changing the parameter again, outputting it again, sending to itself again, changing the parameter again, outputting it again, sending to itself again, changing the parameter again....... On to infinity.

It's surprising it didn't hang completely to be honest.