SlideShare uma empresa Scribd logo
1 de 50
Baixar para ler offline
Android Things
Egor Andreevici
@EgorAnd
https://android-developers.googleblog.com/2016/12/announcing-googles-new-internet-of-things-platform-with-weave-an
d-android-things.html
● Build connected devices using familiar tools, such as Android SDK and
Android Studio
● Google Play Services & Google Cloud
● Flashable image + SDK (Developer Preview)
Android Things
Android Things Platform - https://developer.android.com/things/sdk/index.html
● Peripheral I/O API
○ GPIO, PWM, I2C, SPI, UART
● User Driver API
○ Inject hardware events into the framework
Things Support Library
● Missing core packages
○ e.g. ContactsContract, MediaStore, Settings etc.
● Displays are optional
● Subset of Google Play Services available
● No runtime permissions
● No notifications
Behavior Changes
Hardware: Turnkey Solutions
● Certified development boards
● SoMs (System-on-Modules)
○ SoC, RAM, Flash Storage, WiFi, Bluetooth etc.
● Board Support Package (BSP) managed by Google
Hardware
Supported boards - https://developer.android.com/things/hardware/developer-kits.html
Intel® Edison NXP Pico i.MX6UL Raspberry Pi 3
Coming soon - https://developer.android.com/things/hardware/developer-kits.html
Intel® Joule™ 570x NXP Argon i.MX6UL
Rainbow HAT - https://developer.android.com/things/hardware/developer-kits.html
● Hardware Attached on Top
○ Seven multicolor LEDs
○ Four 14-segment alphanumeric displays
○ Three capacitive touch buttons
○ Blue, green and red LEDs
○ Temperature and pressure sensor
○ Piezo buzzer
Rainbow HAT
Raspberry Pi 3 + Rainbow HAT:
Getting Started
● 8 Gb or larger SD card
● HDMI display + cable
● Ethernet cable
● SD card reader
Flashing the Image: Requirements
● Download and unzip the latest preview image
○ https://developer.android.com/things/preview/download.html
● Write the image to the SD card
○ Instructions for Linux, Mac and Windows
● Insert the SD card into the Raspberry Pi
Flashing the Image
Android Things Launcher
Connecting via ADB
$ adb connect <ip-address>
connected to <ip-address>:5555
or
$ adb connect Android.local
if host platform supports Multicast DNS
Connecting WiFi
$ adb shell am startservice 
-n com.google.wifisetup/.WifiSetupService 
-a WifiSetupService.Connect 
-e ssid <Network_SSID> 
-e passphrase <Network_Passcode>
Demo App
https://blog.egorand.me/making-rainbow-hat-work-with-the-android-things-2/
● Handle touch button clicks
● Change text on the alphanumeric display
● Play a melody using the buzzer
● Blink RGB leds along with the melody
Rainbow HAT Demo
https://www.youtube.com/watch?v=TErot2KaY6w
Declaring Dependencies
dependencies {
provided 'com.google.android.things:androidthings:0.1-devpreview'
compile 'com.google.android.things.contrib:driver-button:0.1'
compile 'com.google.android.things.contrib:driver-ht16k33:0.1'
compile 'com.google.android.things.contrib:driver-pwmspeaker:0.1'
...
}
app/build.gradle
Declaring Dependencies
dependencies {
provided 'com.google.android.things:androidthings:0.1-devpreview'
// compile 'com.google.android.things.contrib:driver-button:0.1'
// compile 'com.google.android.things.contrib:driver-ht16k33:0.1'
// compile 'com.google.android.things.contrib:driver-pwmspeaker:0.1'
compile 'com.google.android.things.contrib:driver-rainbowhat:0.1'
...
}
app/build.gradle
Creating Manifest
AndroidManifest.xml
<application ...>
<uses-library android:name="com.google.android.things"/>
…
</application>
Creating an Activity
RainbowHATDemoActivity.kt
class RainbowHATDemoActivity : Activity() {
…
}
Declaring the Activity in Manifest
AndroidManifest.xml
<activity android:name=".RainbowHATDemoActivity">
<!-- Launch activity from Android Studio -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
…
<activity>
Declaring the Activity in Manifest
AndroidManifest.xml
<activity android:name=".RainbowHATDemoActivity">
…
<!-- Launch activity automatically on boot -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.IOT_LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<activity>
Instantiating driver classes
RainbowHATDemoActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
buttons = Buttons()
display = Display()
buzzer = Buzzer()
leds = Leds()
...
}
Creating the Buttons class
Buttons.kt
class Buttons(private val buttonDrivers: List<ButtonInputDriver> = listOf(
registerButtonDriver(BUTTON_A_GPIO_PIN, KeyEvent.KEYCODE_A),
registerButtonDriver(BUTTON_B_GPIO_PIN, KeyEvent.KEYCODE_B),
registerButtonDriver(BUTTON_C_GPIO_PIN, KeyEvent.KEYCODE_C))) {
…
}
Creating the Buttons class
Buttons.kt
val BUTTON_A_GPIO_PIN = "BCM21"
val BUTTON_B_GPIO_PIN = "BCM20"
val BUTTON_C_GPIO_PIN = "BCM16"
Raspberry Pi 3 + Rainbow HAT Pinout - https://pinout.xyz/pinout/rainbow_hat
Creating the Buttons class
Buttons.kt
private fun registerButtonDriver(pin: String,
keycode: Int): ButtonInputDriver {
val driver = ButtonInputDriver(
pin = pin,
logicLevel = Button.LogicState.PRESSED_WHEN_LOW,
keycode = keycode)
driver.register()
return driver
}
Creating the Display class
Display.kt
class Display(private val display: AlphanumericDisplay =
AlphanumericDisplay(DISPLAY_I2C_BUS)) {
init {
display.setEnabled(true)
display.clear()
}
…
}
Creating the Display class
Display.kt
fun displayMessage(message: String) {
display.display(message)
}
Processing button events
RainbowHATDemoActivity.kt
val MESSAGES = mapOf(
KeyEvent.KEYCODE_A to "AHOY",
KeyEvent.KEYCODE_B to "YARR",
KeyEvent.KEYCODE_C to "GROG")
Processing button events
RainbowHATDemoActivity.kt
override fun onKeyUp(keyCode: Int, event: KeyEvent?) = when (keyCode) {
in MESSAGES.keys -> {
display.displayMessage(MESSAGES[keyCode]!!)
true
}
else -> super.onKeyUp(keyCode, event)
}
Creating the Buzzer class
Buzzer.kt
class Buzzer(private val speaker: Speaker =
Speaker(SPEAKER_PWM_PIN) {
…
}
Creating the Buzzer class
Buzzer.kt
fun play(frequency: Double) {
speaker.play(frequency)
}
fun stop() {
speaker.stop()
}
Creating the Buzzer class
Buzzer.kt
init {
stopRunnable = Runnable { stop() }
}
fun play(frequency: Double, duration: Double) {
speaker.play(frequency)
stopHandler.postDelayed(stopRunnable, duration.toLong())
}
Creating the Leds class
Leds.kt
class Leds(peripheralManagerService: PeripheralManagerService =
PeripheralManagerService()) {
…
}
Creating the Leds class
Leds.kt
private val leds: List<Gpio>
init {
leds = listOf(
openGpio(peripheralManagerService, LED_RED_GPIO_PIN),
openGpio(peripheralManagerService, LED_GREEN_GPIO_PIN),
openGpio(peripheralManagerService, LED_BLUE_GPIO_PIN))
}
Creating the Leds class
Leds.kt
private fun openGpio(service: PeripheralManagerService,
pin: String): Gpio {
val led = service.openGpio(pin)
led.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW)
return led
}
Creating the Leds class
Leds.kt
fun setLed(led: Int, on: Boolean) = with(leds[led]) {
value = on
}
fun toggleLed(led: Int) = with(leds[led]) {
value = !value
}
Integrating Buzzer and Leds
RainbowHATDemoActivity.kt
private fun playMelodyWithLeds() {
playbackRunnable = Runnable {
buzzer.play(NOTES[noteIndex].toDouble(), DURATIONS[timeIndex] * 0.8)
leds.setLed(Leds.LEDS[ledIndex], on = true)
leds.setLed(Leds.LEDS[prevIndex(ledIndex, Leds.LEDS.size)], on = false)
if (noteIndex == NOTES.size - 1) {
// close
} else {
playHandler.postDelayed(playbackRunnable, DURATIONS[timeIndex].toLong())
// increment indices
}
}
playHandler.post(playbackRunnable)
}
Integrating Buzzer and Leds
RainbowHATDemoActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
playMelodyWithLeds()
}
Closing resources
RainbowHATDemoActivity.kt
override fun onDestroy() {
...
arrayOf(leds, buttons, buzzer, display).forEach(Closeable::close)
super.onDestroy()
}
● Android Things - https://developer.android.com/things/index.html
● Samples - https://developer.android.com/things/sdk/samples.html
● Driver Library - https://github.com/androidthings/contrib-drivers
Where do we go from here?
What will you build?
Thanks!
Egor Andreevici
Software Developer at 1&1
@EgorAnd
+EgorAndreevich
https://blog.egorand.me

