Monthly Archives: September 2012

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.

TI Stellaris LM4F120 LaunchPad available to order

LM4f120xl Stellaris Launchpad

Texas Instruments, low cost evaluation board for the ARM Cortex M4F based microcontrollers is available for ordering now. And can you guess the price? It is just $5. Yes it is just $5 😉

ARM Cortex M4F microcontroller

LM4f120xl Stellaris Launchpad The main highlight of the Stellaris LaunchPad is its microcontroller. The LaunchPad comes with the surface mount LM4F120H5QR microcontroller which has 256KB of flash memory, 32KB of SRAM, 12 ADC ports, up to 43 GPIO ports and a huge list of supported interfaces. You can see the complete list in the LM4F120H5QR chips homepage. The chip also has USB 2.0 device interface and hibernation module and also has a built-in programmer.


TI is selling the LaunchPad at $5 (including international shipping) as a promotional price and you can order it directly from them. They say that it would take around 2-4 weeks to ship it.

I am really excited and waiting to play with it. It is definitely worth waiting for 2-4 weeks for it to ship, especially if the shipping is free and you pay only $5 to buy it 😉

User manual (update)

The user manual for Stellaris Launchpad is also now available.