- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content
The Open Accessory API and USB On The Go
Ever since Google announced its Open Accessory APIs for Android at Google I/O, I've been keen to learn more about the implementation. Google I/O had a supercharged marketing rollout for the Open Accessory API, and they gave all attendees at the announcement talk a cardboard tube containing an Arduino board kit. The kit contains the hardware to experiment with the Open Accessory API. The Open Accessory Library lets you (your equipment) talk to your Android phone over USB. A recent post on the Android blog provides more details, and there's a good analysis of the Google kit by our friends over at FunnyRobotics.
[Note added10/11/2011 - here's another source of ADK info http://labs.arduino.cc/ADK/Index ].
The Open Accessory API Development Kit from Google IO, 2011
It's early days, but the most-frequently executed project so far is "stepper-motorize a droidbug controlled by a phone or tablet over USB, and film it dancing". Which, I have to say, is pretty neat.
Basics of the USB Protocol
More than 11 billion USB devices have been sold to date, which means there are roughly 1.5 USB devices for every man, woman, and child on the planet. (And, at any time, about 1% of them are laying in tangled piles on my desk). USB - the Universal Serial Bus - in all its forms and iterations, is the greatest success story of external peripheral connection in the history of computers. Bite on that, Bluetooth!
USB was developed about 16 years ago by PC manufacturers working together. They realized that the old RS232 serial port, first developed by the Romans (OK, I'm not certain about that), needed to be replaced, and relocated to somewhere handier than the dusty back panel of a PC. USB succeeded brilliantly, and has enjoyed 3 major iterations so far. USB 3.0 today offers speeds up to an incredible 5 Gbit/sec, which is faster than FireWire (Apple's alternative solution).
Every piece of equipment with a USB port is either a "USB host" or a "USB device".
- USB hosts are required to supply power to other devices on the bus, and they control all the traffic over the bus. USB hosts are things like your PC. There is exactly one host on the bus, and it keeps track of everything else, through a process called "enumerating the bus" (inviting all devices to state their presence and capabilities).
- USB devices don't do any processing; they just hand over their data when a USB host tells them to. USB devices includes equipment like cameras, flash drives, mice, and foam missile launchers. (There are several open source projects to control those USB foam missile launchers!)
The USB protocol requires a USB host at one end of the cable, and a USB device at the other end. The USB host controls all the USB devices and tells them when to put their data on the bus. Hosts can't talk to other hosts, and devices can't talk to other devices. The interaction is always between a USB host and one or more USB devices.
Is an Android Handset a USB Host or a USB Device?
The question arises whether Android handsets are USB hosts or USB devices? Handsets are like USB hosts because they have the processing power to be a bus master, and you'd like to connect them to your camera or USB keyboard. But handsets are also like USB devices because you'd like to plug them into your PC to develop your apps. A piece of USB-connected equipment has to be either a USB Host, or a USB device. It cannot be both. Up until recently, that was the end of the story. We'll come back to that at the end of the article.
The convention throughout the industry is that smartphones are deemed to be USB devices. That makes it easy to connect them to your PC, but it also means they cannot talk to other USB devices (like the keyboard or flash memory). And USB devices cannot initiate a connection, so you can't start an Android app and have it control some other USB device.
Open Accessory API
Recognizing that smartphones are overwhelmingly configured as USB
devices, Google extended the USB protocol slightly, to put a bit more
smartness into the device end, and a bit more enquiry into the host
end. Under Google's Open Accessory API, USB equipment that wants
to interact with an Android phone should be implemented as a USB host -
with something extra. The something extra is a protocol handshake
after the USB cable is plugged in, and identities are exchanged.
The host will send an extra message, asking in effect "BTW, are you a device that supports Android's accessory mode?"
An Android smartphone that supports the Open Accessory API will expect that extra question, and will reply "Yes, I am! LOL!"
When the USB host gets that confirmation, it does some more
handshaking, then tells the smartphone which compatible application to
start. That app will use the Accessory API to allow the phone user
to interact with the USB host hardware on the other end of the USB
cable. But if the USB host hardware doesn't get an answer, the USB host
knows that the smartphone does not support the API and so the smartphone
won't be controlling the USB host. Perhaps the USB host can
itself offer a less capable alternative interface to the user.
In summary, the Open Accessory protocol offers a data path over USB between the phone and the accessory device. It has a Java API on the phone to detect and interact with connected accessories. The Open Accessory API lets you attach a USB host microcontroller and talk to it from Java on the phone.
Hardware Requirements of the Open Accessory API
Google's approach requires hardware to be upgraded, if it wants to connect to a smartphone over USB. The equipment has to become a USB host, which requires some processing power. Not only that, the equipment is obliged to put half an amp of current at 5 Volts on the bus. This is why the accessory development kit that Google handed out at Google IO includes an Arduino board (for the logic) and a plug-in power supply (for the volts).
Control your electric bike from your Android phone? USB hosts can do this!
The logic and power requirements focus the Open Accessory API on higher-end, special-purpose peripherals, like exercise equipment or electrically-assisted vehicles. It has a really great future there. We still need a solution that lets us attach low-end keyboards, printers, and cameras to our smartphones and tablets. Bluetooth is good for some of these, but not for others (most cameras support USB, with only a few supporting bluetooth).
One obvious USB solution would be to build products with two USB ports: one full size USB socket configured as a host, and one micro socket configured as a device. There are practical difficulties with that approach - battery-powered devices don't have the capacity to provide power to the bus for long; smartphones don't have the space for a full size USB socket - it's duplicative and increases the bill of materials and manufacturing cost.
Nonetheless this approach is used (in theory, if not in practice) by some docking stations that support keyboards and flash memory. More about this in the next section. If you ever wondered why you have to plug some docks in to the wall power outlet, it's because they support USB device connection by acting as a USB host. They need to meet the requirement of powering the bus. They have to plug into an electrical outlet to achieve that. Since they have to plug in, they might as well recharge your phone - this makes a virtue of necessity.
USB On The Go Alternative
We still need a solution for low-end devices. That's where USB On The Go comes in! USB OTG is a specification that allows capable USB devices (like tablets and smartphones ) to temporarily switch roles, and become a USB host so they can talk to another device!
USB On The Go took a few years to catch on, but recently tablets have boosted its popularity. When you see Android products advertised as capable of connecting to cameras, keyboards, and mice, it is typically through a docking station or dongle that implements some part of USB On The Go. Motorola offers such a "USB OTG connector cable" product for the XOOM, calling it a "Camera Kit Adapter", so that people unfamiliar with USB protocols won't get confused.
The HD multimedia dock for ATRIX is an example of a powered dock that supports part of the OTG spec. The dock provides the power to the bus, that allows the smartphone to act as a USB host. So you can connect keyboards and USB storage (disks, flash drives) to the ATRIX dock and thus to the ATRIX. The dock power supply has enough capacity to recharge the phone while also powering the USB bus.
What it all boils down to
That's how practical problems of smartphone connectivity were ingeniously solved for an older bus architecture that was not designed with hybrid (sometimes I'm a device/sometimes I'm a host) products in mind.
- The Open Accessory API lets your phone/tablet connect to a USB host built into high-end equipment, and control the equipment from your Android device.
- USB On The Go lets your tablet or dock act like a USB host and connect to low-end USB devices like printers and cameras.
These late adaptions (Open Accessory and OTG) are classic examples of how good engineers can build on a solid foundation. They also demonstrate how software and hardware changes need to be carefully considered, and kept as unintrusive as possible, to be successful.
Peter van der Linden
Android Technology Evangelist, and Fan of Roman Technology
PS. many thanks to colleagues Jim Theisen, Greg Tong, and Greg Wilson who provided many suggestions for improving this article.