I'm trying to run the MIDI example (http://arduino.cc/en/Tutorial/Midi) on my Arduino Yun. However, when I run the example, the MIDI messages I see on the Mac are garbled. I've verified the hardware setup, so I'm not sure what's causing the notes to be messed up.
I simplified the code a little bit to only play one note, and I moved the output to SoftwareSerial since Serial1 is reserved on the Yun. Here is the code:
#include <SoftwareSerial.h>
SoftwareSerial MidiPort(7, 6);
void setup()
{
MidiPort.begin(31250);
}
void noteOn(byte cmd, byte data1, byte data2)
{
MidiPort.write(cmd);
MidiPort.write(data1);
MidiPort.write(data2);
}
void loop()
{
// Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, 0x5a, 0x45);
delay(1000);
// Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, 0x5a, 0x00);
delay(1000);
}
And here is the output from MIDI Monitor (snoize: MIDI Monitor), where numbers prefixed with $ are in base 16. It almost looks like the baud rate is wrong, but I'm setting it to 31250:
21:19:38.576 From USB Midi Note On 1 $5A 69
21:19:39.577 From USB Midi Note On 1 $10 90
21:19:40.578 From USB Midi Note On 1 $5A 69
21:19:41.579 From USB Midi Note On 1 $00 90
21:19:42.580 From USB Midi Note On 1 $5A 5
21:19:43.584 From USB Midi Note Off 1 $5A 0
21:19:44.583 From USB Midi Note On 1 $1A 69
21:19:45.584 From USB Midi Note On 1 $10 90
21:19:46.585 From USB Midi Note On 1 $1A 69
21:19:47.586 From USB Midi Note Off 1 $1A 0
21:19:48.587 From USB Midi Note On 1 $5A 69
21:19:49.588 From USB Midi Note Off 1 $5A 0
21:19:50.589 From USB Midi Note On 1 $5A 69
21:19:51.590 From USB Midi Note Off 1 $5A 0
21:19:52.592 From USB Midi Note On 1 $5A 69
21:19:53.593 From USB Midi Note Off 1 $5A 0
21:19:54.594 From USB Midi Note On 1 $00 90
21:19:55.595 From USB Midi Note Off 1 $5A 0
21:19:56.596 From USB Midi Note On 1 $10 90
21:19:57.597 From USB Midi Note Off 1 $5A 0
21:19:58.598 From USB Midi Note On 1 $5A 69
21:19:59.599 From USB Midi Note On 1 $10 26
21:20:00.601 From USB Midi Note On 1 $5A 5
21:20:01.601 From USB Midi Note On 1 $10 18
21:20:02.603 From USB Midi Note On 1 $5A 69
21:20:03.604 From USB Midi Note Off 1 $5A 0
21:20:04.605 From USB Midi Note On 1 $5A 69
21:20:05.606 From USB Midi Note Off 1 $5A 0
21:20:06.607 From USB Midi Note On 1 $10 90
21:20:07.608 From USB Midi Note Off 1 $5A 0
Does anyone see anything wrong with the code? I'm beginning to think it might be the MIDI cable's fault. I have this one: http://www.amazon.com/SANOXY-Cable-Converter-Keyboard-Window/dp/B0017H4EBG
Thanks in advance!