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.

62 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

    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.

      1. Michael

        I know this is an old thread, but thought I would ask. Could the system tell the difference if I connect two of the exact same video game controllers to the USB Host Shield via a USB hub or would it just recognize button A and not button A port 1 or button A port 2?

  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.

  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.

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

  6. girindra

    Connecting Teensy 2.0 with Sparkfun’s USB Host Shield
    I’m trying a hardware keylogger project using teensy from…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?


  7. gabriel sosa


  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!

    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?

      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!

        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!

          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!

  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.

    1. Pavol

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


      Did the trick.

  11. chris white

    I’m using a Keyes use host shield by Funduino, but nothing I do seems to work with it. I’m using 2.0 library and mega 2560. Are the pin connection issues or compatability issues that you may be aware of, or do I possibly just have a junk shield? (so far I have found no support for this shield)

    1. Sudar Post author

      Yeah that’s the problem. The library is created by circuits@home for their USH Host Shield, but released it under GPL so that other shield can use it. But they provide support only for their own shield.

      You have two options a) Try to find out if the buyer from whom you bought it has any support. b) Try to run the test program to see if there are any diagnostic message that gets printed.

          1. chris white

            ok new problem, every time i try to upload board test to the arduino, i keep getting one error after another. like “stray \ in program” or “stray # in program”

          2. chris white

            so i got the board test to upload and when i start the serial monitor all i see is random characters… does this mean my shield is junk?

          3. Sudar Post author

            Did you choose the correct baud rate?

            Find out what baud rate is used in the program and use the same in the serial monitor.

    1. Sudar Post author

      From a hardware wise you should be able to connect it, but you may have to write lot of custom code to get everything to work together.

        1. Sudar Post author

          Sorry Dili,

          I am able to understand anything about the shield since the description is not in English.

          Contact the seller of this sheild and ask them whether their sheild supports it or not.

  12. Bryan

    Sudar, this is a great blog, thanks! I have the USB Host Shield from Circuits@home and it’s working fine to do things like read the device descriptor from a USB memory stick.

    My next step is to connect it to a USB port on a Xilinx FPGA board and use my USB host to continually read what the slave on other end is sending (like a console port). I was hoping it would be easy and rather generic, but all the USB host examples I’ve found seem to be quite complex and device-specific.

    Is there an easy way to read what a USB slave is sending, e.g. polling or something? It is a Silicon Image CP2103 Serial to USB converter (as the slave device).

    1. Sudar Post author

      Nice to know that you like my blog.

      I don’t think there is a generic way to read data from USB Slave. But you may have to check with the author of the library to see if there is a way to do it.

  13. Kev

    Trying to get SainSmart USB Host board to work with Uno and so far it has been a total failure. I have tried USB_Host 2 and 3. Tried the jumper and external power tricks mentioned above and I can’t get past usb.init(). The USB_desc sketch returns “OSC did not start. Other sketches yield similar results. I am a software engr. and just dabble with Arduino for fun, but this has not been fun at all. I have used several other shields and hardware successfully, but it seems the USB host boards, libraries, examples etc. are aconvoluted mess. I haven’t found a single place that just explains exactly what to do, step by step with a successful result.

    If anyone could sescribe exactly how to get the USB host shield working properly with a Uno or Due, I would be extremely grateful.

    thanks, Kev

  14. parth

    i use kayes usb host shield with mega…
    i use it to connect PS4 to arduino…
    but everytime i take any input from analog pins(A0 to A6), my PS4 gets disconnect..
    why does this happen everytime?

  15. Brian

    Hello Sudar,
    I just want to start off by saying, I have been reading your blog for quite awhile and have used it numerous times. Thank you very much for doing what you do, it helps me often as I am sure it helps many others.

    For the first time though, I have a question that I cannot find a good answer to.


    I am creating an RFID based system with three readers, 350 tags, five arduino Mega’s , one sainsmart 16 channel relay board, one USB host shield, one barcode reader and one 82 foot long USB extension cable.

    Surprisingly I have everything working except that last part, the extension cable. The extension cable (I can supply more specifics on the cable and on the barcode reader if needed) seems to act as a USB 2.0 Hub. That , I believe is the key problem.

    Problem symptoms:

    When the system is operating nominally the barcode reader scans a barcode, this barcode acts as a conditional statement that changes the logic flow for the program. I have all of that working when the barcode reader is plugged directly into the USB host shield. However, when I plug the reader into the extension cable, and the extension cable into the USB host shield I fail to receive any data from the reader. That is the symptomatic problem.

    My question:

    Can you please help me with getting this to work?


    I know I left a fair amount of specifics out of the post, I can supply you with any thing you need, just let me know.

    Very much looking forward to your response,

    1. Sudar Post author

      I am suspecting two issues

      – Signal loss due to cable length. You can test it out by connecting the cable directly to your PC and see if it is detecting the device.
      – Problem because of USB Hub. Generally being a USB Hub shouldn’t affect anything, but I am not sure whether this is a special type of hub or not.

      1. Brian

        Thank you for your reply,

        The barcode reader works fine when connected through the cable to the computer.

        Below is a link to the extension cable.

        I have run the hub_demo program provided within the USB_host_shield_2.0-master when the cable and reader are connected , the program only detects (or at least outputs) the descriptive data for the cable hub. Unplugging the reader and having just the Cable connected yields the same result. Having just the reader connected the program outputs the readers description.

        Thank you again for your continued support,

        1. Sudar Post author

          Looks like either the hub in your cable is non-standard or the USB Host Shield library does not support the hub.

          USB debugging is very difficult. If you have the time (and skill) you can try to debug it by just running the hub program. Otherwise I would suggest you just use a cable which has no hub support.

  16. Patrick

    can I connect two ARDUINO with USB
    1x ARDUINO with a USB Host Shield and the other without USB Host Shield
    I want to comunicate from one to the next with ARDUINO SERIAL.READ and SERIAL.WRITE
    I need example
    greeting Pam

  17. Balien

    TRENDnet’s USB 3.0 to Gigabit Adapter + USB Hub, type TU3-ETGH3, builds a Gigabit Ethernet slot and also 3 five Gbps Super high Speed USB 3.0 jacks to a Windows® or even Mac® PC.

    The TU3- ETGH3 is usually suitable with USB two and also one jacks. An enclosed additional electrical energy adapter delivers complete energy to energy greedy USB equipments.


Leave a Reply

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