Pages: 1 2 [3]   Go Down
Author Topic: Arduino dropping midi signals  (Read 6898 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

I ran into exactly the same scenario and found a workaround.
I had kuk's MIDI solution wired on a second hand Yamaha keyboard I bought, and was only able to receive a 144 note on signal every 4 or so seconds.
I was pretty sure it had to be the same reason, as the original poster also mentioned a Yamaha PSR series keyboard.
It turns out that Yamaha does kind of ignore MIDI standards. The signals I received on playing "C D E" for example were:
144
20 80 20 0
22 80 22 0
24 80 24 0
So the information about all the notes is being passed through, just not always starting with a 144 note on signal. No idea why.
But every noted is being closed with a velocity of 0, which can be used to detect which notes have been played:

Code:
void loop () { 
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
         
    if (incomingByte >= 36 && incomingByte <= 96) { // note range is between 36 and 96
      prevNote = incomingByte;     
    }   
    else if (incomingByte == 0) {
      blink();
      output += prevNote;
      output += "-";
    }
  }
}

So my code ignores the 144 signals, but every time it detects a 0 signal, it adds the previously read byte to the output, as that one represents the note that has just been hit. This doesn't yet take velocity into account, a slightly more complex code is needed for that, but for me this was sufficient.

Hope this helps!
Logged

Berlin / Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I also searched for how-to Midi merge with Arduino and came across this thread one day. I finally solved this and here (just if anyone needs it one day) is how it works for me:

Using an Arduino Uno R3, the Midi library V3.2 of Franky, the below posted code and the appended schematic for the midi interface (note: I guess you can leave out R11 and the inverter(s) 74HC14N out here).

Code:
#include <MIDI.h>

void setup() {
MIDI.begin();
MIDI.turnThruOn();
}

void loop() {
MIDI.read();
}

It is connected to RX and TX on the Uno (digital pin 0 and 1) while powered by USB - works.
I also already tested this with merging other midicontroller data coming from my software (e.g. a potentiometer connected to an analog input of the Uno)) - works.

Simple and working!

The only restriction is: You must have RX disconnected from the midi-circuit while updating the program via the Arduino IDE and USB - it seems to interfere with the USB connection and disturb the transfer. My try to fix this will be to use other pins for the Midi-connection, will test that within the next days.

greets,
Bruce


* midi.jpg (71.03 KB, 693x404 - viewed 25 times.)
« Last Edit: October 17, 2012, 11:40:40 pm by BruceX » Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 234
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had kuk's MIDI solution wired on a second hand Yamaha keyboard I bought, and was only able to receive a 144 note on signal every 4 or so seconds.
I was pretty sure it had to be the same reason, as the original poster also mentioned a Yamaha PSR series keyboard.
It turns out that Yamaha does kind of ignore MIDI standards.

No, it doesn't. Yahaha uses MIDI just fine. It means that your code is ignoring MIDI standards; in particular, it is failing to detect running status which is part of the MIDI standard. Basically, if the status bytes would be the same as the status for the previous message, sending it is optional. So code which reads MIDI needs to keep the last-seen status around in a variable.

The signals I received on playing "C D E" for example were:
144
20 80 20 0
22 80 22 0
24 80 24 0
So the information about all the notes is being passed through, just not always starting with a 144 note on signal.
Yes, that is a compliant MIDI stream.

No idea why.
The reason why was mentioned in this thread, a couple of posts above yours  smiley-wink

So my code ignores the 144 signals, but every time it detects a 0 signal, it adds the previously read byte to the output, as that one represents the note that has just been hit. This doesn't yet take velocity into account, a slightly more complex code is needed for that, but for me this was sufficient.

Hope this helps!
No, actually, it doesn't help. Firstly, it ignores the runing status, which is easily detected and saved. Secondly, it introduces unnecessary lag. Thirdly, as you say, it ignores velocity. Fourthly, the code ignores status so won't cope with other status messages being mixed in with the note stream.
« Last Edit: October 19, 2012, 04:56:20 am by Nantonos » Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 234
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The only restriction is: You must have RX disconnected from the midi-circuit while updating the program via the Arduino IDE and USB - it seems to interfere with the USB connection and disturb the transfer. My try to fix this will be to use other pins for the Midi-connection, will test that within the next days.

Yes, program upload over USB to serial, and MIDI input on serial, will interfere with each other.

On boards with multiple hardware serial UARTs, like the Mega, the solution is simply to connect MIDI to a different serial (Serial1, Serial2, or Serial3, not Serial).

On boards with a single hardware serial the options are:
  • use software serial (ewww)
  • physically disconnect MIDI input each time you program
  • use a latching switch to physically disconnect  MIDI input each time you program
  • put a tri-state buffer between the output of the optoisolator and SerialRX, with the enable input pulled normally low. This disables MIDI in. Use a separate digital output to take this high, in the setup part of the sketch, to enable MIDI.
Logged

Berlin / Germany
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

use software serial (ewww)
This is what I plan to do ... also because I want to integrate an USB/Midi-Interface in my Midi-Controller. (I am currently in research/learn/development-phase but the most stuff is already tested&understood, the schematic is also basically done, next is the pcb-layout and putting together the "big programm")

physically disconnect MIDI input each time you program
This is what I did while testing on the breadboard. On a final device one could use switch for that but this is somehow lame for an engineer. smiley-grin

greets,
Bruce
Logged

Pages: 1 2 [3]   Go Up
Jump to: