Standard Arduino Works With Android Open Accessory  

Posted by technology2day


Standard Arduino Works With Android Open Accessory
A lot of people have been put off by the price of the reference hardware kit, which is roughly $390. What’s worse, they appear to be sold out until end of May, and Microchip’s cheaper ($80) alternative doesn’t arrive until July. So instead of waiting I decided to write a guide on how to get an ADK-capable Arduino for about $55.
Since the ADK reference design is based on Arduino and Oleg Mazurov’s excellent USB host shield, it stands to reason that we should be able to build our own hardware kit from these components. I already had these parts lying around from my work on MicroBridge, so I decided to ‘port’ their code, which in reality means just changing a couple of pin definitions.
disclaimer: Since I don’t have a phone that supports accessory mode I have no way to verify that this actually works. What I can see however is the output from the Arduino which seems to indicate that everything is working as it should be. If anyone has actual Android hardware that supports ADK and would like to help me test this, let me know!
Hardware
In order to replicate this you’ll need two things:
  1. An Arduino board or compatible. You can get an Arduino from places like Sparkfun, although cheaper clones can be had on Ebay for as low as $20.
  2. A USB host shield. You have the choice of either Oleg’s USB host shield, which will run you $40, or Sparkfun’s cheaper variant which sells for $25.
You can either get a ‘regular’ 328p-based Arduino or an Arduino Mega. The higher price of the Mega gives you extra IO pins, which you might actually need since the host shield occupies pins 7-13.
Sparkfun’s shield is cheaper but has some drawbacks. Firstly it does not work with Arduino Mega variants because these boards have their SPI pins in a different location. Oleg’s 2.0 shield solves this by connecting to the ICSP header on the Arduino, which is in the same location on all variants. Second, Sparkfun’s shield requires an external power source to be connected the the Arduino board. Finally, it’s not stackable, which is really annoying when you’re trying to drive servos, motors, and so forth.
Here’s a picture of the setup I use. As you can see, I use Sparkfun’s shield and an Arduino Uno. Note also the external power supply to power the phone. If you get this combo from Sparkfun, it’ll cost you about $55 ex shipping.

Firmware
While the ADK reference software includes Oleg’s USB library, they slightly modified the code, hardcoding the pin assignment to the max3421e chip. Unfortunately this breaks compatibility with the Arduino shields, so I had to patch their code a bit to make it work again. All I really had to do is add some #defines and it worked pretty much out of the box from there.
To try it out for yourself, download the ADK software package and follow the installation instructions on the ADK page. Instead of installing the USB host lib from their package, get the patched version here and copy it into the libraries directory of your Arduino installation. Remove all the stuff from demokit.pde that uses the demo shield (joystick, RGB leds), and you should be good to go.
You should see the following output on the serial port:
Start
Device addressed... Requesting device descriptor.
found possible device. swithcing to serial mode
Data packet error: 5could not read device protocol version

Device addressed... Requesting device descriptor.
found possible device. swithcing to serial mode
Data packet error: 5could not read device protocol version
Et cetera. This means that the electrical wiring to the shield is in working order and the max3421e is finding the phone. The ‘Data packet error: 5′ means that my phone is not responding to the non-standard control request, which it shouldn’t, since it’s not an accessory-capable device (yet).
Conclusions
As far as I can tell following this guide should give you a slightly more economical Android accessory device compared to the reference kit. Until I get my hands on a phone I cannot test it, so if anyone out there has a capable device or knows how to hack support for it onto a rooted ZTE Blade, let me know. When ADK makes it into Cyanogen mod I’ll certainly flash it on one of my blades and let you know how it goes.
Finally, if anyone out there has one of those cool ADK demo kits and wants to lend me one, feel free to contact me. I’d like to port MicroBridge to it so that it can be used it with pre-2.3.4 devices.
update: much thanks to RobotFreak and Follower for confirming that this setup works! Apparently some versions of avr-libc require ‘PORTB1′ instead of ‘PB1′ to compile correctly

This entry was posted on 11:26 PM . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

0 comments