Trying to figure out this Teensy USB host stuff, but found no documentation on it so here is the issue.
I'm on Teensyduino 1.56 Arduino 1.8.19
I want to connect some other Teensy( 3 x 3.2s) devices over USB serial via a 4-port powered hub. They just send some serial data over USB serial back to T4.1 host
This works perfectly if I connect to the T4.1 host without the hub. Connect/disconnect, send/receive data etc - all good.
The issue is when I use the hub connected to the T4.1 host. I can plug in a t3.2 to the huband its ok .
However when I disconnect the t there is no 'disconnect' message.
Replugging it and it does not connect back to the host. No connect message, nothing.
The only way to get it to works is unplug the hub and the t3.2 and replug the whole thing which is obviously of no practical use.
Connecting the hub and T.3.2 to my MacBook and it seems fine.
I'm using the example from USBHOST-T36 - 'Serial' - not that easy to understand - seems to have a load of stuff for some robot device which
I removed as it had no use for my testing.
My T4.1 sketch is shown below. Any ideas on how to fix this ?
TIA
I'm on Teensyduino 1.56 Arduino 1.8.19
I want to connect some other Teensy( 3 x 3.2s) devices over USB serial via a 4-port powered hub. They just send some serial data over USB serial back to T4.1 host
This works perfectly if I connect to the T4.1 host without the hub. Connect/disconnect, send/receive data etc - all good.
The issue is when I use the hub connected to the T4.1 host. I can plug in a t3.2 to the huband its ok .
However when I disconnect the t there is no 'disconnect' message.
Replugging it and it does not connect back to the host. No connect message, nothing.
The only way to get it to works is unplug the hub and the t3.2 and replug the whole thing which is obviously of no practical use.
Connecting the hub and T.3.2 to my MacBook and it seems fine.
I'm using the example from USBHOST-T36 - 'Serial' - not that easy to understand - seems to have a load of stuff for some robot device which
I removed as it had no use for my testing.
My T4.1 sketch is shown below. Any ideas on how to fix this ?
TIA
Code:
// Simple test of USB Host Mouse/Keyboard
//
// This example is in the public domain
#include "USBHost_t36.h"
#define USBBAUD 115200
uint32_t baud = USBBAUD;
uint32_t format = USBHOST_SERIAL_8N1;
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
// There is now two versions of the USBSerial class, that are both derived from a common Base class
// The difference is on how large of transfers that it can handle. This is controlled by
// the device descriptor, where up to now we handled those up to 64 byte USB transfers.
// But there are now new devices that support larger transfer like 512 bytes. This for example
// includes the Teensy 4.x boards. For these we need the big buffer version.
// uncomment one of the following defines for userial
//USBSerial userial(myusb); // works only for those Serial devices who transfer <=64 bytes (like T3.x, FTDI...)
USBSerial_BigBuffer userial(myusb, 1); // Handles anything up to 512 bytes
//USBSerial_BigBuffer userial(myusb); // Handles up to 512 but by default only for those > 64 bytes
USBDriver *drivers[] = {&hub1, &hub2, &hid1, &hid2, &hid3, &userial};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "Hub2", "HID1", "HID2", "HID3", "USERIAL1" };
bool driver_active[CNT_DEVICES] = {false, false, false, false};
void setup()
{
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
for (int i = 0; i < 5; i++) {
digitalWrite(2, HIGH);
delayMicroseconds(50);
digitalWrite(2, LOW);
delayMicroseconds(50);
}
while (!Serial && (millis() < 5000)) ; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB Host Testing - Serial");
myusb.begin();
// Serial1.begin(115200); // We will echo stuff Through Serial1...
}
void loop()
{
digitalWrite(13, !digitalRead(13));
myusb.Task();
// Print out information about different devices.
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;
const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
// If this is a new Serial device.
if (drivers[i] == &userial) {
// Lets try first outputting something to our USerial to see if it will go out...
userial.begin(baud);
}
}
}
}
while (userial.available()) { // from usb device to ??
// Serial.println("USerial Available");
Serial.write(userial.read());
}
while (Serial.available()) { // from host to usb device
// Serial.println("USerial Available");
userial.write(Serial.read());
}
}