smartphone++
DESCRIPTION
slides for GDG Kota Kinabalu Devfest 2013TRANSCRIPT
Smartphone++ Marc Lester S. Tan Mobile Applications Developer, SAP
GDG Devfest Kota Kinabalu 2013
Agenda
● Overview of Arduino
● Google ADK
● Uses of ADK and Demo
Overview of Arduino
Overview of Arduino
• Open-source electronics prototyping
platform.
• Intended for Artists, Designers and
Hobbyists.
• Arduino Programming Language based
on Wiring.
• Arduino IDE based on Processing
source: http://www.arduino.cc
Overview of Arduino
• Inexpensive
• Cross-platform
• Simple and clear programming environment.
• Open-source software and hardware
Arduino Shields
Shields are boards that can be plugged on top
of the Arduino PCB extending its capabilities.
• SD Card Shield
• USB Host Shield
• Ethernet Shield
source: http://blog.protoneer.co.nz/
Arduino IDE
• Java
• Based on Processing IDE
(processing.org)
• Write and upload code to Arduino
board
Arduino Sketch
• setup()
o called once
o setup pin modes
o library initialization
• loop()
o called over the over again
o heart of every sketches
Sample Sketch int inputPin = 12; // let pin 12 be our input pin
int outputPin = 11; // let pin 11 be our ouput pin
void setup(){
pinMode(outputPin, OUTPUT); // setup output pin to be an OUTPUT
pinMode(inputPin, INPUT); // setup input pin to be our INPUT
}
void loop(){
int inputVal = digitalRead(inputPin);
digitalWrite(outputPin, inputVal); // write the value of input pin to output
delay(100); // wait for 100ms // before looping again.
}
Google ADK
USB on Android Host Mode
Power
Data Transfer
Accessory Mode
Power
Data Transfer
Google ADK
source: http://www.engadget.com/gallery/googles-arduino-based-adk-hands-on-at-google-i-o-2011/
● Reference implementation for
hardware manufacturers and
hobbyists.
● It uses Android Open Accessory
Protocol over USB or Bluetooth
● The hardware is based on
Arduino Mega.
● Two versions: ADK 2011 and
ADK 2012
Hello, Physical World
• Design and create the hardware or
circuit.
• Write the firmware for your
Arduino.
• Create an Android application that
can talk to your firmware.
source: http://www.youtube.com/watch?v=gcP7KwIENGw
Design and Create the Hardware
• Use Fritzing to design your
breadboard, schematic diagram
and bill of materials.
• Get it from http://fritzing.org/
Write the Firmware
if (acc.isConnected()) {
int len = acc.read(msg, sizeof(msg), 1);
if(len > 0){
Serial.println(len);
if(msg[0] == 0x1){
digitalWrite(13, HIGH);
}else{
digitalWrite(13, LOW);
}
}
}else{
digitalWrite(13, LOW);
}
Create the Android Application
● USBManager - available since 3.1 but also available for 2.3.4 using Google API 10
○ Not all devices support accessory mode
● Android Manifest Requirements:
Declare:
<uses-feature android:name="android.hardware.usb.accessory" />
If using Add-on:
<application….>
<uses-library android:name="com.android.future.usb.accessory" />
Create the Android Application
Android Manifest Requirements:
<activity ...>
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" /
>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity>
Create the Android Application
res/xml/accessory_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-accessory manufacturer="Marc Tan" model="Motor Control" version="1.0" />
</resources>
Create the Android Application
onCreate()...
mUsbManager = UsbManager.getInstance(this);
onResume()...
UsbAccessory[] accessories = mUsbManager.getAccessoryList();
UsbAccessory accessory = accessories[0]);
if (mUsbManager.hasPermission(accessory)) {
openAccessory(accessory);
}
Create the Android Application
protected void openAccessory(UsbAccessory accessory) {
fileDescriptor = mUsbManager.openAccessory(accessory);
FileDescriptor fd = fileDescriptor.getFileDescriptor();
input = new FileInputStream(fd);
output = new FileOutputStream(fd);
}
onDestroy()...
output.write(0); // optional
fileDescriptor.close();
Uses of ADK and Demo
Uses of ADK
Audio Docking Station
Uses of ADK
Exercise Machines
Uses of ADK
Weather Stations
Uses of ADK
Home Automation
Demo: Sonar
Demo: Motor Control
Demo: Android as USB Host
Resources
Android ADK a.android.com
Arduino and Electronics, Others
arduino.cc tronixstuff.com hackaday.com
My Blog and Github
marctan.com github.com/mharkus
Quadcopter
bitcraze.se
Thank you Questions?