Mais conteúdo relacionado

Mais procurados

SECON'2017, Кардава Звиад, Android Things + Google Weave
SECON'2017, Кардава Звиад, Android Things + Google WeaveSECON'2017, Кардава Звиад, Android Things + Google Weave
SECON'2017, Кардава Звиад, Android Things + Google Weave
SECON
 

Mais procurados (20)

Android Things Latest News / Aug 25, 2017
Android Things Latest News / Aug 25, 2017Android Things Latest News / Aug 25, 2017
Android Things Latest News / Aug 25, 2017
 
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
Android Things, from mobile apps to physical world by Giovanni Di Gialluca an...
 
Android Things, from mobile apps to physical world
Android Things, from mobile apps to physical worldAndroid Things, from mobile apps to physical world
Android Things, from mobile apps to physical world
 
Raspberry Pi 2 + Windows 10 IoT Core + Node.js
Raspberry Pi 2 + Windows 10 IoT Core + Node.jsRaspberry Pi 2 + Windows 10 IoT Core + Node.js
Raspberry Pi 2 + Windows 10 IoT Core + Node.js
 
Intel ndk - a few Benchmarks
Intel ndk - a few BenchmarksIntel ndk - a few Benchmarks
Intel ndk - a few Benchmarks
 
Go Green - Save Power
Go Green - Save PowerGo Green - Save Power
Go Green - Save Power
 
