Using USB Host Shield with Arduino

USB Host Shield

There is a huge variety of shields that are available which can be stacked on top of an Arduino. Often there are more than one manufacturer for a single type of shield itself. In a way this is good, because as a user you are going to have multiple options. But it becomes a problem when the shield is pretty complex (like the USB Host Shield) and you have to use a library and the shields are not compatible with each other. One such shield which has many incompatible versions is USB Host Shield and in this post I am going to tell you how you can select the proper shield and also the changes that you have to do to make even the incompatible shields work with the library.

What is an USB Host Shield?

Before we start, let’s first understand what is an USB Host Shield. It is a shield which provides USB Host support for Arduino.

So, what is USB Host support? The USB protocol defines two types of devices. One is called the host (or server) and the other one is called peripheral (client). The Host device controls the peripheral device and also provides power to it. When you connect any USB device like a mouse or a keyboard to your computer, your computer acts as the host and controls (or polls) the client device (keyboard or mouse or even an Arduino). For a successful communication to happen using USB protocol, you need at least one of the device to be the host, which means that you cannot connect two keyboards together and expect them to communicate with each other.

The USB Host shield has a separate chip (usually Max3421E), which provides USB Host support. Once you have this shield, your Arduino board can act as USB Host and you can connect other USB devices like keyboard, mouse or even an Android phone and communicate with the device from Arduino itself.

What you can build using USB Host Shield

USB Host shield can be used to interface any USB device to Arduino. The following are examples which I have built using the shield.

Available Hardware Options

The following are the various versions of USB Host Shields from different manufacturers.

Available Software Libraries

The following are the two libraries that are available for USB Host Shield. Both of them are from Oleg of Circuits @ Home.

  • USB Host Library v1.0
  • USB Host Library v2.0

Out of these two, the v1.0 of the library is kind of deprecated. Use it only if you really need to or have to use some other library that depends on it, otherwise use only v2.0.

Selecting the right shield

If you have not bought the shield yet, then just go ahead and buy the shield from Circuits @ Home and use v2.0 of the library. The library works out of the box and you don’t need to modify anything.

But if you have already bought the shield from Sparkfun, especially the old (like me) then read the next section to find out the changes that you have to do to the library to make it work with the shield.

Making the Sparkfun shields work

Choose the instructions from the right section below based on your shield and library version.

Old Sparkfun shield (part no: DEV-09628) with v1.0 of the library

The old sparkfun shield has two issues. First, the GPX and RESET pins are swapped and the second it has power issues.

To solve the first issue, you have to make the following change on line number 24 of the max3421e_constants.h file in the library.

Alternatively if you are using my makefile to compile Arduino sketches (more about it in a separate blog post soon), then you can grab my fork of the library and add the SPARKFUN_9628_SHIELD define to your makefile.

To address the second issue, you have to add an external power source to the shield like a battery or wall adapter, even if you have connected the Arduino through USB cable.

Old Sparkfun shield (part no: DEV-09628) with v2.0 of the library

In v2.0 of the library the communication happens over the SPI pins and therefore you don’t have to make any change to the library. But to fix the swapped pin use you have to short the pin D7 to RESET. Take a small jumper cable and connect one end of it to D7 pin and the other end to the RESET pin (next to the 3.3V pin). This is the only change that is needed to get v2.0 of the library to work.

In addition to that you should also use an external power supply.

New Sparkfun shield (part no: DEV-09947)

The new Sparkfun shield has fixed the swapped pin issue, but it still has power issue. So to use this shield with both v1.0 and v2.0 of the library, you don’t have to make any changes to the library, but you should still connect the external power source.

Related boards

The following are some of the boards that also provide USB Host support.

