Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Things Quick Start Guide

You're reading from  Android Things Quick Start Guide

Product type Book
Published in Aug 2018
Publisher Packt
ISBN-13 9781789341799
Pages 192 pages
Edition 1st Edition
Languages
Author (1):
Raul Portales Raul Portales
Profile icon Raul Portales

Preface

This book will give you a quick start on Android Things, the platform for IoT made by Google and based on Android. We will go through the basics of IoT and smart devices, interact with a few components that are commonly used on IoT devices, and learn the protocols that work underneath, using examples and a hands-on approach.

We take our hands-on learning approach by going straight into playing with hardware using the Rainbow HAT, so we don't need to do any wiring. We then dig through layer after layer to understand what is being used underneath, but only after we have seen them working. If you are curious about more in-depth learning (such as writing your own drivers), you can always go into the next layer, because almost all the code referenced in this book is open source.

Who this book is for

Since Android Things is a simplified version of Android, you only need a very basic knowledge of how Android works. If you have never done any Android development you will be able to follow along because our examples are kept simple by design.

If you have some experience with other similar platforms, that will be handy, but not necessary. This guide is designed for people that have little to no experience with electronics and microcontrollers but want to get started with them.

Basic knowledge of electronics is desired. That implies that you are familiar with the concepts of voltage and current, as well as resistors, diodes, and capacitors. You also need to know how to read a diagram (there will be a few in this book). All that is very basic knowledge. If you are not familiar with these concepts, you still can follow along, but ultimately you need to understand them to design your own schematics.

Throughout the book we will be using Kotlin as the programming language because it is more modern than Java and allows us to write more concise and easier-to-follow code. Kotlin is meant to be the future of Android development, and it makes a lot of sense to use it on the newest Android platform.

What this book covers

Chapter 1, Introducing Android Things, goes over the big picture of Android Things, the vision behind the platform, and how it compares to other – in principle – similar ones, such as Arduino. Then we will explore the Dev Kit, how to install Android Things on them and how connect to the boards to deploy our code to them. Finally, we will create of a project for Android Things using Android Studio, see how it is structured, and what are the differences from a default Android project.

Chapter 2, The Rainbow HAT, explains how to use the Rainbow HAT to get started with interactions with hardware. This HAT (Hardware On Top) is a selection of components that you can plug into a Dev Kit in order to start working with them without the need for any wiring. We will learn how to use LED, buttons, read temperature and pressure from a sensor and display it on an LCD alphanumeric display, play around with an RGB LED strip, and even make a simple piano, all using high-level abstraction drivers.

In the next four chapters we will take a look at what is under the hood and we will start exploring the different protocols in depth.

Chapter 3, GPIO – Digital Input/Output, goes over General Purpose Input Output (GPIO), which is what we used for the buttons and LEDs. We will learn how to access them directly and then look at other sensors that use GPIO, such as proximity and smoke detectors, as well as other components that also interact via GPIO, such as relays, DC motor controllers, stepper motors, ultrasound proximity sensors, and a numeric LCD display.

Chapter 4, PWM – Buzzers, Servos, and Analog Output, focuses on Pulse Width Modulation (PWM) and its basic usages, of which we have already have seen the piezo buzzer. The most popular use of PWM is servo motors, so we will see how they work. Finally, we'll learn how to use PWM as an analog output.

Chapter 5, I2C – Communicating with Other Circuits, covers the Inter-Integrated Circuit (I2C ) protocol. We have already used it for the temperature/pressure sensor and the LCD alphanumeric display. I2C is the most widely used protocol for simple communication between circuits, and we will explore a few of them. One of the key ones is analog to digital converters (ADC), and we will see how we can use them to read from analog sensors. Other components include magnetometers, accelerometers and IMUs in general, as well as GPIO and PWM expansion boards.

Chapter 6, SPI – Faster Bidirectional Communication, is based on the last protocol we'll look into: Serial Parallel Interface (SPI). We have already used this protocol for the RGB LED strip, and in this chapter we will look at some other drivers, such as OLED displays and LED matrix.

Chapter 7, The Real Power of Android Things, explores some areas where Android Things really shines by using some libraries and services that enable us to make the most of our developer kit. Among the topics we will cover are the use of Android UI, making companion apps using a REST API, Firebase, and Nearby, and we will briefly explore other libraries, such as Tensorflow for machine learning.

Appendix, Pinouts diagrams and libraries, we go over the Pinout diagrams of Rasberry PI and NXP iMX7D. We will then go into details about the state of unsupported Android features and intents on Android Things 1.0, as well as the state of available and unavailable Google APIs on Android Things.

To get the most out of this book

To get the most out of this book you'll need an Android Things Dev Kit and a Rainbow HAT because it will allow you to run all the examples in Chapter 2, The Rainbow HAT.

There are a lot of other hardware components that you don't require, but they are interesting to have just to see them working. I recommend that you acquire the ones you are interested in. We go into more detail about developer kits and how to pick the right one, as well as a summary of the other hardware, as part of Chapter 1, Introducing Android Things.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Android-Things-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Code in action

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "There is also the concept of AutoCloseable, which is an interface that all the peripherals implement."

A block of code is set as follows:

dependencies {
[...]
implementation 'com.google.android.things.contrib:driver-rainbowhat:+'
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

class MainActivity : Activity() {

private lateinit var led: Gpio

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setup()
while (true) {
loop()
}
}

Any command-line input or output is written as follows:

$ sudo ./android-things-setup-utility-macos 

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We select Install Android Things."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email feedback@packtpub.com and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at questions@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

lock icon The rest of the chapter is locked
Next Chapter arrow right
You have been reading a chapter from
Android Things Quick Start Guide
Published in: Aug 2018 Publisher: Packt ISBN-13: 9781789341799
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}