This is a retired product.
This guide describe how to connect an Android™ device to an Arduino ADK board (Mega ADK and Micro ADK?) and USB Host shield. Furthermore, we have tried to make it as easy as possible by concentrating in the use of Processing instead of Eclipse as the tool of choice for writing the Android Apps.
Here you can learn how to connect Arduino to Android™ via the USB cable the phone (or tablet) uses for data transfers as well as for recharging its battery. You might be interested in using Bluetooth as an alternative to get Arduino and the Android artifact to talk to each other.
Before moving any further, you need to understand which the connection capabilities of your Android™ device are. It depends not only on the hardware configuration of your device, but also on the software you have running on it.
It is very hard to trace all the possible Android™ devices with all the existing OS versions and mods. Therefore we are going to concentrate in phones that haven’t been rooted and have official updates. This doesn't mean the following explanations couldn't work for your device and we will be more than happy to list your configuration for others to know.
The different configurations listed in this table are Accessory Development Kit (ADK) which uses the Open Accessory library which lets Arduino act as the USB Host. The unofficial USB connection between an Arduino board and an Android™ device is built using sockets on top of the Android Debug Bridge (ADB) and may not be as stable as the ADK. USB Host is the standard USB connection where the Android™ device acts as the USB Host.
Table 1: Configuration options
|Android™ OS||ADK||ADB||BT||USB HOST|
|OS < 2.2 (pre Froyo)|
|2.3.3 ≥ OS ≥ 2.2|
|OS ≥ 2.3.4 (phones)|
|OS ≥ 3.1 (tablets)|
The examples for ADK Mode for Processing has been developed and tested on the Arduino Mega ADK and the Micro ADK?, but should work for other similar Open Accessory enabled boards as well for. The ADK mode requires the following hardware and software:
Note: Nexus 4 is confirmed that doesn't work with Open Accessory
There are two ways of installing the ADK Mode in Processing, through the Mode Manager and manually. To install it using Mode Manager in Processing, follow these steps:
If the Mode Manager doesn't work for you, you always have the option of installing the mode manually. Follow these steps to install it manually:
modes. Move your
You also need to download and install the Arduino libraries for Open Accessory. Follow these steps:
UsbHost.zipfile from http://processing.arduino.cc/UsbHost.zip
Before you can start working with the ADK Mode you’ll need to also install the Android SDK. The Android SDK contains all the bells and whistles that make up an Android application – currently there are 18 different SDK versions available, you only need one of these to develop an application.
While the standard Processing Android Mode requires only version 10 (Android version 2.3.3) the ADK Mode requires version 12. This is because Open Accessory was first introduced in version 12 (the big “tablet” version). The attentive reader who have researched Open Accessory already will have noticed that there is a way of getting Open Accessory working with version 10, however it is an add-on library which actually corresponds to version 2.3.4 of Android™.
To install the proper Android SDK version, follow these steps:
If you are working on a Windows computer you may need to run the SDK Manager as Administrator depending on where you choose to install the android SDK tools.
When developing normal Android™ applications you always have the option of working towards an Android™ Emulator rather than a real device. However, there are some things the Emulator can’t do, usually these things are related to hardware.
Open Accessory works with the standard USB port on your device and changes the way it internally works, the device can take both the Host and the Device roles. This is part of the On-The-Go (OTG) specification released in 2001. All this means that you need to have a real Android device to work with Open Accessory and ADK.
To work with real devices you first need to enable them as development devices, the procedure for enabling a device may vary from one vendor to another. The following instructions are applicable to stock Android™ devices such as the Nexus 5.
You should now have a device that has ADB debugging enabled over USB. This means that the Android Debug Bridge is open and that you have access to the device (although limited) and can install unsigned applications directly to it from Processing.
Depending on your operating systems you need to perform some different configurations on your computer before you can develop on your device.
Download the USB drivers for your device, for more information see the OEM USB page on the Android website.
Mac users will probably not need to do any configurations at all, just plug your developer enabled device to your computer.
Linux users will need to modify their UDEV rules to match the id of the device vendor. Another option, if the UDEV rules do not work is adding the vendor id to the adb_usb.ini file which is located in your ~/.android/ folder. Read more here
Developing for Open Accessory and ADK is a little bit special, there are a few things you should keep in mind.
adb -d logcat.
To test the available example/s follow these steps:
To test the available example/s follow these steps:
The Open Accessory protocol works by switching the USB port on the Android™ device between Host mode and Device mode, this enabled the Android™ phone to connect to both USB Accessories and USB Hosts.
When the phone detect that an Open Accessory enabled device was connected it will assume the role of an accessory meaning it will start drawing power from the USB port on Arduino.
Arduino will send a special identification pattern to the Android™ device, telling it what kind of Open Accessory it is, who is the vendor and it’s version number. You can view this information in the Arduino code in each example. The information within the Arduino code must match the information defined in your Processing sketch. To view and edit the information in Processing open the ADK menu and select Set ADK meta.
If the information is not valid it will present the dialog in Figure 9, this means the Android™ device doesn’t have an appropriate app installed to handle the Open Accessory, and will instead be presented with a link. This link could be either an URL to your company/organization website, or the link to the specific apk that control this Open Accessory.
Last revision 2018/02/10 by SM
The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain.