felis / USB_Host_Shield_2.0

Revision 2.0 of USB Host Library for Arduino.
https://chome.nerpa.tech
1.8k stars 779 forks source link

Usb.Init() failed with Arduino Uno (but it worked before) #549

Closed ashih42 closed 4 years ago

ashih42 commented 4 years ago

Hello,

I have used the USB Host Shield successfully on several MIDI projects before, using the shield to read MIDI messages from my electric piano and using Arduino Uno to do various I/O operations.

I recently revisited these projects, updated this Shield library to the latest version, updated my code, and now nothing worked. After trying with multiple Unos, Shields, and MIDI sources (I first turned on my MIDI source device, connected it with USB cable to the Shield, and then turned on the Arduino Uno.), I found that Usb.Init() failed every time.

This minimal example uses only the Arduino Uno, Shield, and power from USB connection to laptop. I adapted the example code Arduino IDE in File > Examples > USB Host Shield Library 2.0 > USBH_MIDI > USB_MIDI_converter as shown below. In the serial monitor, I saw Usb.Init() failed, and I'm stuck in the loop.

#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>

USB Usb;
USBH_MIDI Midi(&Usb);

void setup() {
  Serial.begin(115200);

  if (Usb.Init() == -1) {
    Serial.write("INIT FAILED \n");
    while (1); //halt
  }
  delay( 200 );
}

void loop() {}

Rewriting setup() as a retry loop didn't help either. Usb.Init() just kept failing in a loop.

void setup() {
  Serial.begin(115200);

  while (Usb.Init() == -1) {
    Serial.write("INIT FAILED \n");
    delay(200);
  }
}

I appreciate it if anyone has any advice or suggestion. Thank you for your time and consideration.

ashih42 commented 4 years ago

I found the solution. It turned out all shields I bought recently have unfinished parts that need soldering.

See https://esp8266-notes.blogspot.com/2017/08/defective-arduino-usb-host-shield-boards.html

On each shield, I only had to solder 3 little blobs to connect the Arduino 3.3V, Arduino 5V, and Vbus Pwr 5V (see second picture in the link above), and now Usb.Init() succeeds.