-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USB Host Shield Mini, not reconnecting. #593
Comments
Did you remember to cut the VBUS jumper? |
You can see the cut on the picture above. that is how I did it. My board is exactly the same as the one in the picture. I did cut it where indicated. No jumper, just cut the track. If I hadn't cut it, the MAX chip would be already destroyed :) |
Sorry I missed the picture! What devices are you trying to use? Please also enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging, so it gives me more information on what is going on. |
Before I do anything else, please watch this little video I have made showing the problem. |
Adding a VBUS power switch migth solve the problem: https://chome.nerpa.tech/mcu/vbus-power-control-on-usb-host-shield/. |
That link gives me this error 502 Bad Gateway |
Funny, just checked again, and only that commercial device seems to trigger that problem. If I connect my other devices that I built myself, an midi to USB converter (device) and my DIY guitar effect switcher, it seems to work ok.. Could it be that Boss ME-80 have a pullup on another USB data pin? I read that older equipment and newer equipment might be detected in different ways. But if i reboot the shield, the Boss device is detected. Weird. |
Weird. Can you try again?
The shield should work with both low and full speed devices, so that should not be the issue. Regarding the pull up resistor on D+ and D-, then it is simply used to identify a low and full speed device. You can read more about it here: https://www.beyondlogic.org/usbnutshell/usb2.shtml. |
Still get the same "502 Bad Gateway" error. But thank you anyway. The shield does work, the problem is that with the Boss pedalboard if I disconnect it, it doesn't connect to it anymore unless I reboot it. This thing can send Audio over USB and MIDI. I am using MIDI at the moment. |
Some devices only support high-speed USB, see if adding a powered hub solves the problem. The hub will translate full-speed to high-speed. This trick also works for super-speed only devices. |
I didn't even know we could connect a hub with more devices to this shield :) |
Yes it's super easy. Just add this to your sketch: #include <usbhub.h>
USBHub Hub1(&Usb); |
Ahh, ok thanks. So, that will allow a Hub, and I could connect several devices to it, right? Or that Hub1 is just for one extra device connected to the Hub.. Sorry if it is a stupid question but I am a beginner in coding and certainly this USB stuff is new to me :) |
Most hubs support 4 devices. Note a 7 port hub usually have two hub ICs inside where one of the downstream ports of the first IC is connected to the upstream port of the second hub, but you can simply just create two instances and the library will take care of the rest: USBHub Hub1(&Usb);
USBHub Hub2(&Usb); You can simply repeat that for as many as you need. |
Cool, thank you so much.. Will try it tomorrow. Will then report. |
Hi, question, do i need to add some more code? because i added this to the sketch and it is still not passing data on the Hub. I have: /*
*******************************************************************************
* Legacy Serial MIDI and USB Host bidirectional converter
* Copyright (C) 2013-2020 Yuuichi Akagawa
*
* for use with Arduino MIDI library
* https://github.com/FortySevenEffects/arduino_midi_library/
*
* Note:
* - If you want use with Leonardo, you must choose Arduino MIDI library v4.0 or higher.
* - This is sample program. Do not expect perfect behavior.
*******************************************************************************
*/
#include <MIDI.h>
#include <usbh_midi.h>
#include <usbhub.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
//Arduino MIDI library v4.2 compatibility
#ifdef MIDI_CREATE_DEFAULT_INSTANCE
MIDI_CREATE_DEFAULT_INSTANCE();
#endif
#ifdef USBCON
#define _MIDI_SERIAL_PORT Serial1
#else
#define _MIDI_SERIAL_PORT Serial
#endif
// Set to 1 if you want to wait for the Serial MIDI transmission to complete.
// For more information, see https://github.com/felis/USB_Host_Shield_2.0/issues/570
#define ENABLE_MIDI_SERIAL_FLUSH 0
//////////////////////////
// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX
//////////////////////////
USB Usb;
USBH_MIDI Midi(&Usb);
USBHub Hub1(&Usb);
void MIDI_poll();
//If you want handle System Exclusive message, enable this #define otherwise comment out it.
#define USBH_MIDI_SYSEX_ENABLE
#ifdef USBH_MIDI_SYSEX_ENABLE
//SysEx:
void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) {
Midi.SendSysEx(sysexmsg, sizeofsysex);
}
#endif
/*
void myClock(void)
{
}
*/
void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.turnThruOff();
// MIDI.setHandleClock(myClock);
#ifdef USBH_MIDI_SYSEX_ENABLE
MIDI.setHandleSystemExclusive(handle_sysex);
#endif
if (Usb.Init() == -1) {
while (1); //halt
}//if (Usb.Init() == -1...
delay( 200 );
}
void loop()
{
uint8_t msg[4];
Usb.Task();
if ( Midi ) {
MIDI_poll();
if (MIDI.read()) {
msg[0] = MIDI.getType();
switch (msg[0]) {
case midi::ActiveSensing :
break;
case midi::SystemExclusive :
//SysEx is handled by event.
break;
default :
if( msg[0] < 0xf0 ){
msg[0] |= MIDI.getChannel() -1;
}
msg[1] = MIDI.getData1();
msg[2] = MIDI.getData2();
Midi.SendData(msg, 0);
break;
}
}
}
}
// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
uint8_t size;
#ifdef USBH_MIDI_SYSEX_ENABLE
uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
uint8_t rcode = 0; //return code
uint16_t rcvd;
uint8_t readPtr = 0;
rcode = Midi.RecvData( &rcvd, recvBuf);
//data check
if (rcode != 0) return;
if ( recvBuf[0] == 0 && recvBuf[1] == 0 && recvBuf[2] == 0 && recvBuf[3] == 0 ) {
return ;
}
uint8_t *p = recvBuf;
while (readPtr < MIDI_EVENT_PACKET_SIZE) {
if (*p == 0 && *(p + 1) == 0) break; //data end
uint8_t outbuf[3];
uint8_t rc = Midi.extractSysExData(p, outbuf);
if ( rc == 0 ) {
p++;
size = Midi.lookupMsgSize(*p);
_MIDI_SERIAL_PORT.write(p, size);
p += 3;
} else {
_MIDI_SERIAL_PORT.write(outbuf, rc);
p += 4;
}
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
readPtr += 4;
}
#else
uint8_t outBuf[3];
do {
if ( (size = Midi.RecvData(outBuf)) > 0 ) {
//MIDI Output
_MIDI_SERIAL_PORT.write(outBuf, size);
#if ENABLE_MIDI_SERIAL_FLUSH
_MIDI_SERIAL_PORT.flush();
#endif
}
} while (size > 0);
#endif
} |
Powered hub may be required. |
ok, let me see if I find a power supply that fits this old hub. I do have a another hub but it has a different connector and i don't have an adapter for it :( |
No, it doesn't work even with it powered. Is the code I posted above ok? Should it just work like that? |
Forgot to say, when I insert the device connector in the hub slot, the corresponding LED turns ON. So, it seems it might be detected, but there is no data flowing as far as I can see |
|
It doesn't work.. At least with the hub I have.. Does it have to be some special sort of hub? |
No any hub should be supported. @jhsa can you try the following example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/hub_demo/hub_demo.ino? |
Sure. But it doesn't compile. It seems some file is missing. The error is: pgmstrings.h: No such file or directory EDIT: I have jut created the pgmstrings.h file from github, and saved it in the sketch directory. It compiled now. |
I guess you want to see the output from the IDE Monitor.
|
And, what does the monitor output mean? |
I tested bidirectional_converter via HUB. It's working fine.
I don't know why it doesn't work in your environment. |
Hi, thanks for your help.. I updated the library to the latest, flashed the code you linked above, uncommented line 47, the HUB is recognized as before, but it doesn't pass data to the USB MIDI adapter or to my guitar effect board. Both work when connected directly to the Host bidirectional converter. Just not through the hub. Need to find another Hub to test. This one might be too old. It does work when connected to a PC though.. |
USB hubs are "dumb" devices, and simply pass along the data. The only problems I have run into with hubs on UHS2 are: |
Hi, the HUB I have works fine directly connected to the computer. |
So basically, from what I'm understanding here, you are attempting to send messages FROM serial TO midi1 and midi2, correct? |
Basically, I need to know what is routing to where. |
Yes, I am doing a bidirectional converter with a Hub. Please have a look at the bidirectional converter example. so, from USB to serial, and from serial to USB. Both directions. |
Ok, well, with a bit of parsing, I think I can get this to do what you want. |
Appendix D is probably what you really need to look at too. |
I believe I am trying to use Midi 1.0 The old type midi. This is also what the midi library uses, right? |
I think the 1st byte has the status and the channel number, and then another 2 bytes are the data bytes. |
yeah, so, should be easy to do. |
Yes, thank you.. the bidirectional one.. |
Nope, this should be pretty easy. (for me anyway) |
Yeah, for you.. definitely not for me.... yet. Still on the steep side of the learning curve.. And I really appreciate your help. thank you. |
Right, hence not exactly doable with this particular library. EMAIL me, I have an idea. |
Done, I hope i got the right email address. |
Yup! we can discuss options there. |
Make sure my email didn't end up in your spam, whitelist it. ;-) |
I found a NAK issue when sending to a slow device. It may not be the same as your problem. If you want to retry when NAK is returned, you need to set "bmNakPower". USB_Host_Shield_2.0/usbh_midi.cpp Lines 119 to 125 in 37c7c51
However, one slow device gets in the way and impacts performance. |
... Or you could retry on your own, which wouldn't, because you could service the other devices. |
Yes, I have seen both problems from both videos.. When it fails, data start being one step behind, just like on your first video. |
Ahh, wait, just need to add one line to .cpp ? Will do and test.. Then report. |
Yes. Add a line after line 124 in usbh_midi.cpp. |
Nope, that didn't fix the problem. As long as I send so´me midi with a note on or control change to my DIY controller, it starts staying one message behind. |
Has the original issue here (reconnecting the USB device without rebooting the Arduino) been solved, and if so, how? Also it would be helpful to know how and why a VBUS power switch would solve that issue. |
Because it limits the inrush current. |
#653 might fix this issue. |
Was this already added to the library? |
@jhsa no not yet. It would help out a lot if you could download the code here: https://github.com/tmk/USB_Host_Shield_2.0/archive/refs/heads/upstream_fix_busprobe.zip and report back if it solves the issue. |
Thanks. This is the complete library that should replace the original, right? |
Ok, quick test. removing and reconnecting a device seems to be working, at least with my setup. I didn't use it for a while due to other problems and had a couple problems to make it work. bad connections on the breadboard, etc. |
I had this problem with arduino uno and USB Host Shield 2.0 and found the fix here In fact, the hangs every time I touch D7 |
I have built my unit and put it in an enclosure. The fix provided above by Lauszus seemed to have done the trick. |
Hi, If I disconnect the USB device from the shield and reconnect, or connect another USB device, most of the times I don't get a connection unless I reboot the Arduino and Shield assembly. Here is a picture of how I connected an Arduino Pro-Mini 8Mhz at 3.3V to the shield. the green numbers are the Arduino Pins.
Any ideas why this would happen?
Thank you very much for your help...
The text was updated successfully, but these errors were encountered: