You are on page 1of 7

Accessory Development Kit

The Accessory Development Kit (ADK) is a reference implementation for hardware manufacturers and
hobbyists to use as a starting point for building accessories for Android. Each ADK release is provided
with source code and hardware specifications to make the process of developing your own accessories
easier.

Accessory Development Kit 2012 Guide

The Android Accessory Development Kit (ADK) for 2012 is the latest reference implementation of
an Android Open Accessory device, designed to help Android hardware accessory builders and software
developers create accessories for Android. The ADK 2012 is based on the Arduino open source
electronics prototyping platform, with some hardware and software extensions that allow it to
communicate with Android devices.

A limited number of these kits were produced and distributed at the Google I/O 2012 developer
conference. If you did not receive one of these kits, fear not! The specifications and design files for the
hardware were also released for use by manufacturers and hobbyists. You should expect to see kits with
similar features available for purchase, or you can build one yourself!

One of the important new features demonstrated by this ADK is the ability to play audio over a USB
connection. Be sure to check out the reference implementation of a USB audio dock in this ADK if you
are interested in making audio-related USB accessories for Android.

Components

The ADK 2012 is based on the Arduino open source electronics prototyping platform and is an open
hardware design. The hardware design files and firmware source code are included with the ADK
software download. The ADK contains two main physical hardware components:

1. Main processing board containing the microprocessor, USB connections, power connector and
input/output pins. This board can be removed and used separately from the rest of the hardware.
2. Shield containing sensors, LEDs, input controls, audio amplifier and speaker output, contained in a
custom, polygon box enclosure.

The main hardware features of the ADK are as follows:

 An ARM 32-bit Cortex M3 micro-processor

 Separate USB connections for an Android device and computer connection for programming and
debugging

 Sensors for light, color, proximity, temperature, humidity, barometric pressure, and acceleration

 Micro SD Card slot

 Bluetooth support

The ADK comes preloaded with an alarm clock firmware program that you can use immediately. A
companion Android application, ADK 2012, is available on Google Play. The source code for both the
Android application and the ADK firmware (an Arduino sketch) can be downloaded from this page.

The ADK 2012 also comes with additional parts to help you develop accessories with it, including:

 AC power adapter

 USB A to Micro USB B connector cable

 Micro USB B to Micro USB AB connector (small, rectangular plug)

 Micro SD Card, preinstalled in the ADK SD Card socket

The Google ADK

The Google ADK is a USB Accessory development kit based on the Arduino Mega2560 and
the Circuits@Home USB shield. It contains the hardware designs for the board, including an optional
demo shield that affixes atop the main board and implements stuff like a small joystick, different LEDs
and more. It also includes firmware libraries for both the USB host logic and the Android device
interaction. Finally, it includes example firmware for the main board and demo shield as well as an
example application for the Android device.

How the ADK Connects with Android Devices


The essential feature of any Android accessory is its ability to connect and communicate with an Android
device. Creating a fast and reliable connection between your accessory and Android devices is the first
order of business when building software for an accessory. This section describes the connection and
communication essentials used in the ADK 2012 so that you can apply them to developing your own
Android accessories

ADK Connection over Bluetooth

The ADK 2012 app and hardware accessory use a Bluetooth Serial Port Profile (SPP) connection to
communicate. This connection allows two way communication between the ADK accessory and Android
devices.

Note: The implementation of the ADK hardware allows the use of other profiles and multiple
connections. However, the basic communication between the ADK 2012 accessory and the Android
application uses SPP.

Accessory Bluetooth Code

In order to enable Bluetooth communications, the clock.ino sketch for the ADK 2012 accessory calls
a btStart()method during the setup() method to enable radio frequency communications and start listening
for Bluetooth connections:
ADK L;
void setup() {
L.adkInit();
L.btStart();
}
...
void btStart(){
uint8_t i, dlci;
int f;

L.btEnable(adkBtConnectionRequest, adkBtLinkKeyRequest, adkBtLinkKeyCreated,


adkBtPinRequest, NULL);

dlci = L.btRfcommReserveDlci(RFCOMM_DLCI_NEED_EVEN);

if(!dlci) dbgPrintf("BTADK: failed to allocate DLCI\n");


else{

//change descriptor to be valid...


for(i = 0, f = -1; i < sizeof(sdpDescrADK); i++){

if(sdpDescrADK[i] == MAGIX){
if(f == -1) f = i;
else break;
}
}

if(i != sizeof(sdpDescrADK) || f == -1){

dbgPrintf("BTADK: failed to find a single marker in descriptor\n");


L.btRfcommReleaseDlci(dlci);
return;
}

sdpDescrADK[f] = dlci >> 1;

dbgPrintf("BTADK has DLCI %u\n", dlci);

L.btRfcommRegisterPort(dlci, btAdkPortOpen, btAdkPortClose, btAdkPortRx);


L.btSdpServiceDescriptorAdd(sdpDescrADK, sizeof(sdpDescrADK));
}
}

Once Bluetooth is enabled with the code shown above, the accessory listens for connection requests. The
ADK library handles listening and connection details, so the accessory
calls ADK::adkEventProcess() once during each loop execution:

void loop(void)
{
...
L.adkEventProcess(); //let the adk framework do its thing
...
}

ADK Connection over USB

The ADK 2012 app and hardware accessory can also use a USB connection to communicate, similar to
the original ADK.
Accessory USB Code

The ADK library takes care of most of the implementation details for a USB connection, the accessory
code must make a few calls to initialize USB connectivity, including setting the accessory identification
strings:
ADK L;
void setup() {
L.adkInit();
L.usbSetAccessoryStringVendor(...);
L.usbSetAccessoryStringName(...);
L.usbSetAccessoryStringLongname(...);
L.usbSetAccessoryStringVersion(...);
L.usbSetAccessoryStringUrl(...);
L.usbSetAccessoryStringSerial(...);

L.usbStart();
}

Once USB is enabled with code shown above, the accessory listens for connection requests. The ADK
library handles listening and connection details, so the accessory calls ADK::adkEventProcess() once
during each loop execution:

void loop(void)
{
...
L.adkEventProcess(); //let the adk framework do its thing
...
}

The accessory must then check for a live USB connection to process commands and send messages. Here
is a summary of the relevant code:

void loop() {
if (L.accessoryConnected()) {
int recvLen = L.accessoryReceive(msg, sizeof(msg));
if (recvLen > 0) {
... // process message
}

L.accessorySend(outmsg, outmsgLen);
}
L.adkEventProcess();
}

You might also like