Friday, March 1, 2013

Test code for ADK on Arduino Due

Arduino 1.5 BETA come with a ADK Terminal Test example to demonstrates USB Host connectivity between an Android phone and an Arduino Due. The ADK for the Arduino Due is a work in progress. For additional information on the Arduino ADK visit http://labs.arduino.cc/ADK/Index.

To load the ADK Terminal Test example, select File in Arduino IDE -> Examples -> USBHost -> ADKTerminalTest.

Open ADK Terminal Test
Open ADK Terminal Test

BUT...it not work in my case! The function Serial.begin(9600) have to be called at the beginning of setup(). After then, it work as expected (view the video). From the thread http://arduino.cc/forum/index.php?PHPSESSID=13eedea106bcfa79b016f120f99a8f34&topic=129390.0

ADKTerminalTest
ADKTerminalTest

/*

 ADK Terminal Test

 This demonstrates USB Host connectivity between an 
 Android phone and an Arduino Due.

 The ADK for the Arduino Due is a work in progress
 For additional information on the Arduino ADK visit 
 http://labs.arduino.cc/ADK/Index

 created 27 June 2012
 by Cristian Maglie

*/

#include "variant.h"
#include <stdio.h>
#include <adk.h>

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

// Make up anything you want for these
char versionNumber[] = "1.0";
char serialNumber[] = "1";
char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk";

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

void setup()
{
        Serial.begin(9600);  //<-- need to add
  
 cpu_irq_enable();
 printf("\r\nADK demo start\r\n");
 delay(200);
}

#define RCVSIZE 128

void loop()
{
 uint8_t buf[RCVSIZE];
 uint32_t nbread = 0;
 char helloworld[] = "Hello World!\r\n";

 Usb.Task();

 if (adk.isReady())
 {
  /* Write hello string to ADK */
  adk.write(strlen(helloworld), (uint8_t *)helloworld);

  delay(1000);

  /* Read data from ADK and print to UART */
  adk.read(&nbread, RCVSIZE, buf);
  if (nbread > 0)
  {
   printf("RCV: ");
   for (uint32_t i = 0; i < nbread; ++i)
   {
    printf("%c", (char)buf[i]);
   }
   printf("\r\n");
  }
 }
}





update@2013-06-17:

Similar Android example with source code found, refer:


No comments:

Post a Comment