URGENT: Aurduino MIDI - Hairless

Hi guys i was hoping you could help us out, we have a project which uses LDR's on a set of gloves to controll midi. Its mostly working, we have the aurdino sending what we think are the right messages to serial when we trigger the LDR's but hairless isnt interpreting the MIDI messages properly, instead its sending out a tone of random messages. I was hoping you guys could help us with what we're doing wrong, heres the code:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

/* Codeist , Midi Gloves and Shoes, 

Callan Marchetti , Sam Cocks , Conor Matheson */

/*This code sends MIDI messages using electrical pulses from FSRs (Force Sensitive Resistors) placed in the toes of shoes and also a resistance change using LDR's in a pair of gloves
It has been adapted from code by Thobson 'Midi Shoes'
/************************************************************/

                 // when the upper threshold is passed a hit is trigered and when the value sinks below the lower threshold another hit is triggered. "HYSTERESIS" makes sure multiple hits arent triggered
#define FINGERTHRESHOLD 400
#define LOWERFINGERTHRESHGHOLD 6
#define TOETHRESHOLD 350
#define LOWERTOETHRESHOLD 101   // We're setting both a lower and an upper threshold for the FSRs, so that they will only trigger a MIDI message when we actually want them too.


#define LHPOINTPIN 0
#define LHMIDPIN 1
#define LHRINGPIN 2
#define LHPINKYPIN 3 
#define RHPINKYPIN 4
#define RHRINGPIN 5   
#define RHMIDPIN 6
#define RHPOINTPIN 7
#define TOE1PIN 8
#define TOE2PIN 9


// Define which analog in pins on the arduino we'll be using

int pinNote[10] = {78,65,88,59,41,42,46,49,73,57};      // This array stores the different MIDI notes that each pin is assigned , do we need this?

boolean lhpoint = false;
boolean lhmid = false;
boolean lhring = false;
boolean lhpinky = false;
boolean rhpinky = false;
boolean rhring = false;
boolean rhmid = false;
boolean rhpoint = false;
boolean toe1 = false;
boolean toe2 = false;                      //These variables will help us to make sure we don't send multiple MIDI messages per single hit        

void setup(void) {
  Serial.begin(57600);                     // We'll send debugging information to the Serial monitor
 
}

