Pages: [1]   Go Down
Author Topic: Serial Midi Converter  (Read 4696 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-roll-sweat
Hello,
I am making a midi drum and I have finished building it but my problem is that Serial MIDI Converter flashes me a red light on the Serial RX. From what I understand is that it should be showing a green light to show that it is receiving a midi signal. What does a midi line look like? I am running code that I found online:

Code:
//*******************************************************************************************************************
// User settable variables
//*******************************************************************************************************************

unsigned char PadNote[6] = {60,61,62,63,64,65};         // MIDI notes from 0 to 127 (Mid C = 60)

int PadCutOff[6] = {900,900,900,900,900,900};           // Minimum Analog value to cause a drum hit

int MaxPlayTime[6] = {90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed

#define  midichannel 0;                              // MIDI channel from 0 to 15 (+1 in "real world")

boolean VelocityFlag  = true;                           // Velocity ON (true) or OFF (false)

//*******************************************************************************************************************
// Internal Use Variables
//*******************************************************************************************************************

boolean activePad[6] = {0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0,0,0};                     // Counter since pad started to play

unsigned char status;

int pin = 0;    
int hitavg = 0;

//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************

void setup()
{
  Serial.begin(57600);                                  // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************

void loop()
{
  for(int pin=0; pin < 6; pin++)
  {
    hitavg = analogRead(pin);                              // read the input pin

    if((hitavg > PadCutOff[pin]))
    {
      if((activePad[pin] == false))
      {
        if(VelocityFlag == true)
        {
//          hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
          hitavg = (hitavg / 8 ) -1 ;                                                 // Upper range
        }
        else
        {
          hitavg = 127;
        }

        MIDI_TX(144,PadNote[pin],hitavg);
        PinPlayTime[pin] = 0;
        activePad[pin] = true;
      }
      else
      {
        PinPlayTime[pin] = PinPlayTime[pin] + 1;
      }
    }
    else if((activePad[pin] == true))
    {
      PinPlayTime[pin] = PinPlayTime[pin] + 1;
      
      if(PinPlayTime[pin] > MaxPlayTime[pin])
      {
        activePad[pin] = false;
        MIDI_TX(128,PadNote[pin],127);
      }
    }
  }
}


//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{  
  status = MESSAGE + midichannel;
  Serial.print(status);
  Serial.print(PITCH);
  Serial.print(VELOCITY);
  
}


Any ideas on how to resolve my issue?
« Last Edit: December 22, 2011, 07:02:14 am by AspireBear » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34510
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please modify that post. Select the code  and hit the # icon and save.
Next how have you got this wired up ?
It is not outputting at MIDI speeds so it must be sending stuff straight into the serial port. What application have you got that translates this into MIDI?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did the following:

With the grounds from the piezos connected to one ground.
And I am using Serial Midi Converter on my Macbook, configured like so:
http://spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html
And that is where my data shows that it is not midi formated... Are there better Midi apps for mac?
I tried changing my baud rate to 31250 and had the same problem.
Edit: I tried again with a baud rate of 31250 and Serial Midi Converter freezes when i select my output...
« Last Edit: December 22, 2011, 07:27:21 am by AspireBear » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34510
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What version of the arduino IDE are you running?
Recent changes might make it not work.
Try replacing that function at the end with this:-
Code:
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)

  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
 
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow! Your the best! That made all the difference, I fiddled with my settings in Ableton Live and now it works with that new line of code!
What I changed in Ableton was the in the Preferences > MIDI Sync and turned on all IAC Input and Output (Track & Remote) and it works!
Now I can drum away  smiley

Thanks Grumpy_Mike.
Logged

Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Try replacing that function at the end with this:-
Code:
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{  
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
  
}

Grumpy_Mike, you are a genius!   smiley

P.S. After thinking about it, I understand why this works and the previous version doesn't.
But I am puzzled on why did the previous version worked with older board, if it did.
« Last Edit: November 11, 2012, 10:56:56 pm by Thot » Logged

There are three kind of people in the world: Those who can count, and those who can't

Pages: [1]   Go Up
Jump to: