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.
Table of ContentsPreface 1Chapter 1: Introducing Android Things 8Technical requirements 8What is Android Things? 9Internet of Things (IoT) vs. smart devices 10Android Things vs. other platforms 10Emulators and testing 11Android Studio 12Design concepts behind Android Things 13Displays are optional 13Home activity support 14Permissions 14Android Things Console 15Supported APIs 16Hardware you will need 16Android Things developer kits 17Raspberry Pi 17NXP Pico iMX7D 18Rainbow HAT 20Components, circuits, and so on 21Wires and breadboards 23Setting up a developer kit 24Installing Android Things 24Configuring Wi-Fi using the script 27Configuring Wi-Fi using the system UI 28Connecting to your Android Things 30Creating an Android Things project 32Manifest 35Gradle configuration 36Activity code 37Summary 38Chapter 2: The Rainbow HAT 39Technical requirements 40Android Things architecture 41Peripheral lifecycle 41User space drivers 42LEDs 42The Arduino way 43Table of Contents[ ii ]Threads 45Coroutines 46Using Handler and Runnable 48Using Timer and Timertask 49Buttons 51Button driver 51Debouncing 52Button input drivers 53Piezo buzzer 55Alphanumeric display (Ht16k33) 57Temperature and pressure sensor (Bmx280) 58Direct read 58Continuous updates with sensor driver 61Adding pressure driver 63LED strip (Apa102) 64Summary 67Chapter 3: GPIO - Digital Input/Output 70Technical requirements 71Making the code work on any developer kit 71Using GPIO for output 73LEDs 73Relays 76Using GPIO for input 78Buttons 78Button driver 78Input drivers 80Controlling buttons directly with GPIO 80Other sensors 81Other usages of GPIO 84DC motor controller (L298N) 84Stepper motor (28BYJ-48) with controller (ULN2003) 87Ultrasonic distance sensor (HC-SR04) 89LCD display (TM1637) 92Summary 94Chapter 4: PWM - Buzzers, Servos, and Analog Output 95Technical requirements 96PWM overview 96Piezo buzzers 98Servos 100Using the servo driver 101Tweaking the servo configuration 106PWM as analog output 107Summary 110Table of Contents[ iii ]Chapter 5: I2C - Communicating with Other Circuits 111Technical requirements 111Overview of I2C 112Addressing circuits 113Revisiting Rainbow HAT components 115Alphanumeric display (Ht16k33) 115Temperature and pressure sensor (Bmx280) 115Extension components 116Analog to digital converter (ADC) – PCF8591 116Analog sensors 118PWM expander – PCA9685 119GPIO expander – PCF8575 122Small displays 123Other I2C sensors 126Accelerometer/gyroscope – MPU6050 127Summary 128Chapter 6: SPI - Faster Bidirectional Communication 129Technical requirements 129Overview of SPI 130LED strip 132Usage on displays 133LED matrix 134SPI version of SSD1306 138Summary 140Chapter 7: The Real Power of Android Things 141Technical requirements 141Using Android UI 142Companion apps and communication 144REST API using NanoHttpd/Retrofit 145Firebase Realtime Database 148Nearby 153Advertising and discovering 155Initiating and confirming connections 155Sending and receiving data 157More cool stuff 158TensorFlow – image classifier 158Publish subscribe buses 159Google Assistant – Home control 160Online resources 161Summary 161Appendix A: Pinouts diagrams and libraries 162Raspberry Pi Pinout 162NXP iMX7D Pinout 163Table of Contents[ iv ]Supported and unsupported libraries 164Unsupported features 164Common intents and content providers 165Available Google APIs 165Unavailable Google APIs 166Other Books You May Enjoy 167Index 170
评论