Loading...

Got a Mega ADK in your hands and can’t wait to use it? Not interested in the project’s history? Visit the step by step tutorial and start playing with your Arduino board, Processing, and your Android device.

This page gives background on Android’s Accessory Development Kit and the Arduino Mega ADK, which was designed to work with Android. If you’re not familiar with the Android ADK and what development tools are available, read on.

Description

The Arduino ADK is a combination of hardware and software designed to help people interested in designing accessories for Android devices.

During Google’s 2011 IO keynote [1], Google introduced a board [2] based on the Arduino Mega 2560 which includes this USB host. A new USB library [3] was introduced, enabling data to be sent and received from any external devices. This library is included with the latest version of the Android OS. Any devices with OS 3.1 and later can use the USB port to connect to accessories. App makers can freely use it in their development. This library has been included in 2.3.4, and some devices have been reported to work with 2.3.3.

About the Mega ADK board

The Mega ADK board is a derivative of the Arduino Mega 2560. The modified Mega 2560 board includes a USB host chip. This host chip allows any USB device to connect to the Arduino.

Arduino Mega ADK board (note the board in the picture is a prototype)

The USB host is not part of the original core of Arduino. To use the new features on this board you will need to include some libraries in your sketches.

There are three libraries needed to make the system work:

  • MAX3421e: handles the USB host chip
  • Usb: handles the USB communication
  • Android Accessory: checks if the device connecting is one of the available accessory-enabled phones

The first two come bundled together into a single folder. The Android Accessory is separate. This way you can write your own high-level libraries for connecting to other devices.

Android Accessories: what are those?

An Android accessory is a physical accessory that can be attached to your Android device. These particular devices perform specific actions. With an Android phone and the Mega ADK, you can use whatever sensors and actuators you require to create your own accessories.

The USB accessory and the device check to make sure they are connected by passing back and forth product and vendor IDs. Google offers two accessory codes for people to try out: product IDs 0×2D00 and 0×2D01. Google has the USB vendor ID 0×1841 [4].

When a user connects the USB accessory, the device is told which application to launch. This wakes the device from sleep, and happens automatically.

Available Software Tools

The typical toolchain for an Android developer consists of Eclipse and the Android SDK. We have been working to make things easier by using Processing [5] as the main prototyping software for Android applications. This Processing for Android USB library can be found on the Arduino github repository

Arduino IDE 1.0 beta Release Candidate

Arduino’s software is based on Processing’s IDE. The current release is version 0022. The Mega ADK has been developed as part of The 1.0 beta release. The libraries needed to make an Android accessory using the USB host chip are not included as part of version 0022, so you’ll need the 1.0 beta to work with the ADK and Android.

There are some fundamental changes in the way version 1.0 works, including a new extension for sketches. The suffix will change from *.pde to *.ino, any previous sketches will need to re-saved with the new extension. The Getting Started section has a link to the software. Version 1.0 is still under development, so there will be more changes to come.

Android SDK

The Android OS is based on Linux. Android Apps are made in a Java-like language running on a virtual machine called Dalvik [6] created by Google.

Android offers a single download location to get the development software used by the different hardware manufacturers. This helps streamline development for different devices. You can get the Android SDK from the Android development website. You can easily upgrade to newer versions of the OS.

Google controls the main branch of the Android development system. They produce the core and the libraries that link the virtual machine with different peripherals.

If you’re going to make a commercially-sold accessory, it is your responsibility to:

  • port their drivers to each new version of the OS
  • create a ROM (functional image memory of a phone) that is compatible with that version of the OS
  • provide the developer’s community with a port of their drivers via the SDK upgrade system

The manufacturers are not always ready with ports the same time Google introduces a new revision of the OS. This has created an interesting parallel ROM development community dedicated to the creation of ROMs that include all the latest features yet capable of running on older devices. One of the most successful mods is Cyanogen [7].

For USB accessories to be supported on a particular device, there must be support for the accessory-mode, a special means of connecting over the USB port. This allows data transfer between devices and external peripherals. Accessory mode is a feature of Android OS since version 2.3.4 Gingerbread and 3.1 Honeycomb.

The examples in this guide are made for Android Gingerbread and have been successfully tested on Nexus S and Nexus One handsets. Some people [8] [9] have reported to get Google’s Demokit example [10] working with other phones and with hardware other than Google’s ADK board.

