Go Down

Topic: Midi Input (Read 3615 times) previous topic - next topic

Chole

Jun 03, 2016, 02:17 am Last Edit: Jun 03, 2016, 02:25 am by Chole
For the life of me I cant manage to make an input midi circuit to work. I rearranged it a dozen times, tying different guides but get that led to turn on. I managed to make a midi keyboard receive notes but not output. I rechecked the midi connector pins, so what else could I be doing wrong?

Attached is a picture of my circuit.

antman49443

Couple things to check:
1.  Assume you're using 5V power supply to 6N138?
2.  Check the resistor from Pin 6. The photo looks like it's only 47 ohms but the photo color could be off.  Make sure it's 470 ohms (yellow purple brown  / 471 )
3.  Check the input diode between pin 2 and 3.  I don't see the band in the photo.  Make sure the band is towards pin 2

Chole

Couple things to check:
1.  Assume you're using 5V power supply to 6N138?
2.  Check the resistor from Pin 6. The photo looks like it's only 47 ohms but the photo color could be off.  Make sure it's 470 ohms (yellow purple brown  / 471 )
3.  Check the input diode between pin 2 and 3.  I don't see the band in the photo.  Make sure the band is towards pin 2
Hi,
Its 5v to pin 8. Multimetar read 450 ohms from the resistor, and i checked it online its 470 (yellow, purple, black, black, brown). The diode is towards pin 2. Dont know what else it can be, maybe output midi on my keyboard is not working although input port did. 

Grumpy_Mike

Can you post a schematic of what you are trying to make please.

Chole

Can you post a schematic of what you are trying to make please.
Essentially what I am trying to accomplish is playing a specific few notes in a row on a keyboard will open a solenoid.
I tried to make this by following this guide as well as this one. Couldn't make them work. Schematics are in the links.

Grumpy_Mike

We need to know the schematic you were trying to follow in those pictures you posted. Then we need to see the code you are using when you use that schematic.

Chole

Ofocurse, here is the schematic, and the code.
Code: [Select]
/*Receive MIDI and check if note = 60
By Amanda Ghassaei
July 2012
<a href="http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/">

http://www.instructables.com/id/Send-and-Receive-...>

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.

*/

byte commandByte;
byte noteByte;
byte velocityByte;

byte noteOn = 144;

//light up led at pin 13 when receiving noteON message with note = 60

void setup(){
  Serial.begin(31250);
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
}

void checkMIDI(){
  do{
    if (Serial.available()){
      commandByte = Serial.read();//read first byte
      noteByte = Serial.read();//read next byte
      velocityByte = Serial.read();//read final byte
      if (commandByte == noteOn){//if note on message
        //check if note == 60 and velocity > 0
        if (noteByte == 60 && velocityByte > 0){
          digitalWrite(13,HIGH);//turn on led
        }
      }
    }
  }
  while (Serial.available() > 2);//when at least three bytes available
}
   

void loop(){
  checkMIDI();
  delay(100);
  digitalWrite(13,LOW);//turn led off
}

Grumpy_Mike

That code comes with a warning, it says Instructables, this is code for what follows is a load of crap written by someone with an inflated idea of their own ability. Use only if you know way more than the person who wrote it.

That code shows that the writer had no idea about MIDI.

There is just so much wrong with it. Unless your MIDI is composed entirely of three byte messages it will get stuck and never show anything.

Scrap the crap.

Just write a program that changes the state of an LED each time anything is received, that will be enough to check out your hardware. Get that blinking first before worrying about trying to make sense of your message.

Chole

I also tried with this one, didnt work for me.
Code: [Select]
#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
  // OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
  // to respond to notes on channel 2 only.
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function you want to call when a NOTE ON command
  // is received. In this case it's "MyHandleNoteOn".
  MIDI.setHandleNoteOff(MyHandleNoteOff); // This command tells the Midi Library
  // to call "MyHandleNoteOff" when a NOTE OFF command is received.
}

void loop() { // Main loop
  MIDI.read(); // Continuously check if Midi data has been received.
}

// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
}

// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,LOW);  //Turn LED off
}

Grumpy_Mike

OK what part of:-
Quote
Just write a program that changes the state of an LED each time anything is received, that will be enough to check out your hardware. Get that blinking first before worrying about trying to make sense of your message.
Are you having trouble with?

You have to prove the hardware first before delving into decoding it. No matter how good you are you have to take the smallest step you can at a time, test it and get it working. Otherwise there is too much that can go wrong and without test equipment you will find it hard to work out what is wrong.

If you have an oscilloscope the look at the signal on the RX input, does it change? If not can you see any change in the voltage level of the input side of the opto isolater.

Chole

OK what part of:-Are you having trouble with?

You have to prove the hardware first before delving into decoding it. No matter how good you are you have to take the smallest step you can at a time, test it and get it working. Otherwise there is too much that can go wrong and without test equipment you will find it hard to work out what is wrong.

If you have an oscilloscope the look at the signal on the RX input, does it change?
I'm quite new at this actually. That last piece of code is from another guide i tried just in case it might work. Don't have an oscilloscope.

If not can you see any change in the voltage level of the input side of the opto isolater.
I'm sorry can you expand on this further?

Grumpy_Mike

That was what to do if you did have an oscilloscope.

If you do not then do what I said in the previous post. You can not just go round steeling code that you don't understand.

You have an error somewhere and I am trying to help you find it. But I can only help if you do the things I ask because only you have the none functioning system.

If you don't understand what I am asking you then ask me.

Chole

I appreciate the help, I know explaining seemingly simple things to a beginner requires patience, but its all still magic to me.

You said I need to test the hardware with a blinking LED. How do I start with this?

Grumpy_Mike

I told you in reply #7 and again this was quoted in reply #9.

Write code that whenever there is a serial input byte in the buffer read it and change the state of the led. Just that.

Chole

Code: [Select]
int incomingByte = 0; 


void setup() {
        Serial.begin(9600);     
        pinMode(13,OUTPUT);
       
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                digitalWrite(13, HIGH);
}
                else
{
                digitalWrite(13, LOW);
}
        }


I am not sure if I am doing this right. Pin 13 doesn't go high when I press a keyboard key.

Go Up