Hack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGSHack the Real World with ANDROID THINGS
Hack the Real World with ANDROID THINGS
 
Myths of Angular 2: What Angular Really Is
Myths of Angular 2: What Angular Really IsMyths of Angular 2: What Angular Really Is
Myths of Angular 2: What Angular Really Is
 
SECON'2017, Кардава Звиад, Android Things + Google Weave
SECON'2017, Кардава Звиад, Android Things + Google WeaveSECON'2017, Кардава Звиад, Android Things + Google Weave
SECON'2017, Кардава Звиад, Android Things + Google Weave
 
Windows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sampleWindows 10 IoT Core, a real sample
Windows 10 IoT Core, a real sample
 
Android Open Accessory APIs
Android Open Accessory APIsAndroid Open Accessory APIs
Android Open Accessory APIs
 
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKAndroid Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADK
 
Project Ara
Project AraProject Ara
Project Ara
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
 
"Android Things + Google Weave" Кардава Звиад, Voximplant, Google Developer E...
"Android Things + Google Weave" Кардава Звиад, Voximplant, Google Developer E..."Android Things + Google Weave" Кардава Звиад, Voximplant, Google Developer E...
"Android Things + Google Weave" Кардава Звиад, Voximplant, Google Developer E...
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoT
 
Hacking with the Raspberry Pi and Windows 10 IoT Core
Hacking with the Raspberry Pi and Windows 10 IoT CoreHacking with the Raspberry Pi and Windows 10 IoT Core
Hacking with the Raspberry Pi and Windows 10 IoT Core
 
