Teensy 3.0 USB Midi recognized but not being read by Android (Nexus 7).

Status
Not open for further replies.
I am trying to make my Teensy 3.0 play notes on my Nexus 7. The two devices are connected via a regular USB and an On-the-Go adapter cable (I've see these two cables work fine with an ordinary Midi controller). I also selected "Midi" under board type.

After I plug the Teensy into my Nexus 7, the Nexus 7 recognizes the Teensy as a Midi device, but nothing seems to happen. When I load the Grand Piano Pro app, no sounds come out. I also don't see any messages received by the "USB Midi Monitor" app (but then again, my other Midi Controller which does produce sound also doesn't show up on USB Midi Monitor).

Could the clock speed be causing an issue? The Teensyduino IDE has set 96 MHz "overclock" by default. Could this be causing an issue? I would check it myself right now, but I'm several miles from my Teensy.

My current code is below. I've tried many variations of it:

Code:
#include <Bounce.h>

const int channel = 1;
const int ledPin = 13;

void setup() {
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    usbMIDI.sendNoteOn(0x90, note, 0x45);
    delay(100);
    digitalWrite(ledPin, HIGH);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    usbMIDI.sendNoteOn(0x90, note, 0x00);   
    delay(100);
    digitalWrite(ledPin, LOW);
  }
}
 
The clock speed is unlikely to be the problem.

First, I'd recommend trying it with a Mac or PC, just to make sure it's really working.

You might also check this thread about stalls when the host unexpectedly transmits messages. The workaround is simple, just add 1 line in loop() to read and ignore any incoming messages.
 
The clock speed is unlikely to be the problem.

First, I'd recommend trying it with a Mac or PC, just to make sure it's really working.

You might also check this thread about stalls when the host unexpectedly transmits messages. The workaround is simple, just add 1 line in loop() to read and ignore any incoming messages.

No, that didn't do it. I'm not sure what other information there is to give.
 
Does it work when connected to a PC or Mac? It'd be useful to know if this is "only" a compatibility problem with Android, or if it's simply not working for some reason?
 
My current code is below.

Code:
void loop() {
  // play notes from F#-0 (0x1E) to F#-5 (0x5A):
  for (int note = 0x1E; note < 0x5A; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    usbMIDI.sendNoteOn(0x90, note, 0x45);
    delay(100);
    digitalWrite(ledPin, HIGH);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    usbMIDI.sendNoteOn(0x90, note, 0x00);   
    delay(100);
    digitalWrite(ledPin, LOW);
  }
}

One immediate problem with your code is the order and value of the parameters to sendNoteOn. Your comment indicates that you think 0x90 means channel one and is the first parameter, and that velocity is the third parameter.
Code:
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    usbMIDI.sendNoteOn(0x90, note, 0x45);

while the actual order of parameters is note, velocity, channel:
Code:
void sendNoteOn(uint32_t note, uint32_t velocity, uint32_t channel)
and the value to use for channel one is, well, one.

So:
Code:
//Send  some note value (note), middle velocity (0x45) on channel 1 (1),:
    usbMIDI.sendNoteOn( note, 0x45, 1);

same error on your zero-velocity note on to switch the note off:

Code:
    //Some note value (note), silent velocity (0x00) on channel 1 (1):
    usbMIDI.sendNoteOn(note, 0x00, 1);

Thus, what your code is currently doing is sending fixed a NoteOn to channel 45 and then the same NoteO to channel 0, in a loop where the variable 'note' is actually controlling velocity. Valid channels run from 1 to 16.

You can read about the USB MIDI implementation (including the type and order of parameters) here.
 
Last edited:
I installed Midi-Ox and verified that the Teensy was in fact transmitting.

I then added a large delay in the setup() function. Android's Grand Piano Pro was finally able to play sounds from the Teensy.

However, the app plays the note only four times and then stops. I figure there must be some kind of timing issue or message backup, but I don't know where to look. I've also taken Paul's advice and added a delay to read and ignore incoming messages.

Code:
void setup()
{
delay(3000);
}

void loop()
{
    delay(2500);
    while (usbMIDI.read()) ; // read and discard any incoming MIDI messages

    usbMIDI.sendNoteOn(60, 99, 1);  // 60 = C4
    
    delay(2500);
    while (usbMIDI.read()) ; // read and discard any incoming MIDI messages
    
    usbMIDI.sendNoteOff(60, 0, 1);
}
 
As an addendum to the above info:

When I connect the same code to Midi-Ox (and my PC's default Midi Synth), I also only hear a couple of notes played before it stops. On Midi-Ox, I hear no new notes playing AND I see no new messages appearing.

In other words, the problem seems to be on the Teensy. I remember in Arduino I had to set a baud rate. Do I have to set a baud rate here?
 
Issue is solved.

Apparently the Android Grand Piano app has a default setting of "Output to Midi/USB". Once I deselected this, the notes continued to play.

Still, I'd like to know why changing this setting fixed the problem. If the problem was simply message transfer back to the Teensy, then how come the line
Code:
while (usbMIDI.read()) ;
didn't fix the problem? Does the "Output to Midi/USB" setting change the behavior of the USB connection (after four notes or so)?

First I want to clear this up:
When I connect the same code to Midi-Ox (and my PC's default Midi Synth), I also only hear a couple of notes played before it stops. On Midi-Ox, I hear no new notes playing AND I see no new messages appearing.

Originally this was a problem, but once I added the line
Code:
while (usbMIDI.read()) ;
, the Windows Synth played the notes fine.
 
Status
Not open for further replies.
Back
Top