SlideShare uma empresa Scribd logo
1 de 41
NFC                Bluetooth

                         Open
                       Accessory



  Better with Friends
(Or "Android: The Loveable Mobile Platform That Plays Well with External Devices")




           Pearl Chen                                          Google+:   klab.ca/+
  pearl@karma-laboratory.com                                   Twitter:   @PearlChen




                                 klab.ca/spotlightandroid
The future is already here
— it's just not very evenly
        distributed.
                                      William Gibson


           klab.ca/spotlightandroid
About me




Some Comp Sci classes back there too




                                       ( Illustration created using modified output from visualize.me and my LinkedIn profile. )
Some of my web projects
Some of non-web my projects
What inspires me




                   A-Nerve by CuteCircuit
The Third Industrial Revolution




                                     From The Economist, April 2012




A number of remarkable technologies are converging: clever software,
 novel materials, more dexterous robots, new processes (notably 3D
printing) and a whole range of web-based services. The factory of the
     past was based on cranking out zillions of identical products.
    The factory of the future will focus on mass customisation.
Microcontrollers




                          Arduino

                                    MaKey MaKey


            Basic Stamp




1975: Microchip PIC
Hardware startups becoming viable




                                             Pebble Kickstarter campaign as of June 2012




              [The founder] also shared a photo of the
              first Pebble prototype using an Arduino and
              some similarly cobbled-together hardware.
              That was four years ago.


                                               via Slashgear
Looking at the hardware trends

• Small, yet mighty
• Multi-screen
• Always on
• $$$ ⇾ $




                                                    Project Glass by Google

                 Steve Mann - world’s first cyborg
...and the software trends




           Location, location, location.
            Context, context, context.
And how is this related to Android?

This talk will cover:
• External hardware integration
  with Android Open Accessory
• NFC for low-friction interactions
  (not related to mobile payments)
• Combining with Bluetooth
Professional Android Sensor Programming




           Disclaimer: I authored chapter 11 (NFC)
                   & co-authored 10 (AOA)
                         (more info here)



                       klab.ca/spotlightandroid
Android Open
 Accessory


    klab.ca/spotlightandroid
Android Open Accessory - Demo!




                 klab.ca/spotlightandroid
Android Development Kit (ADK)




                                            Arduino Mega ADK


                 klab.ca/spotlightandroid
More Android Development Kits!


                 SparkFun IOIO




                                                       Microchip PIC24F ADK


          ODroid ADK




                                 klab.ca/spotlightandroid
Basic firmware/sketch on Arduino ADK
Note: You can get a fully working but barebones Arduino ADK sketch here: iheartrobotics.com/2011/07/arduino-mega-adk-setup-notes.html

#include <Max3421e.h>
                                                                                               USB and USB host libraries
#include <Usb.h>
#include <AndroidAccessory.h>                                                                  Google-supplied C++ library
                                                                                               Create a new instance of the AndroidAccessory
AndroidAccessory acc("Manufacturer", "Model",
                     "Description", "1.0",
                     "http://www.android.com",
                     "0000000012345678");
void setup() {
                                                                                               Convenience method that simply calls the
  acc.powerOn();                                                                               powerOn() method in the Max3421e library.
}
void loop() {
  byte msg[0];                                                                                 Continually check for connection to Android app
  if (acc.isConnected()) {
    //send something to the Android app
    acc.write(msg, 1);                                                                         Create data that the Android app can read
    //or read something
    int len = acc.read(msg, sizeof(msg), 1);                                                   Read data from Android app into msg variable
  }
}
Accessory Filter Resource
In xml/accessory_filter.xml:

<resources>
  <usb-accessory
    manufacturer="Manufacturer"
    model="Model"                 Needs to match the Arduino sketch exactly
    version="1.0" />
</resources>
Android Manifest
In AndroidManifest.xml (3.1+):
<manifest ...>

   <uses-sdk android:minSdkVersion="12" />
   <uses-feature android:name="android.hardware.usb.accessory" />

   <application ...>
     <activity ...>

        <meta-data
          android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
          android:resource="@xml/accessory_filter" />
                                                                            From previous slide

        <intent-filter>
          <action
            android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/>
        </intent-filter>                                     Use intent filter to launch this activity
                                                                            when ADK is plugged in


     </activity>
   </application>

</manifest>
Activity
In the .java file for your Activity (3.1+):
import com.android.hardware.usb.UsbAccessory;
import com.android.hardware.usb.UsbManager;

//...

UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
UsbAccessory accessory =
    (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);

ParcelFileDescriptor fileDescriptor = manager.openAccessory(accessory);
FileDescriptor fd = fileDescriptor.getFileDescriptor();

FileInputStream inputStream = new FileInputStream(fd);
byte[] buffer = new byte[16384];
                                                            Read data from the Arduino
int ret = inputStream.read(buffer);                         via a FileInputStream


FileOutputStream outputStream = new FileOutputStream(fd);
mOutputStream.write(buffer);                                Write data to the Arduino
                                                            via a FileOutputStream
Project ideas

So what can you make with the Open Accessory APIs
and an Arduino?



     Things already
                      1+1=3
        available                         Super
     on your phone                    awesome stuff!
                        Electronics
                       components
                       you can add
Things already available on your phone


    accelerometer                                   touch screen




              GPS                                   camera



                                                    wifi/3G
    mass storage



    proximity/light                                  temperature sensor
          sensors




           microphone                              NFC




                        klab.ca/spotlightandroid
Electronics components you can add




            Electronics inputs and outputs using LittleBits as an example of various components




                           klab.ca/spotlightandroid
Super awesome stuff!




      Music Beta: “Now Playing” by Chris Juergen                      Aerogarden Monitor by Sam Steele 




                        Space Spheres by NASA                      Floating Sensor Project by UC Berkeley


                                        klab.ca/spotlightandroid
Why Open Accessories are “open”




• iOS developer fees: $99/yr.                  • Fill out zero forms to start
                                                   developing.
• Approval required to be in MFi
 program; must sign NDAs.                      • Pay nothing to Google -- now
                                                   or ever.
• Additional Apple licensing fees
 and 3rd party certification.                   • No approval process from
                                                   Google to go to market.
• Final product needs to be
 approved by Apple                             • USB connectors and drivers
                                                   are readily available.
• One supplier (Avent) produces
 the connectors.
                                klab.ca/spotlightandroid
Speaking of connectors...
Are there wireless ADKs?
                                                    Bluetooth Shields
             IOIO w/
USB Bluetooth dongle




                                         Coming soon?
                                         Wifi Shield w/ integrated chip
                  Coming soon? ADK2012
NFC
(near field communications)




          klab.ca/spotlightandroid
What is NFC?
               NFC Scanner




                                  Radiowaves




                             NFC Sticker:
                             antenna and flash storage
How is it different than RFID?


                       Low frequency radio waves
                       can travel far distances.

                        13.56MHz = NFC

                       High frequency waves cannot.
                       NFC works within 10cm only.
How is it different than RFID?
Storage with RFID is also limited to simple IDs
versus the complex data NFC tags can hold.
NFC Forum    Popular Products   Operations    Rewrite Capabilities        Available Memory              Communication Price Range
Type         of This Type       Specifications                                                           Speed         (price per unit)

1            Broadcom Topaz     ISO 14443A      User rewritable; can be   96 bytes, expandable to 2KB   106kbit/s         Low
                                                marked as read-only by                                                    (~$1-2 USD)
                                                user

2            MIFARE             ISO 14443A      User rewritable; can be   48 bytes, 144 bytes is        106kbit/s         Low
             UltraLight                         marked as read-only by    common, expandable to 2KB                       (~$1-2 USD)
                                                user

3            Sony FeliCa        JIS X 6319-4    Manufacture pre-          variable, theoretical 1MB     212kbit/s or      High
                                                configured to be read-                                   424kbit/s         (~$8-10 USD or
                                                only or re-writable.                                                      higher)

4            NXP DESFire, NXP ISO 14443A,       Manufacture pre-          4KBfor DESFire, up to         Up to 424kbit/s   Medium-High
             SmartFX          ISO 14443B        configured to be read-     32KBfor SmartFX                                 (~$3-4 USD)
                                                only or rewritable.


MIFARE       Operations Specifications           Rewrite Capabilities      Available Memory              Communicatio      Price Range
Type                                                                                                    n Speed           (price per unit)

Classic 1K   ISO 14443A compatible, but NDEF    User rewritable; only     752 bytes                     106kbit/s         Low
             is formatted using a proprietary   manufacturer can mark                                                     (~$1 USD)
             protocol                           as read-only

Classic 4K   ISO 14443A compatible, but NDEF    User rewritable; only     3440 bytes                    106kbit/s         Low-Medium
             is formatted using a proprietary   manufacturer can mark                                                     (~$2 USD)
             protocol                           as read-only
NFC - Demo!




              klab.ca/spotlightandroid