Project Ara
Project AraProject Ara
Project Ara
 
Mobile + Cloud + IoT = Future
Mobile + Cloud + IoT = FutureMobile + Cloud + IoT = Future
Mobile + Cloud + IoT = Future
 
Embedded Android Workshop with Lollipop
Embedded Android Workshop with LollipopEmbedded Android Workshop with Lollipop
Embedded Android Workshop with Lollipop
 

Semelhante a Android Things

Звиад Кардава "Android Things + Google Weave"
Звиад Кардава "Android Things + Google Weave" Звиад Кардава "Android Things + Google Weave"
Звиад Кардава "Android Things + Google Weave"
IT Event
 
Introduction to BlackBerry 10 NDK for Game Developers.
Introduction to BlackBerry 10 NDK for Game Developers.Introduction to BlackBerry 10 NDK for Game Developers.
Introduction to BlackBerry 10 NDK for Game Developers.
ardiri
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2D
creagamers
 
android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginner
Ajailal Parackal
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
NgLQun
 

Semelhante a Android Things (20)

Developing for Google Glass
Developing for Google GlassDeveloping for Google Glass
Developing for Google Glass
 
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
Jak vyvinout úspěšnou aplikaci pro Google Glass (Martin Pelant, eMan)
 
Звиад Кардава "Android Things + Google Weave"
Звиад Кардава "Android Things + Google Weave" Звиад Кардава "Android Things + Google Weave"
Звиад Кардава "Android Things + Google Weave"
 
Introduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google CloudIntroduction to Cloud Computing with Google Cloud
Introduction to Cloud Computing with Google Cloud
 
Introduction to BlackBerry 10 NDK for Game Developers.
Introduction to BlackBerry 10 NDK for Game Developers.Introduction to BlackBerry 10 NDK for Game Developers.
Introduction to BlackBerry 10 NDK for Game Developers.
 
Node in Production at Aviary
Node in Production at AviaryNode in Production at Aviary
Node in Production at Aviary
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScript
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2D
 
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
Android Things, from mobile apps to physical world - Stefano Sanna - Giovanni...
 
Android game development
Android game developmentAndroid game development
Android game development
 
android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginner
 
KSS Session and Tech Talk-2019 on IOT.pptx
KSS Session and Tech Talk-2019 on IOT.pptxKSS Session and Tech Talk-2019 on IOT.pptx
KSS Session and Tech Talk-2019 on IOT.pptx
 
Developing AIR for Android with Flash Professional
Developing AIR for Android with Flash ProfessionalDeveloping AIR for Android with Flash Professional
Developing AIR for Android with Flash Professional
 
Google tv
Google tv Google tv
Google tv
 
Integrating Google Play Games
Integrating Google Play GamesIntegrating Google Play Games
Integrating Google Play Games
 
IoT on Raspberry Pi
IoT on Raspberry PiIoT on Raspberry Pi
IoT on Raspberry Pi
 
@Ionic native/google-maps
@Ionic native/google-maps@Ionic native/google-maps
@Ionic native/google-maps
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
Develop Mobile App Using Android Lollipop
Develop Mobile App Using Android LollipopDevelop Mobile App Using Android Lollipop
Develop Mobile App Using Android Lollipop
 

Último

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Último (20)

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

