dcsimg
May 28, 2017
Hot Topics:

Getting Started with Android Things Development

  • April 26, 2017
  • By Rob Gravelle
  • Send Email »
  • More Articles »

The Internet of Things (IoT for short) is a phrase used to describe the connecting of electronic devices over the Internet that participate together on a system. In many cases, people also need to communicate with devices via their smartphones, tablets, and even watches. That's where Android Things comes in. Launched by Google on 13 December 2016, Android Things is an Android-based OS for the Internet of Things that can run on products like connected speakers, smart thermostats, security cameras, routers, and many other devices. This tutorial will get you started with Android Things and show you how to set up the required hardware and software.

What You'll Need

Before you can begin programming for Android Things, you'll need to set up a physical development board flashed with the Android Things OS and the required peripherals for your device. There are currently several options for boards:

  • Intel Edison: A small and powerful System on a Chip (SoC) that includes a CPU, MCU, memory, storage, and dual-band Wi-Fi and Bluetooth. The module can be mounted onto a system of expansion boards, enabling the quick prototyping of light IoT applications. Price: approx. $49.95 USD
  • Intel Joule: Intel's highest-performing system-on-module, packs powerful computing capabilities in a thumb-sized, low-power package. The Intel Joule 550x/570x developer kit enables developers to rapidly prototype all manner of autonomous robots and IoT applications requiring computer vision or edge processing. Price: approx. $340.00 USD
  • NXP i.MX6UL: Expanding the i.MX 6 series, the i.MX 6UltraLite is a high performance, and ultra-efficient processor family featuring an advanced implementation of a single ARM Cortex-A7 core. The Pico variant is pin-compatible with the Intel Edison for sensors and low-speed I/O, but also adds additional expansion possibilities for multimedia and connectivity, providing cutting edge technology that can easily be expanded and implemented for IoT designs. Price: approx. $70.00 USD
  • Raspberry Pi 3: Raspberry Pi 3 Model B is the latest iteration of the world's most popular single board computer. It provides a quad-core 64-bit ARM Cortex-A53 CPU running at 1.2GHz, four USB 2.0 ports, wired and wireless networking, HDMI and composite video output, and a 40-pin GPIO connector for physical interfacing projects. Price: aprox. $40.00 USD ($60.00 for the development kit)

For this tutorial, we'll be using the Adafruit Project Kit with Raspberry Pi, because it's the most popular and the cheapest of the preceding choices. The Project Kit comes equipped with all of the peripherals that you'll need, including sensors, jumper wires, and resistors.

The Adafruit Project Kit with Raspberry Pi
Figure 1: The Adafruit Project Kit with Raspberry Pi

Origins and Terminology Explained

In the processor description above, you'll see a reference to the "GPIO connector." GPIO stands for "General Purpose Input/Output." It contains ports for sensors, LED, button and other thingamagigs. The peripheral I/O lets you control the current state of those LED, buttons, and sensors programmatically or according to some user action, such as pressing a button. They also notify you about the state changes, so that you can tell the Peripheral I/O to switch on the LED or what-have-you.

The Raspberry Pi 3 processor also supports Pulse Width Modulation (PWM). This API is utilized for interacting with servo motors, DC motors, and lights that require a proportional signal to provide fine-grained control over the output.

Some quick trivia: The Pi in "Raspberry Pi" stands for "Python," due to the fact that the manufacturer originally intended to produce a computer that would run only Python.

Flashing the Image

To put Android Things on the Raspberry Pi, you'll need the following additional general purpose items:

  • HDMI cable and a display (such as a computer monitor)
  • Ethernet cable connected to your Internet
  • Micro-USB cable
  • Micro SD card with at least 8GB of space, and an SD card adapter
  • A computer that can read and write to an SD card

Once you have all of the required components, you will need to download the latest system image for the Raspberry Pi from the Google Android Things System Image Downloads page.

You will need to unzip the downloaded file to retrieve the .img file. Some programs, such as the standard Archive Utility on OS X, may have a problem unzipping, due to the large size of the file. If that happens, you can install Unarchiver for OS X or 7-Zip for Windows to extract the file properly.

You'll then have to place the .img file on your SD card. This process will vary for each operating system. This tutorial will cover the process on Windows. You can find the instructions for Max OSand Linux here.

Operating System Image Windows Installation

Follow these steps in order:

  1. Insert the SD card into your SD card reader. You can use the SD card slot if you have one, or an SD adapter in a USB port. Note the drive letter assigned to the SD card. You can see the drive letter in the left hand column of Windows Explorer, for example "F:"

    Mounting the SD card
    Figure 2: Mounting the SD card

  2. Download the Win32DiskImager utility from the Sourceforge Project page as an installer file, and run it to install the software.
  3. Run the Win32DiskImager utility from your desktop or menu.

    Running the Win32DiskImager utility
    Figure 3: Running the Win32DiskImager utility

  4. Select the image file you extracted earlier.
  5. Select the drive letter of the SD card in the device box. Be careful to select the correct drive because choosing the wrong drive could destroy the data on your computer's hard disk! (No stress.) If you are using an SD card slot in your computer and can't see the drive in the Win32DiskImager window, try using an external SD adapter.
  6. Click 'Write' and wait for the operation to complete.
  7. Exit the imager and eject the SD card.

You are now ready to plug the card into your Raspberry Pi. Connect your Raspberry Pi to your display via the HDMI cable, to your network with an Ethernet cable, and to a power source (such as your computer) with the micro USB type-B cable.

Once your Raspberry Pi has booted, you should see the following welcome screen on your display:

The Android Things welcome screen
Figure 4: The Android Things welcome screen

At this point, you will be able to connect to your newly flashed Android Things board and load apps onto it. This is the topic of the next article.

Coding in Android Things

To give you a taste for what Android Things code looks like, here is a snippet that lists available peripherals. The system service responsible for managing peripheral connections is called PeripheralManagerService. You can use this service to list the available ports for all known peripheral types. For instance, the following code outputs the list of available GPIO ports to logcat:

public class HomeActivity extends Activity {
   private static final String TAG = "HomeActivity";

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      PeripheralManagerService service = new
         PeripheralManagerService();
      Log.d(TAG, "Available GPIO: " +
         service.getGpioList());
   }
}

Conclusion

In the next tutorial, we'll write a basic Android Things application that communicates with our board.

About the Author

Author headshot

Rob Gravelle resides in Ottawa, Canada, and has built Web applications for numerous businesses and government agencies. Email him for a quote on your project.

Rob's alter-ego, "Blackjacques," is an accomplished guitar player, who has released several CDs. His band, Ivory Knight, was rated as one of Canada's top hard rock and metal groups by Brave Words magazine (issue #92) and reached the #1 spot in the National Heavy Metal charts on ReverbNation.com.

Rob uses and recommends MochaHost, which provides Web Hosting for as low as $1.95 per month, as well as unlimited emails and disk space!


Tags: Google, Android, SD Card, internet of things, system on a chip, Intel Edison, Raspberry Pi 3, Android Things OS, Adafruit Project Kit, GPIO connector




Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel