Arduinio Heart Rate Midi

Post your questions here and we'll all try to help.
blabberbytes
Posts: 36
Joined: Tue Jul 05, 2016 23:50

Arduinio Heart Rate Midi

Post 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
}

Joris
Posts: 5186
Joined: Fri May 22, 2009 11:38

Re: Arduinio Heart Rate Midi

Post by Joris »

The first thing that I would do is use Midi Monitor to see what data is actually being sent by the Arduino.

blabberbytes
Posts: 36
Joined: Tue Jul 05, 2016 23:50

Re: Arduinio Heart Rate Midi

Post 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?

Zoltán
Team Resolume
Posts: 7603
Joined: Thu Jan 09, 2014 13:08
Location: Székesfehérvár, Hungary

Re: Arduinio Heart Rate Midi

Post 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
Software developer, Sound Engineer,
Control Your show with ”Enter” - multiple Resolume servers at once - SMPTE/MTC column launch
try for free: http://programs.palffyzoltan.hu

blabberbytes
Posts: 36
Joined: Tue Jul 05, 2016 23:50

Re: Arduinio Heart Rate Midi

Post 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?

User avatar
Oaktown
Resolume honorary member
Posts: 2837
Joined: Tue May 08, 2012 15:19
Location: Oakland, CA

Re: Arduinio Heart Rate Midi

Post 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

blabberbytes
Posts: 36
Joined: Tue Jul 05, 2016 23:50

Re: Arduinio Heart Rate Midi

Post 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.

Joris
Posts: 5186
Joined: Fri May 22, 2009 11:38

Re: Arduinio Heart Rate Midi

Post 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?

blabberbytes
Posts: 36
Joined: Tue Jul 05, 2016 23:50

Re: Arduinio Heart Rate Midi

Post 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.

Joris
Posts: 5186
Joined: Fri May 22, 2009 11:38

Re: Arduinio Heart Rate Midi

Post 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.

Post Reply