Monday, July 25, 2011

Arduino Mega ADK Setup Notes

If you try using the Arduino Mega ADK with the default DemoKit code, it will hang during initialization if you do not have all of the same sensors attached.

The following code is a simplified version of the Arduino DemoKit code that connects the built-in LED on pin 13 to the Relay 1 button in the Android DemoKit application.

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

#define  LED1         13

AndroidAccessory acc("Google, Inc.",            // Manufacturer
                     "DemoKit",                 // Model
                     "DemoKit Arduino Board",   // Description
                     "1.0",                     // Version
                     "",  // URI
                     "0000000012345678");       // Serial

void setup();
void loop();

void init_led()
  pinMode(LED1, OUTPUT);

void setup()
  Serial.print("\r\nADK Started\r\n");


  // Power On Android Accessory interface and init USB controller

void loop()
  byte data[3];
  if (acc.isConnected()) {
    int len =, sizeof(data), 1);
    if (len > 0) {
      if (data[0] == 0x3) {
        if (data[1] == 0x0) {
          digitalWrite(LED1, data[2] ? HIGH : LOW);
          Serial.print("Toggle LED\r\n");


1 comment:

Andy said...

Thank you so much! I was smashing my brains out trying to figure out what was going on!
You rule!