Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Things - The IoT platform for everyone - App Builders Switzerland

Android Things - The IoT platform for everyone - App Builders Switzerland

Presented at App Builders Switzerland - 25 April 2017

Internet Of Things on Android!

Rebecca Franks

April 25, 2017
Tweet

More Decks by Rebecca Franks

Other Decks in Technology

Transcript

  1. The IoT platform for everyone
    #appbuilders17 @riggaroo

    View full-size slide

  2. Android Engineering Lead at Dynamic Visual Technologies
    Google Developer Expert for Android & Internet of Things
    riggaroo.co.za
    @riggaroo
    Rebecca Franks

    View full-size slide

  3. What is Android Things?

    View full-size slide

  4. Android Things is an extension of the Android
    platform for IoT and embedded devices.

    View full-size slide

  5. Cameras

    Gateways

    HVAC Control

    Smart Meters
    Point of Sale

    Inventory Control

    Interactive Ads

    Vending Machines
    Security Systems

    Smart Doorbells

    Routers

    Energy Monitors
    Asset Tracking

    Fleet Management

    Driver Assist

    Predictive Service
    Ideal for powerful, intelligent devices that need to be
    secure.

    View full-size slide

  6. Android Things for Developers

    View full-size slide

  7. How is Android Things different?
    Android
    Studio
    Android SDKs
    & Developer
    Tools
    Firebase
    Libraries
    Google Cloud
    Platform SDKs
    Any other
    compatible
    Android/Java
    libraries...

    View full-size slide

  8. Development Boards

    View full-size slide

  9. Displays are Optional

    View full-size slide

  10. Consider Alternate UI

    View full-size slide

  11. Cons
    ● Only in developer preview
    ● Known issues - hardware graphics acceleration is off etc
    ● Weave not yet available for Android Things
    ● Very new platform – not many samples
    ● A bit slow for things that need precise timing
    ● Not open source yet (?)

    View full-size slide

  12. Electronics for Software Developers

    View full-size slide

  13. Electronic Components
    Breadboard - Construction base for
    prototyping electronics
    Jumper Wire - Used to interconnect the
    components of a breadboard

    View full-size slide

  14. LEDs - Emits visible light when an
    electric current passes through it
    Push Switches - Allows electricity
    to flow between its two contacts
    Electronic Components

    View full-size slide

  15. Resistor -Used to reduce current flow
    Source: http://www.electronicshub.org/resistor-color-code/
    Electronic Components
    and many more...

    View full-size slide

  16. Electronic Components
    Raspberry Pi Rainbow HAT
    • Seven APA102 multicolor LEDs
    • Four 14-segment alphanumeric displays (green LEDs)
    • HT16K33 display driver chip
    • Three capacitive touch buttons
    • Atmel QT1070 capacitive touch driver chip
    • Blue, green, and red LEDs
    • BMP280 temperature and pressure sensor
    • Piezo buzzer
    • Breakout pins for servo, 12C, SPI, and UART (all 3v3)

    View full-size slide

  17. Ohm’s Law
    The current through a conductor
    between two points is directly
    proportional to the voltage across
    the two points.
    V = I * R
    V is Voltage (volts)
    I is Current (amps)
    R is Resistance (ohms)
    I = 0.023A
    V = 5V
    R = 5V / 0.023A
    R = ± 217 ohms

    View full-size slide

  18. Pinout Diagrams

    View full-size slide

  19. Hardware Integration on Android Things
    GPIO PWM
    I2C SPI
    UART
    Peripheral I/O
    COMPLEX
    EASY!
    https://github.com/androidthings/contrib-drivers
    Button PWM Servo
    RGB LED
    Strip
    GPS
    Temperature
    Sensor
    Capacitive
    touch buttons
    Github - Peripheral Driver Library

    View full-size slide

  20. Let’s build an App

    View full-size slide

  21. Circuit Setup – LED button control

    View full-size slide

  22. In case of emergency

    View full-size slide

  23. ● A Raspberry Pi 3 or alternative - Running Android Things
    ● Create standard project in Android Studio
    ● Add to app level build.gradle:
    provided 'com.google.android.things:androidthings:...'
    Getting Started

    View full-size slide




  24. ...









    AndroidManifest.xml

    View full-size slide

  25. Button button = new Button("BCM6", Button.LogicState.PRESSED_WHEN_LOW);

    button.setOnButtonEventListener(new Button.OnButtonEventListener() {

    @Override

    public void onButtonEvent(final Button button, final boolean pressed) {
    //...

    Log.i(TAG, "Button value changed:" + pressed);

    ledGpio.setValue(pressed);
    }
    });
    Button Press
    compile 'com.google.android.things.contrib:driver-button:0.2'

    View full-size slide

  26. //get access to the pin

    PeripheralManagerService service = new PeripheralManagerService();

    ledGpio = service.openGpio("BCM6");

    ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);


    ledGpio.setValue(true);


    //remember to close the peripheral

    ledGpio.close();
    Turn on an LED

    View full-size slide

  27. Turn it on or off using Firebase Realtime DB
    FirebaseDatabase.getInstance().getReference("ledKitchen")

    .addValueEventListener(new ValueEventListener() {

    @Override

    public void onDataChange(final DataSnapshot dataSnapshot) {

    Boolean value = (Boolean) dataSnapshot.getValue();

    ledGpio.setValue(value);

    //.. handle exceptions

    }

    //..

    });

    View full-size slide

  28. Other Examples

    View full-size slide

  29. https://github.com/riggaroo/android-things-distributed-piano
    Distributed Piano - Google Nearby API

    View full-size slide

  30. https://github.com/riggaroo/android-things-electricity-monitor
    Firebase Realtime
    Database
    Electricity Monitor

    View full-size slide

  31. final DatabaseReference onlineRef = firebaseDatabase.child(".info/connected");
    final DatabaseReference isPowerOnRef = firebaseDatabase.child("/online");
    onlineRef.addValueEventListener(new ValueEventListener() {

    });
    @Override
    public void onDataChange(final DataSnapshot dataSnapshot) {
    if (dataSnapshot.getValue(Boolean.class)) {
    isPowerOnRef.setValue(true);
    isPowerOnRef.onDisconnect().setValue(false);
    }
    }
    Electricity Monitor – Companion App – onDisconnect()

    View full-size slide

  32. Electricity Monitor – Cloud Functions on Firebase
    const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    exports.sendPowerNotification = functions.database.ref("/online").onWrite((event) => {
    });
    const data = event.data;
    if (!data.changed()) {
    return;
    }
    const onOff = data.val() ? "on": "off";
    const payload = {
    notification: {
    body: `Your electricity is now ${onOff}`
    }
    };
    return admin.messaging().sendToTopic("Power_Notifications", payload, ..);

    View full-size slide

  33. https://github.com/androidthings/sample-tensorflow-imageclassifier
    TensorFlow Offline Image Classifier

    View full-size slide

  34. Rebecca Franks
    riggaroo.co.za
    @riggaroo
    Google's IoT Developers Community
    https://g.co/iotdev
    Google's IoT Solutions
    https://iot.google.com
    Android Things SDK
    https://developer.android.com/things

    View full-size slide

  35. ● https://www.myelectronicslab.com/tutorial/raspberry-pi-3-gpio-model-b-
    block-pinout/
    ● https://developers.google.com/weave/
    ● https://techcrunch.com/2015/10/24/why-iot-security-is-so-critical/
    ● https://github.com/androidthings/sample-simplepio/
    ● https://developer.android.com/things/index.html
    ● https://github.com/riggaroo/android-things-electricity-monitor
    ● https://github.com/riggaroo/android-things-distributed-piano
    ● https://github.com/riggaroo/android-things-button-examples
    Links & References

    View full-size slide