Difference between revisions of "Android open accessory"
Jump to navigation
Jump to search
(→Software: Added Rancidbacon sites sketch and app) |
(→demokit.pde: added workingish code edit for Arduino code) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
===Software=== | ===Software=== | ||
− | *Arduino 0022 | + | *[http://arduino.cc/en/Main/Software Arduino 0022] |
− | **ADK release 0512 | + | **[https://dl-ssl.google.com/android/adk/adk_release_0512.zip ADK release 0512] |
***AndroidAccessory (library for Arduino) | ***AndroidAccessory (library for Arduino) | ||
***<s>USB_Host_Shield (library for Arduino)</s> | ***<s>USB_Host_Shield (library for Arduino)</s> | ||
***demokit.pde (Arduino sketch for the demokit)* | ***demokit.pde (Arduino sketch for the demokit)* | ||
− | **Romfont USB_Host_Shield (library for Arduino)* | + | **[http://code.google.com/p/microbridge/downloads/detail?name=usb_host_patched.zip Romfont USB_Host_Shield] (library for Arduino)* |
− | *Rancidbacon.com demo sketch & app | + | *[http://rancidbacon.com/p/android-arduino-accessory/ Rancidbacon.com] demo [http://rancidbacon.com/files/Handbag001/Handbag.pde sketch] & [http://rancidbacon.com/files/Handbag001/Handbag.apk app] |
− | *Eclipse | + | *[http://www.eclipse.org/ Eclipse] |
− | **Android SDK | + | **[http://developer.android.com/sdk/index.html Android SDK] |
***DemoKit (demo android app that comes with the ADK) | ***DemoKit (demo android app that comes with the ADK) | ||
− | *CyanogenMod-7-05252011-NIGHTLY-vision (based on 2.3.4)<br> | + | *[http://www.cyanogenmod.com/ CyanogenMod-7-05252011-NIGHTLY-vision (based on 2.3.4)]<br> |
<br> | <br> | ||
* indicate that I had to change the code to get it to work. | * indicate that I had to change the code to get it to work. | ||
+ | |||
+ | ==Changes== | ||
+ | There are a few changes that have to be made to the stoke software to get this to work. | ||
+ | |||
+ | ===demokit.pde=== | ||
+ | Out of the box the Arduino sketch for the demokit will not compile for the ATmega328. There are a lot of pins that are used that do not have the same name or do not exist. | ||
+ | |||
+ | #include <Wire.h> | ||
+ | <s>#include <Servo.h></s><br> | ||
+ | #include <Max3421e.h> | ||
+ | #include <Usb.h> | ||
+ | #include <AndroidAccessory.h><br> | ||
+ | <s>#include <CapSense.h></s><br> | ||
+ | #define LED3_RED 2 | ||
+ | #define LED3_GREEN 4 | ||
+ | #define LED3_BLUE 3<br> | ||
+ | #define LED2_RED 5 | ||
+ | <s>#define LED2_GREEN 7 | ||
+ | #define LED2_BLUE 6<br> | ||
+ | #define LED1_RED 8 | ||
+ | #define LED1_GREEN 10 | ||
+ | #define LED1_BLUE 9<br> | ||
+ | #define SERVO1 11 | ||
+ | #define SERVO2 12 | ||
+ | #define SERVO3 13<br> | ||
+ | #define TOUCH_RECV 14 | ||
+ | #define TOUCH_SEND 15<br></s> | ||
+ | #define RELAY1 A0 | ||
+ | #define RELAY2 A1<br> | ||
+ | #define LIGHT_SENSOR A2 | ||
+ | #define TEMP_SENSOR A3<br> | ||
+ | <s>#define BUTTON1 A6 | ||
+ | #define BUTTON2 A7 | ||
+ | #define BUTTON3 A8<br> | ||
+ | #define JOY_SWITCH A9 // pulls line down when pressed | ||
+ | #define JOY_nINT A10 // active low interrupt input | ||
+ | #define JOY_nRESET A11 // active low reset output</s> | ||
+ | |||
+ | After removing the definitions that are not used. removed all of the functions that control things that will not be used and changed everything to LED/buttons you this is whats left. | ||
+ | |||
+ | <pre> | ||
+ | #include <Wire.h> | ||
+ | |||
+ | #include <Max3421e.h> //must be edited before use | ||
+ | #include <Usb.h> | ||
+ | #include <AndroidAccessory.h> | ||
+ | |||
+ | #define LED1 2 //digital | ||
+ | #define LED2 4 //digital | ||
+ | #define LED3 3 //pwm | ||
+ | #define LED4 5 //pwm | ||
+ | |||
+ | #define Button1 A0 | ||
+ | #define Button2 A1 | ||
+ | |||
+ | AndroidAccessory acc("Google, Inc.", //manufacturer | ||
+ | "DemoKit", //model | ||
+ | "DemoKit Arduino Board", //discription | ||
+ | "1.0", //version | ||
+ | "http://www.android.com", //uri | ||
+ | "0000000012345678"); //serial | ||
+ | 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_leds() | ||
+ | { | ||
+ | digitalWrite(LED1, 1); | ||
+ | digitalWrite(LED2, 1); | ||
+ | digitalWrite(LED3, 1); | ||
+ | digitalWrite(LED4, 1); | ||
+ | |||
+ | pinMode(LED1, OUTPUT); | ||
+ | pinMode(LED2, OUTPUT); | ||
+ | pinMode(LED3, OUTPUT); | ||
+ | pinMode(LED4, OUTPUT); | ||
+ | |||
+ | } | ||
+ | |||
+ | byte b1, b2; | ||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.print("\r\nStart"); | ||
+ | |||
+ | init_leds(); | ||
+ | init_buttons(); | ||
+ | |||
+ | b1 = digitalRead(Button1); | ||
+ | b2 = digitalRead(Button2); | ||
+ | |||
+ | acc.powerOn(); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | // byte err; | ||
+ | // byte idle; | ||
+ | // static byte count = 0; | ||
+ | byte msg[3]; | ||
+ | |||
+ | if (acc.isConnected()) { //If the arduino is talking to the phoen | ||
+ | int len = acc.read(msg, sizeof(msg), 1); //set len to the size of the last msg from the phone | ||
+ | // int i; | ||
+ | byte b; | ||
+ | // uint16_t val; | ||
+ | // int x, y; | ||
+ | // char c0; | ||
+ | |||
+ | if (len > 0) { | ||
+ | // assumes only one command per packet | ||
+ | if (msg[0] == 0x2) { | ||
+ | if (msg[1] == 0x0) | ||
+ | analogWrite(LED1, 255 - msg[2]); | ||
+ | else if (msg[1] == 0x1) | ||
+ | analogWrite(LED2, 255 - msg[2]); | ||
+ | else if (msg[1] == 0x2) | ||
+ | analogWrite(LED3, 255 - msg[2]); | ||
+ | else if (msg[1] == 0x3) | ||
+ | analogWrite(LED4, 255 - msg[2]); | ||
+ | } else if (msg[0] == 0x3) { | ||
+ | } | ||
+ | |||
+ | 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; | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | // reset outputs to default values on disconnect | ||
+ | analogWrite(LED1, 255); | ||
+ | analogWrite(LED2, 255); | ||
+ | analogWrite(LED3, 255); | ||
+ | analogWrite(LED4, 255); | ||
+ | } | ||
+ | |||
+ | delay(10); | ||
+ | } | ||
+ | |||
+ | </pre> |
Latest revision as of 03:28, 2 June 2011
This stub is to document the process of trying to get AOA working with older hardware. ie freeduino + spark fun host shield and phones not currently supported.
What I am using
Hardware
- Freeduino 1.22 with a ATmega328p-pu chip
- Sparkfun USB Host shield
- HTC G2
Software
- Arduino 0022
- ADK release 0512
- AndroidAccessory (library for Arduino)
USB_Host_Shield (library for Arduino)- demokit.pde (Arduino sketch for the demokit)*
- Romfont USB_Host_Shield (library for Arduino)*
- ADK release 0512
- Rancidbacon.com demo sketch & app
- Eclipse
- Android SDK
- DemoKit (demo android app that comes with the ADK)
- Android SDK
- CyanogenMod-7-05252011-NIGHTLY-vision (based on 2.3.4)
* indicate that I had to change the code to get it to work.
Changes
There are a few changes that have to be made to the stoke software to get this to work.
demokit.pde
Out of the box the Arduino sketch for the demokit will not compile for the ATmega328. There are a lot of pins that are used that do not have the same name or do not exist.
#include <Wire.h>#include <Servo.h>
#include <Max3421e.h> #include <Usb.h> #include <AndroidAccessory.h>
#include <CapSense.h>
#define LED3_RED 2 #define LED3_GREEN 4 #define LED3_BLUE 3
#define LED2_RED 5#define LED2_GREEN 7 #define LED2_BLUE 6#define RELAY1 A0 #define RELAY2 A1
#define LED1_RED 8 #define LED1_GREEN 10 #define LED1_BLUE 9
#define SERVO1 11 #define SERVO2 12 #define SERVO3 13
#define TOUCH_RECV 14 #define TOUCH_SEND 15
#define LIGHT_SENSOR A2 #define TEMP_SENSOR A3
#define BUTTON1 A6 #define BUTTON2 A7 #define BUTTON3 A8
#define JOY_SWITCH A9 // pulls line down when pressed #define JOY_nINT A10 // active low interrupt input #define JOY_nRESET A11 // active low reset output
After removing the definitions that are not used. removed all of the functions that control things that will not be used and changed everything to LED/buttons you this is whats left.
#include <Wire.h> #include <Max3421e.h> //must be edited before use #include <Usb.h> #include <AndroidAccessory.h> #define LED1 2 //digital #define LED2 4 //digital #define LED3 3 //pwm #define LED4 5 //pwm #define Button1 A0 #define Button2 A1 AndroidAccessory acc("Google, Inc.", //manufacturer "DemoKit", //model "DemoKit Arduino Board", //discription "1.0", //version "http://www.android.com", //uri "0000000012345678"); //serial 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_leds() { digitalWrite(LED1, 1); digitalWrite(LED2, 1); digitalWrite(LED3, 1); digitalWrite(LED4, 1); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); } byte b1, b2; void setup() { Serial.begin(115200); Serial.print("\r\nStart"); init_leds(); init_buttons(); b1 = digitalRead(Button1); b2 = digitalRead(Button2); acc.powerOn(); } void loop() { // byte err; // byte idle; // static byte count = 0; byte msg[3]; if (acc.isConnected()) { //If the arduino is talking to the phoen int len = acc.read(msg, sizeof(msg), 1); //set len to the size of the last msg from the phone // int i; byte b; // uint16_t val; // int x, y; // char c0; if (len > 0) { // assumes only one command per packet if (msg[0] == 0x2) { if (msg[1] == 0x0) analogWrite(LED1, 255 - msg[2]); else if (msg[1] == 0x1) analogWrite(LED2, 255 - msg[2]); else if (msg[1] == 0x2) analogWrite(LED3, 255 - msg[2]); else if (msg[1] == 0x3) analogWrite(LED4, 255 - msg[2]); } else if (msg[0] == 0x3) { } 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; } } } else { // reset outputs to default values on disconnect analogWrite(LED1, 255); analogWrite(LED2, 255); analogWrite(LED3, 255); analogWrite(LED4, 255); } delay(10); }