Android Manifest
In AndroidManifest.xml (4.0+):
<manifest ...>

   <uses-sdk android:minSdkVersion="10" />
   <uses-feature android:name="android.hardware.nfc" android:required="true" />
   <uses-permission android:name="android.permission.NFC" />

   <application ...>
     <activity ...>

        <intent-filter>
          <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="text/plain" />
                                                             Could be custom MIME Type like:
        </intent-filter>                                     application/root.gast.playground.nfc


     </activity>
   </application>

</manifest>
Activity - Reacting to NFC scans
In the .java file for your Activity:
import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcEvent;

//...

NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
Boolean nfcEnabled = mNfcAdapter.isEnabled();
                                                                Give priority to the foreground
mNfcAdapter.enableForegroundDispatch(this,                      activity to receive NFC scan intents.

                         mNfcPendingIntent, mReadTagFilters, null);
                                                           Enable Android Beam for peer-to-peer
mNfcAdapter.setNdefPushMessageCallback(this,this);
Activity - Formatting to NDEF Format
In the .java file for your Activity:
import     android.nfc.NdefMessage;
import     android.nfc.NdefRecord;
import     android.nfc.tech.Ndef;
import     android.nfc.tech.NdefFormatable;
//...

// get the values from the form's text fields:
Editable nameField = mName.getText();
JSONObject computerSpecs = new JSONObject();                    JSON for readability,
                                                                not performance
computerSpecs.put("name", nameField);
String data = computerSpecs.toString();

// create a new NDEF record w/ NDEF message using the app's custom MIME type:
String mimeType = "application/root.gast.playground.nfc";         Unique to your app
byte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8"));
byte[] dataBytes = data.getBytes(Charset.forName("UTF-8"));
byte[] id = new byte[0];
NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
            mimeBytes, id, dataBytes);                            Not hard at all!

NdefMessage m = new NdefMessage(new NdefRecord[] { record });
Activity - Reading NDEF Format
In the .java file for your Activity:
import android.nfc.Tag;
//...


Parcelable[] rawMsgs =
      intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

NdefMessage[] msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
  msgs[i] = (NdefMessage) rawMsgs[i];
}
NdefRecord record = msgs[0].getRecords()[0];
                                                           The info you wanted.
byte[] payload = record.getPayload();                      (e.g. string or json)
A case for NFC

• Create low friction interactions
• Augment physical objects (even offline)
• Make your software app more tangible
• Engage others to share and connect
• Increase the viralness of your app
• Possibility to be platform agnostic

                    klab.ca/spotlightandroid
Mobile OS support for NFC




                Chart updated for Sept 27, 2012




                   klab.ca/spotlightandroid
Don’t worry, this isn’t Apple bashing...

  Hey! What                                    By touching
did you just do                                 phones?
     there?




                   Oh, I just sent
                   him a playlist.


                    klab.ca/spotlightandroid
Thank you!
 Oh, and check out some upcoming Arduino workshops!
    Sign up for mailing list on karma-laboratory.com.




         Pearl Chen                                     Google+:   klab.ca/+
pearl@karma-laboratory.com                              Twitter:   @PearlChen




                             klab.ca/spotlightandroid

Mais conteúdo relacionado

Semelhante a Better With Friends: Android+NFC+Arduino

Creating mobile apps with Cordova for iOS, Android and BlackBerry 10
Creating mobile apps with Cordova for iOS, Android and BlackBerry 10Creating mobile apps with Cordova for iOS, Android and BlackBerry 10
Creating mobile apps with Cordova for iOS, Android and BlackBerry 10Demian Borba
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentLiving Online
 
Internet of Things Conference - Bogor city
Internet of Things Conference - Bogor cityInternet of Things Conference - Bogor city
Internet of Things Conference - Bogor cityAndri Yadi
 
Android deep dive
Android deep diveAndroid deep dive
Android deep diveAnuSahniNCI
 
Programming The Real World
Programming The Real WorldProgramming The Real World
Programming The Real Worldpauldeng
 
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016Benjamin Cabé
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspectiveGunjan Kumar
 
Android in Netbooks
Android in NetbooksAndroid in Netbooks
Android in NetbooksMike Demler
 
Microsoft IT Academy Summit 2011
Microsoft IT Academy Summit 2011Microsoft IT Academy Summit 2011
Microsoft IT Academy Summit 2011Lee Stott
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyMike Hagedorn
 
Building Better IoT Applications without Servers
Building Better IoT Applications without ServersBuilding Better IoT Applications without Servers
Building Better IoT Applications without ServersIan Massingham
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020 Bogusz Jelinski
 
Android – As a tool of innovation
Android – As a tool of innovation Android – As a tool of innovation
Android – As a tool of innovation Pallab Sarkar
 
Internet of things - The Present & The Future
Internet of things - The Present & The FutureInternet of things - The Present & The Future
Internet of things - The Present & The Futureiotians
 

Semelhante a Better With Friends: Android+NFC+Arduino (20)

Android tutorial1
Android tutorial1Android tutorial1
Android tutorial1
 
Android Things - The IoT platform for everyone.
Android Things - The IoT platform for everyone. Android Things - The IoT platform for everyone.
Android Things - The IoT platform for everyone.
 
Creating mobile apps with Cordova for iOS, Android and BlackBerry 10
Creating mobile apps with Cordova for iOS, Android and BlackBerry 10Creating mobile apps with Cordova for iOS, Android and BlackBerry 10
Creating mobile apps with Cordova for iOS, Android and BlackBerry 10
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) Development
 
Internet of Things Conference - Bogor city
Internet of Things Conference - Bogor cityInternet of Things Conference - Bogor city
Internet of Things Conference - Bogor city
 
Android deep dive
Android deep diveAndroid deep dive
Android deep dive
 
Programming The Real World
Programming The Real WorldProgramming The Real World
Programming The Real World
 
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016
The Right Tools for IoT Developers – Dan Gross @ Eclipse IoT Day ThingMonk 2016
 
Android by LAlitha
Android by LAlithaAndroid by LAlitha
Android by LAlitha
 
Getting started with android dev and test perspective
Getting started with android   dev and test perspectiveGetting started with android   dev and test perspective
Getting started with android dev and test perspective
 
Android in Netbooks
Android in NetbooksAndroid in Netbooks
Android in Netbooks
 
Microsoft IT Academy Summit 2011
Microsoft IT Academy Summit 2011Microsoft IT Academy Summit 2011
Microsoft IT Academy Summit 2011
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
Building Better IoT Applications without Servers
Building Better IoT Applications without ServersBuilding Better IoT Applications without Servers
Building Better IoT Applications without Servers
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Android – As a tool of innovation
Android – As a tool of innovation Android – As a tool of innovation
Android – As a tool of innovation
 
Internet of things - The Present & The Future
Internet of things - The Present & The FutureInternet of things - The Present & The Future
Internet of things - The Present & The Future
 
Android
Android Android
Android
 
Android
AndroidAndroid
Android
 

