6
\$\begingroup\$

The Android Accessory SDK relies on the accessory having USB host. However, my understanding is that newer versions of Android (3.1, 2.4?) have USB host support in the kernel. And I know many existing Android devices have hardware support for host (most tablets surely, Moto Droid, HTC Droid Incredible, etc.).

So my question is, given an Android device that has USB host, what will be the simplest/cheapest way to interface this with a micro? The first thing that comes to mind is using an FTDI USB->serial chip and a micro with UART. But I don't know if the FTDI drivers can be put on Android devices. Anyway, there's probably a much better solution.

I'd prefer a solution that doesn't require a rooted Android device, but would be interested to hear some of these options too.

\$\endgroup\$
  • \$\begingroup\$ no link right now but I was watching this carefully and they are not planning to make Android support USB OTG or Being a host directly. This means that you really have to use their spec. \$\endgroup\$ – Kortuk Jul 12 '11 at 4:30
  • 1
    \$\begingroup\$ Wow, that is crazy. Why would they not put usb otg/host into the kernel? Aren't tablet owners going to want to be able to use generic accessories? \$\endgroup\$ – Chinasaur Jul 14 '11 at 2:24
  • 1
    \$\begingroup\$ Now I'm confused. The Android 3.1 API says explicitly that it supports interaction with both USB accessories (meaning things with host mode) and USB devices (things without host), including things like bulk transport, etc. So isn't this host mode running on the android system? \$\endgroup\$ – Chinasaur Jul 14 '11 at 2:37
  • 1
    \$\begingroup\$ So it sounds like maybe getting a micro that can emulate a specific kind of USB device may be the easiest way to work with an Android device that has host capability. I don't know much about different standard USB devices; any links for a simple run down of the capabilities of different ones for interacting with the host? \$\endgroup\$ – Chinasaur Jul 16 '11 at 2:34
  • 2
    \$\begingroup\$ @Chinasaur, Here's a list of all USB device classes: usb.org/developers/devclass_docs#approved Most USB micros have example code for HID (keyboard/mouse) and Mass storage. Perhaps you can use these to your advantage. Also, if you can write up an answer summary, it would be much appreciated. I think this info could be helpful to others wanting to go down this road. \$\endgroup\$ – Jon L Jul 29 '11 at 17:00
4
\$\begingroup\$

The cheapest way? Use a µC with USB built in. Many of the pic18 and upwards have this. So do many other makes of µC.

The simplest way? As you already state - convert it to RS-232 at TTL levels with some form of conversion chip like the FTDI.

Yes, there could well be problems with drivers for both solutions, but it is more likely the FTDI will be supported out of the box. However, the first solution has the advantage that you can make the µC look like whatever device you want it to look like.

Oh, and as an aside - some of the high end PICs (eg some pic32 chips) have USB host built in as well. Just thought I'd mention it...

\$\endgroup\$
  • 1
    \$\begingroup\$ Why the down-vote? Some constructive criticism would be nice... \$\endgroup\$ – Majenko Jul 14 '11 at 20:38
4
\$\begingroup\$

I'm no expert on Android but FTDI released an app note detailing how you can build in driver support for their USB to Serial IC's into the android kernel.

I don't know if this is feasible to do on a production phone, or if any phones have this driver already built in (I doubt it). In my opinion, Google has laid out a good specification for Open Accessory which will most likely be available on this generation of Android devices and the next given that they all update to the newer Android OS versions.

In the Open Accessory case, the phone switches over to a device and the accessory is the host. Implementing an embedded USB Host is a bit more complicated than using an FTDI USB to Serial IC but there are some pretty good application-specific micros out there that have hardware support for the USB stack and there are some examples out there of the Open Accessory protocol implemented on some of these micros. Given that the support is already in the OS for Open Accessory (or will be in the near future for all devices), I think this is the way to go.

\$\endgroup\$
  • \$\begingroup\$ Yes, but this is the "old" way predating official support - with the exception of built-in capabilities like keyboards and mice, the Android USB host APIs expect user-mode code contained in individual apps to talk raw USB operations. Conceptually, it's a lot like a desktop app written against libusb, rather than relying on a kernel driver for the peripheral. \$\endgroup\$ – Chris Stratton Jul 22 '14 at 17:31
4
\$\begingroup\$

Update: I switched this over to community wiki

It looks like Android is going to support USB Host in the kernel. Android 3.1 already has this, I think Android 2.4 will have it back ported, and surely Android 4 will have it. Therefore if you have a micro that can emulate an appropriate USB slave device, you should be able to communicate with Android fairly simply and cheaply as long as your Android device is hardware capable of USB Host. Most older devices (e.g. Droid, Droid Inc) are hardware capable, and new devices should be.

