Hi all,
Is there general pointer to gotchas/tips for solving USB Host-mode problems, on Teensy 3.6, or in general?
Today I've got everything wired together, using the USB host cable from PJRC.
But at the moment the symptom is that Teensy hangs the moment I plug in a USB client device.
(Log stops printing & led stops blinking.)
I tried this with a 150ma (labeled) USB MIDI musical instrument as client, as well as with
my 64ma (measured!) Pocket Integrator board. In both cases the Teensy freezes
when I plug in, stays frozen after I unplug.
Could this be a power problem?
I am plugging Teensy straight into a powered hub, so I expect to be able to draw 500ma total.
I am using short, thick USB cables.
Also, I have the LED lit on the Teensy when I plug this in, it doesn't dim or flicker when the hang happens.
And the USB devices themselves function just fine.
Or maybe it's a software problem? Code below, it's simple. Possibly the call to myusb.Task() or MIDI.read() is hanging
when I plug in the usb MIDI device? But I don't know why they would.
Any ideas would be most welcome. Thanks!
-mykle-
------
Is there general pointer to gotchas/tips for solving USB Host-mode problems, on Teensy 3.6, or in general?
Today I've got everything wired together, using the USB host cable from PJRC.
But at the moment the symptom is that Teensy hangs the moment I plug in a USB client device.
(Log stops printing & led stops blinking.)
I tried this with a 150ma (labeled) USB MIDI musical instrument as client, as well as with
my 64ma (measured!) Pocket Integrator board. In both cases the Teensy freezes
when I plug in, stays frozen after I unplug.
Could this be a power problem?
I am plugging Teensy straight into a powered hub, so I expect to be able to draw 500ma total.
I am using short, thick USB cables.
Also, I have the LED lit on the Teensy when I plug this in, it doesn't dim or flicker when the hang happens.
And the USB devices themselves function just fine.
Or maybe it's a software problem? Code below, it's simple. Possibly the call to myusb.Task() or MIDI.read() is hanging
when I plug in the usb MIDI device? But I don't know why they would.
Any ideas would be most welcome. Thanks!
-mykle-
------
Code:
#include <elapsedMillis.h>
#include <MIDI.h>
#define TEENSY36
#ifdef TEENSY36
#include <USBHost_t36.h>
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
MIDIDevice MIDI(myusb);
#else
MIDI_CREATE_DEFAULT_INSTANCE();
#endif
#include "NoteList.h"
NoteList nl;
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
nl.add(channel, pitch, velocity);
}
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
nl.remove(pitch);
}
// -----------------------------------------------------------------------------
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
#ifdef TEENSY36
Serial.begin(115200);
// Wait 1.5 seconds before turning on USB Host.
delay(1500);
Serial.println("USB Host InputFunctions example");
delay(10); // why?
myusb.begin();
#endif
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
#ifdef TEENSY36
MIDI.begin();
#else
MIDI.begin(MIDI_CHANNEL_OMNI);
#endif
#ifndef TEENSY36
// on Pico-philtower, there were problems when (usb)Serial was started before (usb)MIDI
Serial.begin(115200);
delay(200); // let USB stabilize before speaking ...
#endif
}
#define LOGTIME 1000 //ms
void loop()
{
static elapsedMillis logTimer = 0;
static bool ledOn = false;
#ifdef TEENSY36
myusb.Task();
#endif
MIDI.read();
if (logTimer > LOGTIME){
digitalWrite(LED_BUILTIN, ledOn ? HIGH : LOW);
logTimer -= LOGTIME;
ledOn = !ledOn;
Serial.println("log:");
nl.print(&Serial);
}
}