smartphone++

30
Smartphone++ Marc Lester S. Tan Mobile Applications Developer, SAP GDG Devfest Kota Kinabalu 2013

Upload: mharkus

Post on 28-Jan-2015

1.762 views

Category:

Technology


4 download

DESCRIPTION

slides for GDG Kota Kinabalu Devfest 2013

TRANSCRIPT

Page 1: Smartphone++

Smartphone++ Marc Lester S. Tan Mobile Applications Developer, SAP

GDG Devfest Kota Kinabalu 2013

Page 2: Smartphone++

Agenda

●  Overview of Arduino

●  Google ADK

●  Uses of ADK and Demo

Page 3: Smartphone++

Overview of Arduino

Page 4: Smartphone++

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

Page 5: Smartphone++

Overview of Arduino

•  Inexpensive

•  Cross-platform

•  Simple and clear programming environment.

•  Open-source software and hardware

Page 6: Smartphone++

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/

Page 7: Smartphone++

Arduino IDE

•  Java

•  Based on Processing IDE

(processing.org)

•  Write and upload code to Arduino

board

Page 8: Smartphone++

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

Page 9: Smartphone++

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.

}

Page 10: Smartphone++

Google ADK

Page 11: Smartphone++

USB on Android Host Mode

Power

Data Transfer

Accessory Mode

Power

Data Transfer

Page 12: Smartphone++

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

Page 13: Smartphone++

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

Page 14: Smartphone++

Design and Create the Hardware

•  Use Fritzing to design your

breadboard, schematic diagram

and bill of materials.

•  Get it from http://fritzing.org/

Page 15: Smartphone++

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);

}

Page 16: Smartphone++

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" />

Page 17: Smartphone++

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>

Page 18: Smartphone++

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>

Page 19: Smartphone++

Create the Android Application

onCreate()...

mUsbManager = UsbManager.getInstance(this);

onResume()...

UsbAccessory[] accessories = mUsbManager.getAccessoryList();

UsbAccessory accessory = accessories[0]);

if (mUsbManager.hasPermission(accessory)) {

openAccessory(accessory);

}

Page 20: Smartphone++

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();

Page 21: Smartphone++

Uses of ADK and Demo

Page 22: Smartphone++

Uses of ADK

Audio Docking Station

Page 23: Smartphone++

Uses of ADK

Exercise Machines

Page 24: Smartphone++

Uses of ADK

Weather Stations

Page 25: Smartphone++

Uses of ADK

Home Automation

Page 26: Smartphone++

Demo: Sonar

Page 27: Smartphone++

Demo: Motor Control

Page 28: Smartphone++

Demo: Android as USB Host

Page 29: Smartphone++

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

Page 30: Smartphone++

Thank you Questions?