<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>Android Developer
http://devel.androidsith.com</description><title>Hpsaturn</title><generator>Tumblr (3.0; @hpsaturn)</generator><link>http://hpsaturn.com/</link><item><title>How to Android ADK with Arduino USB Host Shield</title><description>&lt;h2&gt;Description:&lt;/h2&gt;
&lt;p&gt;Android ADK is the official Google implementation to join the worlds of Android and Arduino. This quick guide explains how to do it with USB Host Shield for Arduino (&lt;b&gt;WARNING: Beta release of this document!&lt;/b&gt;).&lt;/p&gt;
&lt;div align="center"&gt;&lt;iframe width="420" height="315" src="http://www.youtube.com/embed/LXOrH24mHNM" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;h2&gt;Android requirements:&lt;/h2&gt;
&lt;br/&gt;&lt;h3&gt;ROM&lt;/h3&gt;
&lt;ul&gt;&lt;li&gt;For any Android, you must have an Android rom either 2.3.4 or higher or Android 3.1.&lt;/li&gt;
&lt;li&gt;For  HTC G1 install the ROM: &lt;a href="http://forum.xda-developers.com/showthread.php?t=882356"&gt;EzGingerbread&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;SDK&lt;/h3&gt;
&lt;ul&gt;&lt;li&gt;Install and configure Android SDK (&lt;a href="http://developer.android.com/sdk/installing.html"&gt;Complete guide&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dl-ssl.google.com/android/adk/adk_release_0512.zip"&gt;Download&lt;/a&gt; the project and libraries to the SDK&lt;/li&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
mkdir ~/android_adk
cd ~/android_adk
mv ~/download/adk_release_0512.zip .
unzip adk_release_0512.zip
cp -r ADK_release_0512/app ~/workspace/DemoKit
]]&gt;&lt;/script&gt;&lt;li&gt;Import the project DemoKit on Eclipse&lt;/li&gt;
&lt;/ul&gt;&lt;br/&gt;&lt;h2&gt;Arduino requirements&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;Install Arduino software (&lt;a href="http://arduino.cc/en/Guide/HomePage"&gt;complete guide&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Download USB Host Shield &lt;a href="https://github.com/felis/USB_Host_Shield/tree/dev"&gt;firmware&lt;/a&gt; or clone this and include library in Arduino:&lt;/li&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
cd /opt/arduino/libraries
git clone https://github.com/felis/USB_Host_Shield.git
]]&gt;&lt;/script&gt;&lt;li&gt;include AndroidAccessory firmware in Arduino:&lt;/li&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
cd ~/android_adk
cp -r ADK_release_0512/firmware/arduino_libs/AndroidAccessory /opt/arduino/libraries/
]]&gt;&lt;/script&gt;&lt;/ul&gt;&lt;br/&gt;&lt;h2&gt;Arduino Code&lt;/h2&gt;
&lt;br/&gt;&lt;p&gt;Create a new Arduino project and include this code. Compile it and send it to your Arduino with USB Host installed&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: java"&gt;&lt;![CDATA[
#include &lt;Max3421e.h&gt;
#include &lt;Usb.h&gt;
#include &lt;AndroidAccessory.h&gt;
#include &lt;Wire.h&gt;
#include &lt;Servo.h&gt;

#define  LED1_RED       5
#define  LED1_GREEN     3
#define  LED1_BLUE      6
#define  SERVO1         2 
#define  SERVO2         4
#define  RELAY1         A2
#define  LIGHT_SENSOR   A0
#define  TEMP_SENSOR    A1
#define  BUTTON1        7
#define  BUTTON2        8

AndroidAccessory acc("Google, Inc.",
		     "DemoKit",
		     "DemoKit Arduino Board",
		     "1.0",
		     "http://www.android.com",
		     "0000000012345678");
Servo servos[2];

void setup();
void loop();

void init_buttons(){
	pinMode(BUTTON1, INPUT);
	pinMode(BUTTON2, INPUT);
	// enable the internal pullups
	digitalWrite(BUTTON1, HIGH);
	digitalWrite(BUTTON2, HIGH);
}

void init_relays(){
	pinMode(RELAY1, OUTPUT);
}

void init_leds(){
	pinMode(LED1_RED, OUTPUT);
	pinMode(LED1_GREEN, OUTPUT);
	pinMode(LED1_BLUE, OUTPUT);
	analogWrite(LED1_RED, 0);
	analogWrite(LED1_GREEN, 0);
	analogWrite(LED1_BLUE, 0);
}

byte b1, b2, c;

void setup(){
	Serial.begin(115200);
	Serial.print("\r\nStart");

	init_leds();
	init_relays();
	init_buttons();

	servos[0].attach(SERVO1);
	servos[0].write(90);
	servos[1].attach(SERVO2);
	servos[1].write(90);

	b1 = digitalRead(BUTTON1);
	b2 = digitalRead(BUTTON2);
	c = 0;

	acc.powerOn();
}