void loop(void) {                                                                                                                  // This is the main function that executes all the others.

        
      
        lhpoint = sender((analogRead(LHPOINTPIN)+0), LHPOINTPIN, pinNote[LHPOINTPIN], "", lhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        lhmid = sender((analogRead(LHMIDPIN)+0), LHMIDPIN, pinNote[LHMIDPIN], "", lhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD); 
        
        lhring = sender((analogRead(LHRINGPIN)+0), LHRINGPIN, pinNote[LHRINGPIN], "", lhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        lhpinky = sender((analogRead(LHPINKYPIN)+0), LHPINKYPIN, pinNote[LHPINKYPIN], "", lhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);   
  
        rhpinky = sender((analogRead(RHPINKYPIN)+0), RHPINKYPIN, pinNote[RHPINKYPIN], "", rhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        rhring = sender((analogRead(RHRINGPIN)+0), RHRINGPIN, pinNote[RHRINGPIN], "", rhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  
  
        rhmid = sender((analogRead(RHMIDPIN)+0), RHMIDPIN, pinNote[RHMIDPIN], "", rhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        rhpoint = sender((analogRead(RHPOINTPIN)+0), RHPOINTPIN, pinNote[RHPOINTPIN], "", rhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  
        
        toe1 = sender((analogRead(TOE1PIN)+0), TOE1PIN, pinNote[TOE1PIN], "", toe1, TOETHRESHOLD, LOWERTOETHRESHOLD);
      
        toe2 = sender((analogRead(TOE2PIN)+0), TOE2PIN, pinNote[TOE2PIN], "", toe2, TOETHRESHOLD, LOWERTOETHRESHOLD);  
        
        
}

void midimsg(unsigned char message, unsigned char pitch, unsigned char velocity) {    // This function sends a MIDI message with a message, pitch, and velocity
    Serial.print(message);
    Serial.print(pitch);
    Serial.print(velocity);
}

boolean sender(int reading, int pin, int note, char msg[], boolean press, int threshold, int lowerthreshold ) {   // This function is what does all the work
  if(reading <= threshold) {                                                                                      // If the user stomps harder than a certain threshold...
    if(!press) {                                                                                                  // and if the sensor is not already in 'pressed' mode...
        reading = reading/8 - 1;                                                                                  // convert the FSR reading to a MIDI-friendly value     
	midimsg(144, note, 128);                                                                              // Send a MIDI message
	Serial.println(msg);                                                                                      // Send a unique debug message to the Serial monitor
        delay(100);
     }  press = true;                                                                                             // The sensor is now in 'pressed' mode,
   } else if(reading >= lowerthreshold) {                                                                         // once the applied force sinks below the lower threshold...
	if(press)
        midimsg(128,note,0);	
        press = false;                                                                                    // the sensor is no longer in 'pressed' mode
        }
   return press;
}

Tools + Auto Format would make that mess more readable.

Why are you adding 0 to all the analogRead() values?
Why are you passing a pin number to sender() when sender never uses it?
Why are you sending an empty string to the function?

What is on the other end of the Serial port? What is that expected to do with the carriage return and line feed that you send in sender after each MIDI message?

Is 57600 the correct speed? I thought MIDI was 38400.

Hi, thanks for the quick reply, i tried autoformating it, and i have now changed Serial.print, to serial.write, and it is now working with serial to midi convertor, but it doesn't seem to be outputting useable note data. And when i try it again with hairless its still sending a lot of random messages. Im afraid i don't understand what you mean about the sender, should i delete coming from that?

Here is the new code

/* Codeist , Midi Gloves and Shoes, 
 
 Callan Marchetti , Sam Cocks , Conor Matheson */

/*This code sends MIDI messages using electrical pulses from FSRs (Force Sensitive Resistors) placed in the toes of shoes and also a resistance change using LDR's in a pair of gloves
 It has been adapted from code by Thobson 'Midi Shoes'
/************************************************************/

// when the upper threshold is passed a hit is trigered and when the value sinks below the lower threshold another hit is triggered. "HYSTERESIS" makes sure multiple hits arent triggered
#define FINGERTHRESHOLD 400
#define LOWERFINGERTHRESHGHOLD 6
#define TOETHRESHOLD 350
#define LOWERTOETHRESHOLD 101   // We're setting both a lower and an upper threshold for the FSRs, so that they will only trigger a MIDI message when we actually want them too.


#define LHPOINTPIN 0
#define LHMIDPIN 1
#define LHRINGPIN 2
#define LHPINKYPIN 3 
#define RHPINKYPIN 4
#define RHRINGPIN 5   
#define RHMIDPIN 6
#define RHPOINTPIN 7
#define TOE1PIN 8
#define TOE2PIN 9


// Define which analog in pins on the arduino we'll be using

int pinNote[10] = {
  78,65,88,59,41,42,46,49,73,57};      // This array stores the different MIDI notes that each pin is assigned , do we need this?

boolean lhpoint = false;
boolean lhmid = false;
boolean lhring = false;
boolean lhpinky = false;
boolean rhpinky = false;
boolean rhring = false;
boolean rhmid = false;
boolean rhpoint = false;
boolean toe1 = false;
boolean toe2 = false;                      //These variables will help us to make sure we don't send multiple MIDI messages per single hit        

void setup(void) {
  Serial.begin(57600);                     // We'll send debugging information to the Serial monitor

}

void loop(void) {                                                                                                                  // This is the main function that executes all the others.



  lhpoint = sender((analogRead(LHPOINTPIN)), LHPOINTPIN, pinNote[LHPOINTPIN], "", lhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);

  lhmid = sender((analogRead(LHMIDPIN)), LHMIDPIN, pinNote[LHMIDPIN], "", lhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD); 

  lhring = sender((analogRead(LHRINGPIN)), LHRINGPIN, pinNote[LHRINGPIN], "", lhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);

  lhpinky = sender((analogRead(LHPINKYPIN)), LHPINKYPIN, pinNote[LHPINKYPIN], "", lhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);   

  rhpinky = sender((analogRead(RHPINKYPIN)), RHPINKYPIN, pinNote[RHPINKYPIN], "", rhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);

  rhring = sender((analogRead(RHRINGPIN)), RHRINGPIN, pinNote[RHRINGPIN], "", rhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  

  rhmid = sender((analogRead(RHMIDPIN)), RHMIDPIN, pinNote[RHMIDPIN], "", rhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);

  rhpoint = sender((analogRead(RHPOINTPIN)), RHPOINTPIN, pinNote[RHPOINTPIN], "", rhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  

  toe1 = sender((analogRead(TOE1PIN)), TOE1PIN, pinNote[TOE1PIN], "", toe1, TOETHRESHOLD, LOWERTOETHRESHOLD);

  toe2 = sender((analogRead(TOE2PIN)), TOE2PIN, pinNote[TOE2PIN], "TOE2", toe2, TOETHRESHOLD, LOWERTOETHRESHOLD);  


}

void midimsg(unsigned char message, unsigned char pitch, unsigned char velocity) {    // This function sends a MIDI message with a message, pitch, and velocity
  Serial.write(message);
  Serial.write(pitch);
  Serial.write(velocity);
}

boolean sender(int reading, int pin, int note, char msg[], boolean press, int threshold, int lowerthreshold ) {   // This function is what does all the work
  if(reading <= threshold) {                                                                                      // If the user stomps harder than a certain threshold...
    if(!press) {                                                                                                  // and if the sensor is not already in 'pressed' mode...
      reading = reading/8 - 1;                                                                                  // convert the FSR reading to a MIDI-friendly value     
      midimsg(144, note, 128);                                                                              // Send a MIDI message
      Serial.println(msg);                                                                                      // Send a unique debug message to the Serial monitor
      delay(100);
    }  
    press = true;                                                                                             // The sensor is now in 'pressed' mode,
  } 
  else if(reading >= lowerthreshold) {                                                                         // once the applied force sinks below the lower threshold...
    if(press)
      midimsg(128,note,0);	
    press = false;                                                                                    // the sensor is no longer in 'pressed' mode
  }
  return press;
}
boolean sender(int reading, int pin, int note, char msg[], boolean press, int threshold, int lowerthreshold ) {   // This function is what does all the work
  if(reading <= threshold) {                                                                                      // If the user stomps harder than a certain threshold...
    if(!press) {                                                                                                  // and if the sensor is not already in 'pressed' mode...
      reading = reading/8 - 1;                                                                                  // convert the FSR reading to a MIDI-friendly value     
      midimsg(144, note, 128);                                                                              // Send a MIDI message
      Serial.println(msg);

What is that Serial.println() statement doing there? Is your MIDI device expecting a carriage return and line feed? Why are you passing msg to the function when it is always and empty string?

Why are you passing pin to the function when it does not use it?

So i stripped away Serial.println(), msg and pin and im now getting an error in hairless saying Error: got unexpected data byte 0x6, any idea? Thanks for all the help its greatly appreciated!

So i stripped away Serial.println(), msg and pin

But, I'm not going to show you the changed code...

Sorry here it is

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

/* Codeist , Midi Gloves and Shoes, 

Callan Marchetti , Sam Cocks , Conor Matheson */

/*This code sends MIDI messages using electrical pulses from FSRs (Force Sensitive Resistors) placed in the toes of shoes and also a resistance change using LDR's in a pair of gloves
It has been adapted from code by Thobson 'Midi Shoes'
/************************************************************/

                 // when the upper threshold is passed a hit is trigered and when the value sinks below the lower threshold another hit is triggered. "HYSTERESIS" makes sure multiple hits arent triggered
#define FINGERTHRESHOLD 400
#define LOWERFINGERTHRESHGHOLD 6
#define TOETHRESHOLD 350
#define LOWERTOETHRESHOLD 101   // We're setting both a lower and an upper threshold for the FSRs, so that they will only trigger a MIDI message when we actually want them too.


#define LHPOINTPIN 0
#define LHMIDPIN 1
#define LHRINGPIN 2
#define LHPINKYPIN 3 
#define RHPINKYPIN 4
#define RHRINGPIN 5   
#define RHMIDPIN 6
#define RHPOINTPIN 7
#define TOE1PIN 8
#define TOE2PIN 9
#define  midichannel	0; 


// Define which analog in pins on the arduino we'll be using

int pinNote[10] = {78,65,88,59,41,42,46,49,73,57};      // This array stores the different MIDI notes that each pin is assigned , do we need this?

boolean lhpoint = false;
boolean lhmid = false;
boolean lhring = false;
boolean lhpinky = false;
boolean rhpinky = false;
boolean rhring = false;
boolean rhmid = false;
boolean rhpoint = false;
boolean toe1 = false;
boolean toe2 = false;                      //These variables will help us to make sure we don't send multiple MIDI messages per single hit        

void setup() {
  MIDI.begin(1);
  Serial.begin(57600);
}                    // We'll send debugging information to the Serial monitor
 


void loop(void) {                                                                                                                  // This is the main function that executes all the others.

        
      
        lhpoint = sender((analogRead(LHPOINTPIN)+0), pinNote[LHPOINTPIN], lhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        lhmid = sender((analogRead(LHMIDPIN)+0), pinNote[LHMIDPIN], lhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD); 
        
        lhring = sender((analogRead(LHRINGPIN)+0), pinNote[LHRINGPIN], lhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        lhpinky = sender((analogRead(LHPINKYPIN)+0), pinNote[LHPINKYPIN], lhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);   
  
        rhpinky = sender((analogRead(RHPINKYPIN)+0), pinNote[RHPINKYPIN], rhpinky, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        rhring = sender((analogRead(RHRINGPIN)+0), pinNote[RHRINGPIN], rhring, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  
  
        rhmid = sender((analogRead(RHMIDPIN)+0), pinNote[RHMIDPIN], rhmid, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);
      
        rhpoint = sender((analogRead(RHPOINTPIN)+0), pinNote[RHPOINTPIN], rhpoint, FINGERTHRESHOLD, LOWERFINGERTHRESHGHOLD);  
        
        toe1 = sender((analogRead(TOE1PIN)+0), pinNote[TOE1PIN], toe1, TOETHRESHOLD, LOWERTOETHRESHOLD);
      
        toe2 = sender((analogRead(TOE2PIN)+0), pinNote[TOE2PIN], toe2, TOETHRESHOLD, LOWERTOETHRESHOLD);  
        
        
}

void midimsg(unsigned char message, unsigned char pitch, unsigned char velocity) {    // This function sends a MIDI message with a message, pitch, and velocity
   
    Serial.write(message);
    Serial.write(pitch);
    Serial.write(velocity);
}

boolean sender(int reading, int note, boolean press, int threshold, int lowerthreshold ) {   // This function is what does all the work
  if(reading <= threshold) {                                                                                      // If the user stomps harder than a certain threshold...
    if(!press) {                                                                                                  // and if the sensor is not already in 'pressed' mode...
        reading = reading/20 - 1;                                                                                  // convert the FSR reading to a MIDI-friendly value     
	midimsg(144, note, 128);                                                                              // Send a MIDI message
	                                                                                      // Send a unique debug message to the Serial monitor
        delay(100);
     }  press = true;                                                                                             // The sensor is now in 'pressed' mode,
   } else if(reading >= lowerthreshold) {                                                                         // once the applied force sinks below the lower threshold...
	if(press)
        midimsg(128,note,0);	
        press = false;                                                                                    // the sensor is no longer in 'pressed' mode
        }
   return press;
}

You are back to adding 0 to the analogRead() output, and back to the crappy formatting. Why?

I don't see where you are using the MIDI class at all. Why include the library and initialize the instance?

Sorry, i forgot to take the 0's out and reformat it. As far as the midi library is concerned, the hairless documentation said it was required, and is it not needed for the midi.begin in the setup function?

Bump: is anyone able to help out with this? Its part of a University project and would be greatly appreciated

The MIDI class has a method to send data. The order of the things that it sends is not the same as the order of the things you send. I'm not even sure that the things are completely compatible. Where did you get the idea that your list was correct, and in the correct order?

Would the order for the midi not be note message, note number and velocity? Thats whats coming up in the serial monitor so i thought thats all that would get sent to Hairless, as for the lists, I'm not sure, we adapted this from existing code.

Esentially i just want to use the LDR's as switches whicc triger a midi message of a set note and velocity when theres a drop in light and send a midi off message for the same note when the light increases. I have it printing what appears to be the correct midi message in the serial monitor under these conditions but they come up as errors or random messages in hairless

Would the order for the midi not be note message, note number and velocity?

Take a look at this page.
http://arduinomidilib.sourceforge.net/a00001.html

Note the sendNoteOn() method, and the order and data sent by that method.