- 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.
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[] = "https://sites.google.com/site/arduinosite/exercise/helloadk/HelloADK_0.1.apk"; 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() { Serial.begin(9600); cpu_irq_enable(); pinMode(led, OUTPUT); //Indicate start of program digitalWrite(led, LOW); delay(2000); digitalWrite(led, HIGH); for(int i = 0; i <= 2; i++){ digitalWrite(led, HIGH); delay(250); digitalWrite(led, LOW); delay(250); } } #define RCVSIZE 128 void loop() { char helloworld[] = "Hello World!\r\n"; uint8_t buf[RCVSIZE]; uint32_t nbread = 0; Usb.Task(); if (adk.isReady()){ digitalWrite(led, HIGH); adk.read(&nbread, RCVSIZE, buf); if (nbread > 0){ adk.write(nbread, buf); } }else{ 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.
Hi,
ReplyDeleteWould you know what transfer rate is achievable between the DUE and an Android device ?
Thank you,
Paul
I'm not sure. But in my experience, I have to set 9600 to make it work. refer: http://arduino-er.blogspot.com/2013/03/test-code-for-adk-on-arduino-due.html.
Delete