Último

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Último (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Better With Friends: Android+NFC+Arduino

  • 1. NFC Bluetooth Open Accessory Better with Friends (Or "Android: The Loveable Mobile Platform That Plays Well with External Devices") Pearl Chen Google+: klab.ca/+ pearl@karma-laboratory.com Twitter: @PearlChen klab.ca/spotlightandroid
  • 2. The future is already here — it's just not very evenly distributed. William Gibson klab.ca/spotlightandroid
  • 3. About me Some Comp Sci classes back there too ( Illustration created using modified output from visualize.me and my LinkedIn profile. )
  • 4. Some of my web projects
  • 5. Some of non-web my projects
  • 6. What inspires me A-Nerve by CuteCircuit
  • 7. The Third Industrial Revolution From The Economist, April 2012 A number of remarkable technologies are converging: clever software, novel materials, more dexterous robots, new processes (notably 3D printing) and a whole range of web-based services. The factory of the past was based on cranking out zillions of identical products. The factory of the future will focus on mass customisation.
  • 8. Microcontrollers Arduino MaKey MaKey Basic Stamp 1975: Microchip PIC
  • 9. Hardware startups becoming viable Pebble Kickstarter campaign as of June 2012 [The founder] also shared a photo of the first Pebble prototype using an Arduino and some similarly cobbled-together hardware. That was four years ago. via Slashgear
  • 10. Looking at the hardware trends • Small, yet mighty • Multi-screen • Always on • $$$ ⇾ $ Project Glass by Google Steve Mann - world’s first cyborg
  • 11. ...and the software trends Location, location, location. Context, context, context.
  • 12. And how is this related to Android? This talk will cover: • External hardware integration with Android Open Accessory • NFC for low-friction interactions (not related to mobile payments) • Combining with Bluetooth
  • 13. Professional Android Sensor Programming Disclaimer: I authored chapter 11 (NFC) & co-authored 10 (AOA) (more info here) klab.ca/spotlightandroid
  • 14. Android Open Accessory klab.ca/spotlightandroid
  • 15. Android Open Accessory - Demo! klab.ca/spotlightandroid
  • 16. Android Development Kit (ADK) Arduino Mega ADK klab.ca/spotlightandroid
  • 17. More Android Development Kits! SparkFun IOIO Microchip PIC24F ADK ODroid ADK klab.ca/spotlightandroid
  • 18. Basic firmware/sketch on Arduino ADK Note: You can get a fully working but barebones Arduino ADK sketch here: iheartrobotics.com/2011/07/arduino-mega-adk-setup-notes.html #include <Max3421e.h> USB and USB host libraries #include <Usb.h> #include <AndroidAccessory.h> Google-supplied C++ library Create a new instance of the AndroidAccessory AndroidAccessory acc("Manufacturer", "Model",                      "Description", "1.0",                      "http://www.android.com",                      "0000000012345678"); void setup() { Convenience method that simply calls the acc.powerOn(); powerOn() method in the Max3421e library. } void loop() { byte msg[0]; Continually check for connection to Android app   if (acc.isConnected()) {     //send something to the Android app acc.write(msg, 1); Create data that the Android app can read     //or read something int len = acc.read(msg, sizeof(msg), 1); Read data from Android app into msg variable   } }
  • 19. Accessory Filter Resource In xml/accessory_filter.xml: <resources> <usb-accessory manufacturer="Manufacturer" model="Model" Needs to match the Arduino sketch exactly version="1.0" /> </resources>
  • 20. Android Manifest In AndroidManifest.xml (3.1+): <manifest ...> <uses-sdk android:minSdkVersion="12" /> <uses-feature android:name="android.hardware.usb.accessory" /> <application ...> <activity ...> <meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" android:resource="@xml/accessory_filter" /> From previous slide <intent-filter> <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/> </intent-filter> Use intent filter to launch this activity when ADK is plugged in </activity> </application> </manifest>
  • 21. Activity In the .java file for your Activity (3.1+): import com.android.hardware.usb.UsbAccessory; import com.android.hardware.usb.UsbManager; //... UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE); UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY); ParcelFileDescriptor fileDescriptor = manager.openAccessory(accessory); FileDescriptor fd = fileDescriptor.getFileDescriptor(); FileInputStream inputStream = new FileInputStream(fd); byte[] buffer = new byte[16384]; Read data from the Arduino int ret = inputStream.read(buffer); via a FileInputStream FileOutputStream outputStream = new FileOutputStream(fd); mOutputStream.write(buffer); Write data to the Arduino via a FileOutputStream
  • 22. Project ideas So what can you make with the Open Accessory APIs and an Arduino? Things already 1+1=3 available Super on your phone awesome stuff! Electronics components you can add
  • 23. Things already available on your phone accelerometer touch screen GPS camera wifi/3G mass storage proximity/light temperature sensor sensors microphone NFC klab.ca/spotlightandroid
  • 24. Electronics components you can add Electronics inputs and outputs using LittleBits as an example of various components klab.ca/spotlightandroid
  • 25. Super awesome stuff! Music Beta: “Now Playing” by Chris Juergen  Aerogarden Monitor by Sam Steele  Space Spheres by NASA Floating Sensor Project by UC Berkeley klab.ca/spotlightandroid
  • 26. Why Open Accessories are “open” • iOS developer fees: $99/yr. • Fill out zero forms to start developing. • Approval required to be in MFi program; must sign NDAs. • Pay nothing to Google -- now or ever. • Additional Apple licensing fees and 3rd party certification. • No approval process from Google to go to market. • Final product needs to be approved by Apple • USB connectors and drivers are readily available. • One supplier (Avent) produces the connectors. klab.ca/spotlightandroid
  • 28. Are there wireless ADKs? Bluetooth Shields IOIO w/ USB Bluetooth dongle Coming soon? Wifi Shield w/ integrated chip Coming soon? ADK2012
  • 29. NFC (near field communications) klab.ca/spotlightandroid
  • 30. What is NFC? NFC Scanner Radiowaves NFC Sticker: antenna and flash storage
  • 31. How is it different than RFID? Low frequency radio waves can travel far distances. 13.56MHz = NFC High frequency waves cannot. NFC works within 10cm only.
  • 32. How is it different than RFID? Storage with RFID is also limited to simple IDs versus the complex data NFC tags can hold. NFC Forum Popular Products Operations Rewrite Capabilities Available Memory Communication Price Range Type of This Type Specifications Speed (price per unit) 1 Broadcom Topaz ISO 14443A User rewritable; can be 96 bytes, expandable to 2KB 106kbit/s Low marked as read-only by (~$1-2 USD) user 2 MIFARE ISO 14443A User rewritable; can be 48 bytes, 144 bytes is 106kbit/s Low UltraLight marked as read-only by common, expandable to 2KB (~$1-2 USD) user 3 Sony FeliCa JIS X 6319-4 Manufacture pre- variable, theoretical 1MB 212kbit/s or High configured to be read- 424kbit/s (~$8-10 USD or only or re-writable. higher) 4 NXP DESFire, NXP ISO 14443A, Manufacture pre- 4KBfor DESFire, up to Up to 424kbit/s Medium-High SmartFX ISO 14443B configured to be read- 32KBfor SmartFX (~$3-4 USD) only or rewritable. MIFARE Operations Specifications Rewrite Capabilities Available Memory Communicatio Price Range Type n Speed (price per unit) Classic 1K ISO 14443A compatible, but NDEF User rewritable; only 752 bytes 106kbit/s Low is formatted using a proprietary manufacturer can mark (~$1 USD) protocol as read-only Classic 4K ISO 14443A compatible, but NDEF User rewritable; only 3440 bytes 106kbit/s Low-Medium is formatted using a proprietary manufacturer can mark (~$2 USD) protocol as read-only
  • 33. NFC - Demo! klab.ca/spotlightandroid
  • 34. Android Manifest In AndroidManifest.xml (4.0+): <manifest ...> <uses-sdk android:minSdkVersion="10" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> <uses-permission android:name="android.permission.NFC" /> <application ...> <activity ...> <intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> Could be custom MIME Type like: </intent-filter> application/root.gast.playground.nfc </activity> </application> </manifest>
  • 35. Activity - Reacting to NFC scans In the .java file for your Activity: import android.nfc.NfcAdapter; import android.nfc.NfcAdapter.CreateNdefMessageCallback; import android.nfc.NfcEvent; //... NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this); Boolean nfcEnabled = mNfcAdapter.isEnabled(); Give priority to the foreground mNfcAdapter.enableForegroundDispatch(this, activity to receive NFC scan intents. mNfcPendingIntent, mReadTagFilters, null); Enable Android Beam for peer-to-peer mNfcAdapter.setNdefPushMessageCallback(this,this);
  • 36. Activity - Formatting to NDEF Format In the .java file for your Activity: import android.nfc.NdefMessage; import android.nfc.NdefRecord; import android.nfc.tech.Ndef; import android.nfc.tech.NdefFormatable; //... // get the values from the form's text fields: Editable nameField = mName.getText(); JSONObject computerSpecs = new JSONObject(); JSON for readability, not performance computerSpecs.put("name", nameField); String data = computerSpecs.toString(); // create a new NDEF record w/ NDEF message using the app's custom MIME type: String mimeType = "application/root.gast.playground.nfc"; Unique to your app byte[] mimeBytes = mimeType.getBytes(Charset.forName("UTF-8")); byte[] dataBytes = data.getBytes(Charset.forName("UTF-8")); byte[] id = new byte[0]; NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, id, dataBytes); Not hard at all! NdefMessage m = new NdefMessage(new NdefRecord[] { record });
  • 37. Activity - Reading NDEF Format In the .java file for your Activity: import android.nfc.Tag; //... Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage[] msgs = new NdefMessage[rawMsgs.length]; for (int i = 0; i < rawMsgs.length; i++) { msgs[i] = (NdefMessage) rawMsgs[i]; } NdefRecord record = msgs[0].getRecords()[0]; The info you wanted. byte[] payload = record.getPayload(); (e.g. string or json)
  • 38. A case for NFC • Create low friction interactions • Augment physical objects (even offline) • Make your software app more tangible • Engage others to share and connect • Increase the viralness of your app • Possibility to be platform agnostic klab.ca/spotlightandroid
  • 39. Mobile OS support for NFC Chart updated for Sept 27, 2012 klab.ca/spotlightandroid
  • 40. Don’t worry, this isn’t Apple bashing... Hey! What By touching did you just do phones? there? Oh, I just sent him a playlist. klab.ca/spotlightandroid
  • 41. Thank you! Oh, and check out some upcoming Arduino workshops! Sign up for mailing list on karma-laboratory.com. Pearl Chen Google+: klab.ca/+ pearl@karma-laboratory.com Twitter: @PearlChen klab.ca/spotlightandroid