Android Things

  • 3. ● Build connected devices using familiar tools, such as Android SDK and Android Studio ● Google Play Services & Google Cloud ● Flashable image + SDK (Developer Preview) Android Things
  • 4. Android Things Platform - https://developer.android.com/things/sdk/index.html
  • 5. ● Peripheral I/O API ○ GPIO, PWM, I2C, SPI, UART ● User Driver API ○ Inject hardware events into the framework Things Support Library
  • 6. ● Missing core packages ○ e.g. ContactsContract, MediaStore, Settings etc. ● Displays are optional ● Subset of Google Play Services available ● No runtime permissions ● No notifications Behavior Changes
  • 8. ● Certified development boards ● SoMs (System-on-Modules) ○ SoC, RAM, Flash Storage, WiFi, Bluetooth etc. ● Board Support Package (BSP) managed by Google Hardware
  • 9. Supported boards - https://developer.android.com/things/hardware/developer-kits.html Intel® Edison NXP Pico i.MX6UL Raspberry Pi 3
  • 10. Coming soon - https://developer.android.com/things/hardware/developer-kits.html Intel® Joule™ 570x NXP Argon i.MX6UL
  • 11. Rainbow HAT - https://developer.android.com/things/hardware/developer-kits.html
  • 12. ● Hardware Attached on Top ○ Seven multicolor LEDs ○ Four 14-segment alphanumeric displays ○ Three capacitive touch buttons ○ Blue, green and red LEDs ○ Temperature and pressure sensor ○ Piezo buzzer Rainbow HAT
  • 13. Raspberry Pi 3 + Rainbow HAT: Getting Started
  • 14. ● 8 Gb or larger SD card ● HDMI display + cable ● Ethernet cable ● SD card reader Flashing the Image: Requirements
  • 15. ● Download and unzip the latest preview image ○ https://developer.android.com/things/preview/download.html ● Write the image to the SD card ○ Instructions for Linux, Mac and Windows ● Insert the SD card into the Raspberry Pi Flashing the Image
  • 17. Connecting via ADB $ adb connect <ip-address> connected to <ip-address>:5555 or $ adb connect Android.local if host platform supports Multicast DNS
  • 18. Connecting WiFi $ adb shell am startservice -n com.google.wifisetup/.WifiSetupService -a WifiSetupService.Connect -e ssid <Network_SSID> -e passphrase <Network_Passcode>
  • 21. ● Handle touch button clicks ● Change text on the alphanumeric display ● Play a melody using the buzzer ● Blink RGB leds along with the melody Rainbow HAT Demo
  • 23. Declaring Dependencies dependencies { provided 'com.google.android.things:androidthings:0.1-devpreview' compile 'com.google.android.things.contrib:driver-button:0.1' compile 'com.google.android.things.contrib:driver-ht16k33:0.1' compile 'com.google.android.things.contrib:driver-pwmspeaker:0.1' ... } app/build.gradle
  • 24. Declaring Dependencies dependencies { provided 'com.google.android.things:androidthings:0.1-devpreview' // compile 'com.google.android.things.contrib:driver-button:0.1' // compile 'com.google.android.things.contrib:driver-ht16k33:0.1' // compile 'com.google.android.things.contrib:driver-pwmspeaker:0.1' compile 'com.google.android.things.contrib:driver-rainbowhat:0.1' ... } app/build.gradle
  • 25. Creating Manifest AndroidManifest.xml <application ...> <uses-library android:name="com.google.android.things"/> … </application>
  • 26. Creating an Activity RainbowHATDemoActivity.kt class RainbowHATDemoActivity : Activity() { … }
  • 27. Declaring the Activity in Manifest AndroidManifest.xml <activity android:name=".RainbowHATDemoActivity"> <!-- Launch activity from Android Studio --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> … <activity>
  • 28. Declaring the Activity in Manifest AndroidManifest.xml <activity android:name=".RainbowHATDemoActivity"> … <!-- Launch activity automatically on boot --> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.IOT_LAUNCHER"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> <activity>
  • 29. Instantiating driver classes RainbowHATDemoActivity.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) buttons = Buttons() display = Display() buzzer = Buzzer() leds = Leds() ... }
  • 30. Creating the Buttons class Buttons.kt class Buttons(private val buttonDrivers: List<ButtonInputDriver> = listOf( registerButtonDriver(BUTTON_A_GPIO_PIN, KeyEvent.KEYCODE_A), registerButtonDriver(BUTTON_B_GPIO_PIN, KeyEvent.KEYCODE_B), registerButtonDriver(BUTTON_C_GPIO_PIN, KeyEvent.KEYCODE_C))) { … }
  • 31. Creating the Buttons class Buttons.kt val BUTTON_A_GPIO_PIN = "BCM21" val BUTTON_B_GPIO_PIN = "BCM20" val BUTTON_C_GPIO_PIN = "BCM16"
  • 32. Raspberry Pi 3 + Rainbow HAT Pinout - https://pinout.xyz/pinout/rainbow_hat
  • 33. Creating the Buttons class Buttons.kt private fun registerButtonDriver(pin: String, keycode: Int): ButtonInputDriver { val driver = ButtonInputDriver( pin = pin, logicLevel = Button.LogicState.PRESSED_WHEN_LOW, keycode = keycode) driver.register() return driver }
  • 34. Creating the Display class Display.kt class Display(private val display: AlphanumericDisplay = AlphanumericDisplay(DISPLAY_I2C_BUS)) { init { display.setEnabled(true) display.clear() } … }
  • 35. Creating the Display class Display.kt fun displayMessage(message: String) { display.display(message) }
  • 36. Processing button events RainbowHATDemoActivity.kt val MESSAGES = mapOf( KeyEvent.KEYCODE_A to "AHOY", KeyEvent.KEYCODE_B to "YARR", KeyEvent.KEYCODE_C to "GROG")
  • 37. Processing button events RainbowHATDemoActivity.kt override fun onKeyUp(keyCode: Int, event: KeyEvent?) = when (keyCode) { in MESSAGES.keys -> { display.displayMessage(MESSAGES[keyCode]!!) true } else -> super.onKeyUp(keyCode, event) }
  • 38. Creating the Buzzer class Buzzer.kt class Buzzer(private val speaker: Speaker = Speaker(SPEAKER_PWM_PIN) { … }
  • 39. Creating the Buzzer class Buzzer.kt fun play(frequency: Double) { speaker.play(frequency) } fun stop() { speaker.stop() }
  • 40. Creating the Buzzer class Buzzer.kt init { stopRunnable = Runnable { stop() } } fun play(frequency: Double, duration: Double) { speaker.play(frequency) stopHandler.postDelayed(stopRunnable, duration.toLong()) }
  • 41. Creating the Leds class Leds.kt class Leds(peripheralManagerService: PeripheralManagerService = PeripheralManagerService()) { … }
  • 42. Creating the Leds class Leds.kt private val leds: List<Gpio> init { leds = listOf( openGpio(peripheralManagerService, LED_RED_GPIO_PIN), openGpio(peripheralManagerService, LED_GREEN_GPIO_PIN), openGpio(peripheralManagerService, LED_BLUE_GPIO_PIN)) }
  • 43. Creating the Leds class Leds.kt private fun openGpio(service: PeripheralManagerService, pin: String): Gpio { val led = service.openGpio(pin) led.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW) return led }
  • 44. Creating the Leds class Leds.kt fun setLed(led: Int, on: Boolean) = with(leds[led]) { value = on } fun toggleLed(led: Int) = with(leds[led]) { value = !value }
  • 45. Integrating Buzzer and Leds RainbowHATDemoActivity.kt private fun playMelodyWithLeds() { playbackRunnable = Runnable { buzzer.play(NOTES[noteIndex].toDouble(), DURATIONS[timeIndex] * 0.8) leds.setLed(Leds.LEDS[ledIndex], on = true) leds.setLed(Leds.LEDS[prevIndex(ledIndex, Leds.LEDS.size)], on = false) if (noteIndex == NOTES.size - 1) { // close } else { playHandler.postDelayed(playbackRunnable, DURATIONS[timeIndex].toLong()) // increment indices } } playHandler.post(playbackRunnable) }
  • 46. Integrating Buzzer and Leds RainbowHATDemoActivity.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... playMelodyWithLeds() }
  • 47. Closing resources RainbowHATDemoActivity.kt override fun onDestroy() { ... arrayOf(leds, buttons, buzzer, display).forEach(Closeable::close) super.onDestroy() }
  • 48. ● Android Things - https://developer.android.com/things/index.html ● Samples - https://developer.android.com/things/sdk/samples.html ● Driver Library - https://github.com/androidthings/contrib-drivers Where do we go from here?
  • 49. What will you build?
  • 50. Thanks! Egor Andreevici Software Developer at 1&1 @EgorAnd +EgorAndreevich https://blog.egorand.me