Android ADK

Google’s Accesspry Development Kit (ADK)[11] is Google’s derivative of the Arduino Mega 2560 with:

  • a shield including sensors, LEDs and actuators
  • the source for an App called Demokit that can show the information coming from the sensors on the shield
  • an Arduino sketch

Since they introduced the Demokit at the May 2011 Google IO, different manufacturers have been creating boards that are compatible with the one made by Google.

The intended use is the creation of new peripherals to phones. It is meant for:

  • prototyping new devices
  • learning about hardware that could benefit from having a device as a gateway to the internet
  • using the phone as interface to -almost- everything
  • using phones as the “brains” of other machines

Eclipse + Android Plugin

Google suggests programming with the ADK using Eclipse and the Android SDK, together with Arduino’s IDE.

Eclipse [12] is a multi-platform development environment. It performs operations like code prediction, error correction, project storage, and multiple workspace management.

To develop Android applications, the ADT (Android Development Tools) plugin is needed on top of Eclipse. The ADT links Eclipse with the Android SDK toolchain [13]

In these guides, we will be using Processing, not Eclipse, for App development.

Processing + Arduino ADK Plugin

Arduino is a daughter project of Processing [14]. Processing is designed as an easy gateway into programming. As of version 1.5, it allows you to compile and run code directly on an Android device.

To use the Mega ADK you need to install a plugin for Processing called Arduino ADK. This plugin will make sure the right libraries and xml files are included in the compilation of your code, and send the program to your device.

Your Processing sketches must also include a new library that enables communication between the device and accessory over the USB port.

Handbag

Since the Android ADK announcement a series of developers and companies have been producing research material and prototyping tools. One of Arduino’s developers, Follower, has created a tool for developing new accessories that don’t require very specialized UIs.

His approach, named Handbag [15], enables accessories to dynamically update a series of premade UI components.

This is for Arduino users who are not interested in learning the Android development environment but are still interested in creating objects that could easily be controlled from a phone.

What has been developed here?

We have developed some tools and examples for you to learn how to use Arduino boards connected to Android devices.

  • a tool for Processing to compile code for the latest Android OS and upload it to phones
  • a series of basic examples for sending data from the phone to the board and vice-versa
  • a series of libraries that simplify the code for an Arduino
  • a library that simplifies the the code for Processing, which manages communication via the usb port

Known Issues

The Processing and Android Java libraries might not work on your phone. USB devices need to have a registered vendor ID, and the USB port is handled differently in different devices. You might need to wait until the phone manufacturer brings its own release of the USB development library.

Google has partially solved this is by providing a “usb.jar” file as part of the Google Inc. version 10 development package for the Android SDK. The software works on officially updated Nexus S and Nexus One handsets, and the Samsung Galaxy 10.1 tablet. It has also been reported to work on modded phones and some tablets.

People

Andreas Göransson: coded the USB library on the Android side, prepared the basic examples both on the Arduino and the Processing side. Andreas works for 1scale1 and Malmo University

David Cuartielles: coded the Processing tool needed to launch the compilation process for phones. Defined the basic examples and wrote the initial version of the documentation. David is one of the co-founders of the Arduino project

Tom Igoe: sketched the USB library and suggested the way the libraries should be structured. Tom is one of the co-founders of the Arduino project

Dave Mellis: coded the USB library on the Arduino side. Dave is one of the co-founders of the Arduino project

Shawn Van Every: provided valuable testing and debugging help on the Processing library and helped sketch out the API structure. Shawn is a mobile media technology consultant and the author of Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets

Gianluca Martino: designed the Mega ADK board. Gianluca is one of the co-founders of the Arduino project

Mads Hobye: contributed creating the code for the AD strategy. Mads is co-founder of Illutron

Benjamin Weber: contributed creating the code for the AD strategy. Benjamin was artist in residence at Illutron during the summer 2011. Find more about him at bw.nu

Brian Jepson: made an elegant patch that helped the Processing Tool to compile for v2 of Processing’s IDE. You can finr more about Brian at jepstone.net

Phillip aka Follower: has fixed the Arduino libraries (USB Host and ADK Accessory) to work with Arduino 1.0 after the update to the Arduino core that affected the Print functions. Phillip makes a lot of contributions to the Open Source community, follow him at rancidbacon.com