25 thoughts on “Using USB Host Shield with Arduino

  1. Pingback: Controlling USB Missile Launchers using Arduino | Hardware Fun

  2. Shashank Khanna

    Can we use two usb host shields with an arduino??I actually want to transfer data from one usb drive to another..please help

    Reply
    1. Sudar Post author

      You can’t use two USB Host Shield with a single Arduino. Instead you can connect a USB Hub to your USB Host Shield and can connect up to 64 devices.

      Reply
  3. Pingback: Accessing GPIO pins of Max 3421 IC in USB Host ShieldHardware Fun | Hardware Fun

    1. Praveen

      Hi abhijit,
      Are you able to connect bhashatech shield with usb shield?
      I am also trying to do it but could not succeed.

      Reply
  4. Developer

    Did any one try to connect usb ethernet network lan adapter to usb host shield?
    I’m working on this.
    In this case no need for Ethernet shield and saving money.
    Regards.

    Reply
  5. vatsal

    Can anyone please provide me with a code and connection diagram to transfer data to and from into a pendrive using usb host shield and a leonardo board??

    Reply
  6. girindra

    Connecting Teensy 2.0 with Sparkfun’s USB Host Shield
    I’m trying a hardware keylogger project using teensy from http://www.irongeek.com/i.php?page=s…eylogger-phukd
    it is stated that i can’t connect my keyboard -> teensy -> computer directly because teensy needs to act as a USB host for the keyboard.

    I can’t find the USB host from the site, so I had a Sparkfun USB host shield instead.
    So, I connected the Teensy, micro-SD card adapter module, and sparkfun’s USB host shield like the [left] picture, with wiring like the [right] picture

    in details, I connected the micro-sd adapter to SPI pins 0-3 on teensy, and the USB host adapter to Tx & Rx pins 7-8.
    you can see the green cable on the [left] picture is Rx of teensy -> Tx of USB Host
    and the yellow cable is Tx from teensy -> Rx of USB Host
    the twisted Red and Black cable are the +5V and GND
    (in short, i followed the guidelines from the [right] picture)

    with this configuration, the micro-SD card adapter works fine, as i can access it from my computer, but the keyboard connected through the USB adapter isn’t detected.
    Anyone can help to point out of what I did wrong? any solutions to my problem?

    -Thanks!

    Reply
  7. gabriel sosa

    HI I WANT TO CONECT THE ARDUINO TO A PRINTER ZEBRA, USING THE USB HOST SHIELD, BUT I DONT KNOW HOW TO USE OR MAYBE IF THAT CAN BE USED, I HAVE THE CODE TO PRINT, BUT HOW DID I CAN SEND THIS IN THE USB HOST, PLEASE HELP!!!!

    Reply
  8. Jônas

    Hello, I need help,

    I have a USB Host shield from Sparkfun (new version) and I have to make it work with an Arduino Mega 2560, but still not getting success.
    I’ve done some tests like: connect D7 to reset, making connections SPI pins according to the mega, I used an external power supply, but nothing made ​​it work properly.
    Use version 2 of the Circuits @ Home library.

    ‘ve Got errors like:
    “Error: OSC Did Not Start”! (USB_desc)

    “Error: failed to assert OSCOKIRQ
    Circuits At Home 2010
    USB Host Shield QC test routine
    Press any key to continue …
    Reading REVISION register … Die revision invalid. Value returned: FF
    Test FAILED!!!
    Test Halted.
    0x55 pattern is being Transmitted via SPI to aid in troubleshooting
    Press RESET to restart test “! (Board_qc)

    I appreciate the attention and the help!

    Note .: I’m Brazilian, and I used the Google translator to translate this text!

    Reply
    1. Sudar Post author

      Hello Jonas,

      This sounds like a hardware problem to me. Do you have any other shield which you can test on?

      Also did you contact Sparkfun support?

      Reply
      1. Jônas

        Thanks for the reply!

        I am also suspecting that this is the problem!
        I have no Shield. And unfortunately I can not count on support from Sparkfun because the shield was purchased at a local retailer!

        I will continue trying to solve the problem!

        Thanks for listening!

        Note .: I’m Brazilian, and I used the Google translator to translate this text!

        Reply
        1. Jônas

          Hello, I’m here again,

          I made new tests with the sparkfun usb host shield with Arduino Mega 2560, and am now getting the board_qc the the following message:

          Circuits At Home 2011
          USB Host Shield Quality Control Routine
          Reading REVISION register … Die revision 03
          SPI long test. Transfers 1MB of data. Each dot is 64K ……………. SPI long test passed
          GPIO test. Connect to GPIN0 GPOUT7, GPIN1 to GPOUT6, and so on
          Test failed. Value written: 00 Value read: FF
          Press any key to continue …

          I do not know what to do !!!

          I appreciate the help!

          Note.: I’m Brazilian, and I used the Google translator to translate this text!

          Reply
          1. Sudar Post author

            What happens after this?

            GIPO test will fail because you would not have connected the GPIO pins. But does the other tests pass?

  9. Jônas

    Then I did a test with a mouse using the USB_desc example and it worked correctly.
    Then I did the tests with the barcode reader (which was what I wanted to do) and it worked correctly.

    My solution:

    Make a jumper between reset pin and pin 7.
    Make jumper between pins of SPI shield with the SPI pins of Mega 2560 (​​50, 51, ​​52, 53):

    10 > 53 (SS)
    11 > 51 (MOSI)
    12 > 50 (MISO)
    13 > 52 (SCK)

    That was my solution!

    I appreciate the help and attention, his contribution was very important to solve this problem!

    Reply
  10. Pavol

    Hello Sudar,

    I am using Arduino Due + USB Host Shield + official Ethernet shield.
    They use both SS at pin 10, so I have moved it on USB Host Shield to pin 7, updated the UsbCore.h. too and verified if working. So the USB shield uses now pin 7 for SS and it works.

    Ethernet shield was not modifed and so it should use Pin 10.
    It really works perfectly = ethernet shield is able to send/receive data, but only until Usb.Init() is called.
    It means, both devices work when connected to Arduino, but Ethernet shield doesn’t work after USB initialization.

    May I ask you for any advice?
    According to research I did on internet, what I did should have been sufficient.

    Reply
    1. Pavol

      Seems I have solved the problem:
      Before ethernet initialization it is necessary specifically require SPI for Ethernet shield.

      pinMode(10,OUTPUT);
      digitalWrite(10,LOW);

      Did the trick.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>