Davinder Singh is a Polymath. He loves reading, learning and writing technical cookbooks about new technologies.
What Is Android Things?
Android Things is an Operating system (OS) developed by Google for embedded devices such as low powered microcontrollers. The operating system is a special piece of system software that manages the hardware and handles all the dirty work for you so that you can focus on more important things.
Why You Should Try It?
Android Things unlike other embedded operating systems, is powered by Google's Android operating system which runs on millions of devices. And hence comes with security, stability and API support from Google. If you have never worked in the field of IoT before but you have plenty of experience developing Android applications then you can get started right away. Android Things also comes with a low-level hardware API which gives you full control of your hardware like you used to have before. And lastly, because it is fun and you can do lots of awesome things with it with very little effort.
- I am assuming that you have Raspberry Pi or compatible board
- A computer (mac, PC or Linux) with stable internet connection
- Micro-USB cable
- Ethernet cable
- MicroSD card reader
- 8 GB or larger microSD card
- HDMI cable and HDMI-enabled display
Raspberry Pi 3 starter kit
Download and Install Android Studio
Android studio is an official integrated development environment used for developing android applications. We will use this to write programs for android things and burn them to the board (burning is a metaphor for installing). Here you will find all the instructions and links required to set up Android Studio on your computer.
Setting up Android Things
You have two options to install Android Things operating system. Either you can use the prebuilt package provided by Google or you can create your custom package. In this article, we will use a custom image for our raspberry pi.
- Head to the Google Developer console by clicking here.
- Sign in using your Gmail credentials.
Creating a New Android Things OS
After clicking continue, you will be greeted to Android Things. Here you will have to create a new product. The product is like a project. For every project, you can create a unique product having unique features to handle the job at hand. Click create and then give your product a unique name (I'll name my product Hello World) and in SOM select Raspberry Pi 3.
Add a Model
Every product consists of several Models. Models help to unify the whole process of maintaining and updating the product. Android Things has Over The Air (OTA) update systems hence you can push new features and improvements to all the devices on a single go.
Let's Configure the Build
After a model has been created,
- Click on it (model). A new window will open.
- Click the new button and then select Start from scratch.
- Now give a name to your operating system (your operating system exciting).
- Keep on clicking on next, leaving the rest of the settings as it is till you reach the partition section.
Here you are presented with the option to configure the partition of your final product. You get to choose what amount is to be left for application use. 4096 MB (4 GB) is the minimum amount of space that can be allocated. You can configure this by adding the amount your memory card has. For example, if your memory card is 8GB you will have to enter 8 x 1024 = 8192 and so on. Click on build the process should start immediately.
Flashing Android things on device
1. After the build process click on Download and select development for now. Wait for Google to build your operating system. The download should start shortly. While it is being downloaded head to the Tools side menu and download the operating system flashing tool aka Setup Utility.
2. After download complete. Extract the zip file in a folder. Also, place the android-things zip file downloaded from the console. The directory should contain the following files at the moment
- Android-Setup utility folder containing various scripts (one of them is for your OS).
- Raspberry Pi android things zip (mine is of 331 megabytes).
Don't forget to connect raspberry pi to your PC using usb cable before continuing
3. If you are running Linux or Mac os, open bash and run the script by typing the path of the script as follows,“./android-things-setup-utility/android-things-setup-utility-linux” or in case you are running mac os, “./android-things-setup-utility/android-things-setup-utility-mac”. On windows just double click open windows executable file.
4. Enter 1 and hit enter or return key.
Recommended for you
5. Input 1 to select raspberry pi for, “What hardware are you using?”.
6. Now it will ask for which image you want to install. Input 2 followed by the path to zip the file that you just built from the console (containing your custom build).
7. Setup should start.
Testing the Install
Now is the time to test the installation. To test the installation we will write a simple program in Android studio to blink LED connected to one of the port of Raspberry Pi.
- Disconnect raspberry pi from your PC.
- Connect the short leg of the LED (the negative leg, called the cathode) to the GND (Pin 20).
- Connect the long leg of the LED (the positive leg, called the anode) to the GPIO pin (Pin 18).
Let's Write Some Code
After you are done with connections. Connect the raspberry pi with your PC again. And run Android Studio.
- Create a new project.
- Uncheck use Kotlin box.
- Give name to the project, location and a package name (com.helloworld.iot).
- Now in choose your project click on Android Things and then select Android Things Empty Activity.
5. Give a name to the activity. and check Launch activity automatically on boot. Click next and wait for android studio to set up things for you.
6. In the editor window (MainActivity.java), Paste the following code.
Code to Blink LED
Building the Project
1. Make sure raspberry pi is connected before proceeding.
2. Click on the green arrow on the top and select your device in the run window.
3. Click next.
Note: If you ran into error or device doesn't show up then go to following link or comment below with screenshot.
Wrapping It Up
The LED should start blinking the moment code is uploaded. If it didn't work or you had hard time understanding the article comment below, I'll be happy to help you, Well, that's all for this one. Hope you liked it. Thank you for reading.
This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.
© 2019 Dav Vendator
bhattuc on April 09, 2020:
Highly technical but nicely explained. Thanks. Keep in touch.
Dav Vendator (author) from Amritsar on March 28, 2019:
Android is Open Source Project, Even if Google don't, The user is still free to Port security patches to the Raspberry Pi.
Matt R on March 27, 2019:
Good work. - However I'm worried that google wont support android things anymore for devices like rpi :(