Smartphone++
-
Upload
mharkus -
Category
Technology
-
view
1.762 -
download
4
description
Transcript of Smartphone++
![Page 1: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/1.jpg)
Smartphone++ Marc Lester S. Tan Mobile Applications Developer, SAP
GDG Devfest Kota Kinabalu 2013
![Page 2: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/2.jpg)
Agenda
● Overview of Arduino
● Google ADK
● Uses of ADK and Demo
![Page 3: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/3.jpg)
Overview of Arduino
![Page 4: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/4.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/5.jpg)
Overview of Arduino
• Inexpensive
• Cross-platform
• Simple and clear programming environment.
• Open-source software and hardware
![Page 6: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/6.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/7.jpg)
Arduino IDE
• Java
• Based on Processing IDE
(processing.org)
• Write and upload code to Arduino
board
![Page 8: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/8.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/9.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/10.jpg)
Google ADK
![Page 11: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/11.jpg)
USB on Android Host Mode
Power
Data Transfer
Accessory Mode
Power
Data Transfer
![Page 12: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/12.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/13.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/14.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/15.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/16.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/17.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/18.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/19.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/20.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/21.jpg)
Uses of ADK and Demo
![Page 22: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/22.jpg)
Uses of ADK
Audio Docking Station
![Page 23: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/23.jpg)
Uses of ADK
Exercise Machines
![Page 24: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/24.jpg)
Uses of ADK
Weather Stations
![Page 25: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/25.jpg)
Uses of ADK
Home Automation
![Page 26: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/26.jpg)
Demo: Sonar
![Page 27: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/27.jpg)
Demo: Motor Control
![Page 28: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/28.jpg)
Demo: Android as USB Host
![Page 29: Smartphone++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/29.jpg)
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++](https://reader034.fdocuments.us/reader034/viewer/2022051819/54c8456c4a795985748b4640/html5/thumbnails/30.jpg)
Thank you Questions?