void loop(){
	byte err;
	byte idle;
	static byte count = 0;
	byte msg[3];
	long touchcount;

	if (acc.isConnected()) {
		int len = acc.read(msg, sizeof(msg), 1);
		int i;
		byte b;
		uint16_t val;
		int x, y;
		char c0;

		if (len &gt; 0) {
			// assumes only one command per packet
			if (msg[0] == 0x2) {
				if (msg[1] == 0x0)
					analogWrite(LED1_RED, msg[2]);
				else if (msg[1] == 0x1)
					analogWrite(LED1_GREEN, msg[2]);
				else if (msg[1] == 0x2)
					analogWrite(LED1_BLUE, msg[2]);
				else if (msg[1] == 0x10)
					servos[0].write(map(msg[2], 0, 255, 0, 180));
                else if (msg[1] == 0x11)
					servos[1].write(map(msg[2], 0, 255, 0, 180));
                                
			} else if (msg[0] == 0x3) {
			    if (msg[1] == 0x0)
					digitalWrite(RELAY1, msg[2] ? HIGH : LOW);
			}
		}

		msg[0] = 0x1;

		b = digitalRead(BUTTON1);
		if (b != b1) {
			msg[1] = 0;
			msg[2] = b ? 0 : 1;
			acc.write(msg, 3);
			b1 = b;
		}
		b = digitalRead(BUTTON2);
		if (b != b2) {
			msg[1] = 1;
			msg[2] = b ? 0 : 1;
			acc.write(msg, 3);
			b2 = b;
		}
		switch (count++ % 0x10) {
		case 0:
			val = analogRead(TEMP_SENSOR);
			msg[0] = 0x4;
			msg[1] = val &gt;&gt; 8;
			msg[2] = val &amp; 0xff;
			acc.write(msg, 3);
			break;
		case 0x4:
			val = analogRead(LIGHT_SENSOR);
			msg[0] = 0x5;
			msg[1] = val &gt;&gt; 8;
			msg[2] = val &amp; 0xff;
			acc.write(msg, 3);
			break;
		}
	} else {
		// reset outputs to default values on disconnect
		analogWrite(LED1_RED, 255);
		analogWrite(LED1_GREEN, 255);
		analogWrite(LED1_BLUE, 255);
		servos[0].write(90);
        servos[1].write(90);
		digitalWrite(RELAY1, LOW);
	}
	delay(10);
}
]]&gt;&lt;/script&gt;&lt;h4&gt;Additional links&lt;/h4&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino/"&gt;Circuit@Home&lt;/a&gt; (USB Host Shield)
&lt;/li&gt;&lt;li&gt;&lt;a href="http://wiki.cyanogenmod.com/wiki/HTC_Dream:_Rooting"&gt;How to root HTC G1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Video: &lt;a href="http://youtu.be/LXOrH24mHNM"&gt;Android ADK in a HTC G1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://hpsaturn.com/post/11980594986</link><guid>http://hpsaturn.com/post/11980594986</guid><pubDate>Wed, 26 Oct 2011 23:25:00 -0500</pubDate><category>android</category><category>arduino</category><category>ADK</category><category>SDK</category><category>USB</category><category>HOST</category><category>Shield</category><category>Electronics</category><category>Java</category></item><item><title>Port of the ADK (Android Open Accessory Development Kit) in...</title><description>&lt;iframe width="400" height="328" src="http://www.youtube.com/embed/LXOrH24mHNM?wmode=transparent&amp;autohide=1&amp;egm=0&amp;hd=1&amp;iv_load_policy=3&amp;modestbranding=1&amp;rel=0&amp;showinfo=0&amp;showsearch=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Port of the ADK (Android Open Accessory Development Kit) in G1&lt;/p&gt;
&lt;p&gt;Author: @hpsaturn&lt;/p&gt;
&lt;p&gt;More info:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bit.ly/qwysxW"&gt;http://bit.ly/qwysxW&lt;/a&gt; (GitHub code) &lt;a href="http://developer.android.com/guide/topics/usb/adk.html"&gt;http://developer.android.com/guide/topics/usb/adk.html&lt;/a&gt; (ADK Android Developers) &lt;a href="http://forum.xda-developers.com/showthread.php?t=882356"&gt;http://forum.xda-developers.com/showthread.php?t=882356&lt;/a&gt; (XDA implementation)&lt;/p&gt;
&lt;p&gt;Thanks to @xdaterry&lt;/p&gt;</description><link>http://hpsaturn.com/post/9507891569</link><guid>http://hpsaturn.com/post/9507891569</guid><pubDate>Sun, 28 Aug 2011 12:43:16 -0500</pubDate><category>Android</category><category>HTC</category><category>ADK</category><category>G1</category><category>Accessory</category><category>Arduino</category><category>ROM</category><category>CyanogenMod</category><category>Gingerbread</category><category>host</category><category>USB</category></item></channel></rss>

