The examples for the Mega ADK using the board in accessory mode require the following hardware and software:
UsbHost library for Arduino (includes the AndroidAccessory class)
The libraries and tools required for Arduino and Processing can be downloaded in the file ArduinoADK.zip
Uncompress the file and inside the resulting folder ArduinoADK [TODO: Actually ArduinoADK-beta-001 currently] you will find two additional folders:
Arduino
Processing
The instructions below will tell you what to do with their content.
You can get the Android SDK from the Android Development website:
http://developer.android.com/sdk/installing.html
Unless you are planning on using Eclipse as part of your development, you can skip their step 3 of the installation.
Step 4 can be time consuming, you need to include the APIs for Google versions 10 and higher; consider installing everything at once.
This screenshot shows the minimum options you need selected for Android 2.3.4 and 4.0.3 support:

When you start the install you should see a confirmation screen similar to this:

[NOTE: Google seems to have broken the ability to download the needed Google APIs using Java 5 (a.k.a 1.5) —if you don’t see the Google APIs in the available packages list that’s probably why.
To work around this you may need to force the android application to run with Java 6 (a.k.a 1.6). For Mac OS X you can use the Java Preferences application to ensure the correct version of Java is used.
When you start the Java Preferences application it will look something like this (make a note of the exact settings for your computer):

Quit the android application and then temporarily change the Java preferences to deselect all variations of Java 5/1.5:

Then run the android application again to download the SDK.
When you have installed the SDK you should change the Java Preferences settings back to how they were when you started—if you do not change the settings back the Arduino and Processing IDEs or other Java applications may not run correctly.
The bug report for this issue.
TODO: Remove this note when the issue is fixed.]

Processing can normally be obtained from the following link:
But we need to use a particular pre-release version of Processing 2.0 which can be downloaded from [TODO: Update when later version is compatible]:
Download the appropriate version for your OS and run the application. The first time Processing is run it will create your sketchbook. This is the way Processing defines your workspace and where it will be storing all your work by default.
We now need to add a library and a tool to the standard installation.
First, exit Processing so that it will find the new libraries and tools when you next run it.
Look inside the folder Processing (not the Arduino folder) you uncompressed earlier (inside the ArduinoADK folder) and you will find two further folders:
libraries
tools
If your Processing sketchbook folder is empty you can copy the libraries and tools folders into your sketchbook folder.
If you already have a libraries or tools folder in your sketchbook you will need to copy the content of the libraries and tools folders into their respective folders in your sketchbook.
You should now have two subfolders inside your sketchbook:
tools/Arduino_ADK: contains the compilation/uploading tool
libraries/ArduinoAdkUsb: contains the library to handle the USB communication
The next time you start Processing the tool and library will be ready to use.
Toward the upper right corner of the sketch editor window you will see a small button stating the work mode for Processing. By default you will be working in Standard mode. Click on the button to change to Android mode. That should also change the color of your application from grey to green.
At this stage Processing will ask you to select the location of the Android SDK which you downloaded earlier.

You can now use the editor to write code for your phone. In order to launch your ADK compatible code, you should look for the Arduino ADK option from the Tools menu.


Download the Arduino IDE from the following link. You might have this software already installed in your computer:
As with Processing, you need to run the Arduino IDE once to create your sketchbook folder. Make sure you exit the IDE before performing the next step to install the library.
Once the Arduino sketchbook folder is created, copy the libraries folder (not the experimental libraries-v2 folder) from the Arduino folder you uncompressed earlier (the one inside the ArduinoADK folder) into the Arduino sketchbook folder. If you have an existing libraries folder in your Arduino sketchbook folder then copy the UsbHost library (from inside the ArduinoADK/Arduino/libraries folder) into it instead.
Remember, if you are using the same location as a previous Arduino installation, take care not to overwrite the existing libraries folder. You should just copy the UsbHost library into the existing libraries folder.
As with the Processing bundle, if you had an older version of the library (e.g. you downloaded it before 20120607), you should delete the old folders and replace them with the new one.
If you have any of the following Arduino libraries installed you will need to remove them:
AndroidAccessory
USB_Host_Shield (both version 1.x and 2.x)
The new UsbHost library cannot co-exist with the older AndroidAccessory library nor any version of the USB_Host_Shield library.
You can now upload the provided example accessory sketches and write sketches to create your own accessories.
The libraries you installed both in Processing and Arduino come with Examples for you to try out the technology.
You can browse the example sketches by going to the menu File > Examples > UsbHost in the Arduino IDE and File > Examples… > Contributed Libraries > ArduinoAdkUsb in the Processing IDE.
These tools require a particular process. You are writing code for two different pieces of hardware:
A good way of working could be to:
As of 7 June 2012 there are some known issues:
onStop() function is not provided in the sketch.
future USB class hierarchy.