I don't know exactly which USB slave devices are easy to interact with from Android (here's a list of existing device types), but surely keyboard (i.e. HID) is an easy one to try.

Edit: The Android USB host APIs are based around the idea of having user-mode code contained within applications make raw USB transfers to peripherals. So instead of the "kernel driver" model, this is the "application understands peripheral details" one - conceptually very similar to desktop programs which use libusb or similar to talk to a peripheral. The exceptions would be HID devices such as keyboards and mice which Android talks to itself and utilizes in the expected fashion to provide input to the system in general. It's also worth noting that (with the exception of a few devices where the vendor has done otherwise) USB mass storage is not implemented by the system, so an app which wants to use such a device has to to implement both file system code and the USB mass storage protocol, against the raw android USB APIs.

There is an AVR library that provides a USB stack: http://fourwalledcubicle.com/LUFA.php. With this you should be able to do keyboard or other device emulation from a USB enabled AVR. Including this in your generic AVR firmware build is not too difficult. As Mihailo points out in the comments, make sure you use an oscillator frequency compatible with USB (8 or 16 MHz). I'm not sure whether it's possible to get this working on standard Arduino hardware.

It looks like the easiest way to approach this may be the new Arduino Leonardo board: http://arduino.cc/blog/2011/09/17/arduino-launches-new-products-in-maker-faire/

I'm sure cheaper/simpler/smaller Leonardo clones will come out soon, or roll your own!

\$\endgroup\$
  • 1
    \$\begingroup\$ ATMega8u2 is the cheapest you can go, ATMega32u4 is like a bigger brother (featured in Leonardo). For a minimal board you literally need 5 passive components to make it working. Also it has a DFU (Device Firmware Upgrade) Bootloader so you just plug it in a USB port for programming - no external programmer required. LUFA comes with lots of example drivers (Keyboard, Mouse, Joystick, ...) and it's dead simple to make and test them (and subsequently tailor them to your needs). Just make sure you use 8 or 16 MHz crystal, otherwise USB won't work. \$\endgroup\$ – Mihailo Sep 20 '11 at 8:31
  • \$\begingroup\$ All great points; thanks! By cheaper I mean an Arduino Leonardo compatible will come out cheaper than the official $20. But of course putting it together yourself is probably cheaper still and as you say pretty straightforward. I edited my answer to reflect some of your points. \$\endgroup\$ – Chinasaur Sep 20 '11 at 9:09
  • \$\begingroup\$ BTW, is this why Arduino is 16MHz? I always thought that was a weird choice... \$\endgroup\$ – Chinasaur Sep 20 '11 at 9:14
  • \$\begingroup\$ Probably it is, I'm not sure, older Arduino (the one I have) had FTDI USB to Serial chip, the newer ones have ATMEGA8U2. I haven't looked at schematics of the new ones, if they are using only one crystal I'd say it is because ATMEGA8U2 requires it. \$\endgroup\$ – Mihailo Sep 20 '11 at 14:33
0
\$\begingroup\$

I am not sure what do you exactly mean by cheap, but I don't think there is any problem using FTDI UART->USB chip like FT232RL or Prolific PL2303.. They're cheap.

Still obviously there are two ways to do this:

  1. Get an MCU with USB support:

Advantages:

A. You won't need any external chip to convert levels or implement any protocol.

Disadvantages:

A. You will need to implement the USB protocol with the Class you need (Like, CDC, HID, etc.) in your firmware all by yourself.

B. You will need to buy a VID and PID if your MCU manufacturer does not allow to use the default VID and PID.

  1. Use FTDI chip:

Advantages:

A. You don't need to implement the protocol. A simple UART communication would be fine.

B. Android supports FTDI perfectly. I am not sure what, "need to install the drivers in Android Phone" means but in my experience the only thing you need to recognize a device in android is VID and PID, which you put into intent-filter of your activity provided that Android and Host both supports the class you want to implement.

Disadvantages:

A. If you can afford the chip, I don't think there are any.

A suggestion:

If your MCU does not do any function (run processes in parallel threads or implements several Interrupt Request Subroutines, have event oriented callbacks or interfaced with too many peripherals) other than USB communication then go for a MCU with USB support otherwise FTDI chip is always better option as it only uses an UART of MCU and does not overload it at all.

\$\endgroup\$
-1
\$\begingroup\$

Have you considered Arduino ADK board? It exploits Google ADK to achieve communication with Android.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks, but the ADK requires the accessory to implement USB Host (thus it's much more expensive than a standard Arduino/micro). The idea of this question is to avoid implementing USB Host. \$\endgroup\$ – Chinasaur Sep 20 '11 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.