After learning about Android Things Starter Kit, I get on next to create a simple Android Things App that access the Internet and uses the Peripehral.
It is done reuse my previous simple Wiki Search App, and link it to some Android Things Rainbow HAT peripherals for the result.
Goal of the App
I have two goals of making this APP
- Create an App that has connection to the internet
- Create an App that trigger some peripherals output
Use Kotlin Code and some of its language feature for the entire project
Use Coroutine for some parallel processing of the LED Strip light display
The App Functionality
This is what the App does
- Key in a word in the provided EditText box, and press
CHECK SEARCH COUNT
- It will then send the word to wikipedia API, that returns the count of the word found in wikipedia
- While it is performing the search, the peripheral LED strip on the Rainbow HAT will lit up and down in sequence
- Once the result is back, it will show the result on the screen, as well as on the 14 segment display on the Rainbow HAT
Check out the video demo below for detail.
I’m not sharing on the technical side of how to connect to Wikipedia from the App, as it is clearly shared in Wiki Search App
I’m covering the code that works with Peripherals here
Include the dependencies
Other than Android Things, I’m adding the Rainbow HAT driver library as below in the
Add the permission
Permission is needed to access the peripheral. Just add it in the
One note: If you have previously installed the App without the permission, you’ll need to uninstall the App first, then reinstall the App. Else your newly added permission take effective.
To access the LED Strip, you need to initialize it.
val ledStrip = RainbowHat.openLedStrip()
As there are 7 LED Strips, you’ll need to assign an array of 7 Integer.
val colors = IntArray(7)
You could put and RGB color to the array content as you wish, then write the array content to the LED Strip
Then you’ll get the color shown on the display.
14 Segment Display
To access the 14 Segment Display, you need to initialize it.
val segmentDisplay = RainbowHat.openDisplay()
After that, you’ll need to enable it
Finally you just display the value (it accept
Double and even
Then you’ll get the word displayed.
You could get the code below.
demo_androidthings_wiki_count - Using Android Things to perform search count on wiki, and display the progress on…
If you like to explore beyond that, and also use the temperature sensor feature of the AndroidThings, you could check it out in