Saturday, March 9, 2013

Hello World ADK: Communication between Arduino Due and Android device

The former post demonstrate half "Pre-Hello World for ADK". It's further implemented to include communication between Arduino Due and Android Device.

  • In Arduino Due side: it monitor any incoming data from accessory, and send it back.
  • In Android side, it will send out the text when Send button clicked. And display the text received from USB.
It implement the function of bi-direction communication between Arduino Due and Android Device.

The code in Arduino side is listed here:
#include "variant.h"
#include <stdio.h>
#include <adk.h>

// Accessory descriptor. It's how Arduino identifies itself to Android.
char applicationName[] = "HelloADK"; // the app on your phone
char accessoryName[] = "Arduino Due"; // your Arduino board
char companyName[] = "Arduino-er";

// Make up anything you want for these
char versionNumber[] = "0.1";
char serialNumber[] = "1";
char url[] = "";

USBHost Usb;
ADK adk(&Usb, companyName, applicationName, accessoryName,versionNumber,url,serialNumber);

// Pin 13 has an LED connected on most Arduino boards.
int led = 13;

void setup() {
    pinMode(led, OUTPUT);
    //Indicate start of program
    digitalWrite(led, LOW);
    digitalWrite(led, HIGH);
    for(int i = 0; i <= 2; i++){
        digitalWrite(led, HIGH);
        digitalWrite(led, LOW);

#define RCVSIZE 128

void loop() {
    char helloworld[] = "Hello World!\r\n";
    uint8_t buf[RCVSIZE];
    uint32_t nbread = 0;
    if (adk.isReady()){
        digitalWrite(led, HIGH);
       , RCVSIZE, buf);
        if (nbread > 0){
            adk.write(nbread, buf);
        digitalWrite(led, LOW);

The Android side code will be shown in next post "Hello World ADK: Android code".

Remark: The example tested run on HTC One with Android 4.1.1, but NOT work on Nexus One with Android 2.3.6.


  1. Hi,
    Would you know what transfer rate is achievable between the DUE and an Android device ?
    Thank you,