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
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
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
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
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()
}
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?