<<

Practical Tinker Board Getting Started and Building Projects with the ASUS Single-Board Computer

Liz Clark Practical Tinker Board: Getting Started and Building Projects with the ASUS Single-Board Computer Liz Clark Boston, MA, USA

ISBN-13 (pbk): 978-1-4842-3825-7 ISBN-13 (electronic): 978-1-4842-3826-4 https://doi.org/10.1007/978-1-4842-3826-4 Library of Congress Control Number: 2018965217 Copyright © 2019 by Liz Clark This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Natalie Pao Development Editor: James Markham Coordinating Editor: Jessica Vakili Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit http://www.apress. com/rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-3825-7. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper This book is dedicated to my mom, Linda, for always believing in me and for being an amazing teacher, both inside and outside the classroom. Table of Contents

About the Author �������������������������������������������������������������������������������xiii Introduction ����������������������������������������������������������������������������������������xv

Part I: Getting Started ������������������������������������������������������������������1 Chapter 1: What is the ? �����������������������������������������3 A Little Context ������������������������������������������������������������������������������������������������������3 What Is a Single-Board Computer? �����������������������������������������������������������������������4 ���������������������������������������������������������������������������������������������4 The Tinker Board’s Hardware ��������������������������������������������������������������������������������4 GPIO �����������������������������������������������������������������������������������������������������������������6 Tinker Board S ������������������������������������������������������������������������������������������������������8 eMMC ��������������������������������������������������������������������������������������������������������������8 I2S �������������������������������������������������������������������������������������������������������������������8 Power-on Header ���������������������������������������������������������������������������������������������9 Original Tinker Board or Tinker Board S? ��������������������������������������������������������9 Conclusion ����������������������������������������������������������������������������������������������������������10

Chapter 2: Ready to Begin: What Do You Need to Use a Tinker Board? ���������������������������������������������������������������������������13 What Do You Need? ���������������������������������������������������������������������������������������������13 Cooling ����������������������������������������������������������������������������������������������������������������13 Other Cooling Methods ����������������������������������������������������������������������������������15

v Table of Contents

Power ������������������������������������������������������������������������������������������������������������������17 Advanced Power Option ��������������������������������������������������������������������������������18 Peripherals ����������������������������������������������������������������������������������������������������������19 Keyboard and Mouse Choice �������������������������������������������������������������������������19 Storage ����������������������������������������������������������������������������������������������������������������21 eMMC ������������������������������������������������������������������������������������������������������������23 Optional: Cases ���������������������������������������������������������������������������������������������������23 Types of Cases �����������������������������������������������������������������������������������������������24 Conclusion ����������������������������������������������������������������������������������������������������������25

Chapter 3: Installing an �����������������������������������������27 Prepping the SD Card ������������������������������������������������������������������������������������������28 Installing SD Card Formatter �������������������������������������������������������������������������29 Booting from USB for TinkerOS ���������������������������������������������������������������������������36 Prepping Your USB Device �����������������������������������������������������������������������������37 Conclusion ����������������������������������������������������������������������������������������������������������45 Part II: Official Operating Systems and GPIO �����������������������������47 Chapter 4: Getting to Know TinkerOS �������������������������������������������������49 First Boot �������������������������������������������������������������������������������������������������������������49 What Is TinkerOS? �����������������������������������������������������������������������������������������50 Customizing Panels ���������������������������������������������������������������������������������������������55 Changing the Default Password ��������������������������������������������������������������������������57 Changing the Default Username ��������������������������������������������������������������������58 Wi-Fi ��������������������������������������������������������������������������������������������������������������������60 Updating TinkerOS ����������������������������������������������������������������������������������������������61 Video Playback ����������������������������������������������������������������������������������������������������62 YouTube ���������������������������������������������������������������������������������������������������������63 vi Table of Contents

Audio �������������������������������������������������������������������������������������������������������������������67 LibreOffice �����������������������������������������������������������������������������������������������������������69 A Quick Tour ���������������������������������������������������������������������������������������������������71 Fun and Games ���������������������������������������������������������������������������������������������������73 Hello World, Let’s Get Back to Work ��������������������������������������������������������������������75 Installing an IDE for C ������������������������������������������������������������������������������������76 Conclusion ����������������������������������������������������������������������������������������������������������80

Chapter 5: Programming with the GPIO Pins ��������������������������������������81 Gathering Supplies ����������������������������������������������������������������������������������������������82 LEDs ��������������������������������������������������������������������������������������������������������������83 Resistors ��������������������������������������������������������������������������������������������������������83 Photoresistor �������������������������������������������������������������������������������������������������83 Buttons and Switches ������������������������������������������������������������������������������������84 Capacitors �����������������������������������������������������������������������������������������������������84 Connecting Your Circuits to the Tinker Board ������������������������������������������������������84 Circuit Diagrams ��������������������������������������������������������������������������������������������86 Installing Programming Libraries in TinkerOS �����������������������������������������������������86 Installing the Python Library �������������������������������������������������������������������������������87 Blink! �������������������������������������������������������������������������������������������������������������������90 Build the Circuit ���������������������������������������������������������������������������������������������90 Writing Python Code ��������������������������������������������������������������������������������������92 Running Your Code ����������������������������������������������������������������������������������������99 Add a Button �����������������������������������������������������������������������������������������������������100 Switch It Up �������������������������������������������������������������������������������������������������104 Reading Data �����������������������������������������������������������������������������������������������������105 Installing the C Library ��������������������������������������������������������������������������������������111

vii Table of Contents

Blink in C �����������������������������������������������������������������������������������������������������������112 Button in C ��������������������������������������������������������������������������������������������������������117 Pulse Width Modulation ������������������������������������������������������������������������������������120 Coding with Hardware-Controlled PWM ������������������������������������������������������121 Coding with Software-Controlled PWM �������������������������������������������������������124 The Lack of a Real Time Clock ��������������������������������������������������������������������������127 Wrapping Things Up ������������������������������������������������������������������������������������������129

Chapter 6: Android on the Tinker Board �������������������������������������������131 Installation ��������������������������������������������������������������������������������������������������������131 Navigation ���������������������������������������������������������������������������������������������������132 The Home Screen ����������������������������������������������������������������������������������������133 More Apps ���������������������������������������������������������������������������������������������������134 Connecting to Wi-Fi �������������������������������������������������������������������������������������������134 More Settings ����������������������������������������������������������������������������������������������136 Apps In-Depth ���������������������������������������������������������������������������������������������������140 Camera ��������������������������������������������������������������������������������������������������������140 Music and Video ������������������������������������������������������������������������������������������������144 The Music App ���������������������������������������������������������������������������������������������145 The Video App ����������������������������������������������������������������������������������������������146 Installing VLC ����������������������������������������������������������������������������������������������������146 Using VLC �����������������������������������������������������������������������������������������������������149 ApkInstaller �������������������������������������������������������������������������������������������������������150 Legal Considerations �����������������������������������������������������������������������������������151 How It Works �����������������������������������������������������������������������������������������������152 Install �����������������������������������������������������������������������������������������������������������153

viii Table of Contents

Manage ��������������������������������������������������������������������������������������������������������154 Exit ���������������������������������������������������������������������������������������������������������������155 Power ����������������������������������������������������������������������������������������������������������������155 Where Is the App Store? �����������������������������������������������������������������������������������156 Installing F-Droid �����������������������������������������������������������������������������������������157 Exploring F-Droid �����������������������������������������������������������������������������������������158 Using Open Camera for Time-Lapses ����������������������������������������������������������161 Conclusion ��������������������������������������������������������������������������������������������������������166 Part III: Tinker Board Projects �������������������������������������������������167 Chapter 7: Project 1: Build a Game Emulation System ���������������������169 What Is Emulation? �������������������������������������������������������������������������������������������169 ROMs �����������������������������������������������������������������������������������������������������������170 Lakka ����������������������������������������������������������������������������������������������������������������171 Downloading and Installing Lakka ��������������������������������������������������������������������172 First Boot �����������������������������������������������������������������������������������������������������������174 Navigating Lakka: the Main Menu ���������������������������������������������������������������������175 Settings �������������������������������������������������������������������������������������������������������178 Favorites, History, Netplay, and Import Content �������������������������������������������181 Importing ROMs into Lakka �������������������������������������������������������������������������������181 Loading ROMs over the Network �����������������������������������������������������������������182 Loading ROMs over USB ������������������������������������������������������������������������������187 Playing Games ���������������������������������������������������������������������������������������������189 Connecting via SSH �������������������������������������������������������������������������������������������191 Wrapping Things Up ������������������������������������������������������������������������������������������196

ix Table of Contents

Chapter 8: Project 2: Use the Tinker Board as a Media Center with Kodi �������������������������������������������������������������������������������197 LibreELEC ����������������������������������������������������������������������������������������������������������197 What Is Kodi? ����������������������������������������������������������������������������������������������������198 Legal Considerations for Kodi ����������������������������������������������������������������������198 LibreELEC for the Tinker Board �������������������������������������������������������������������������199 CEC ��������������������������������������������������������������������������������������������������������������200 LibreELEC ISO for the Tinker Board �������������������������������������������������������������201 What Is Cross-compiling? ���������������������������������������������������������������������������������202 Ubuntu ���������������������������������������������������������������������������������������������������������203 System Settings ������������������������������������������������������������������������������������������210 Loading Media ��������������������������������������������������������������������������������������������������216 USB Storage ������������������������������������������������������������������������������������������������216 Loading Media to Local Storage over the Network ��������������������������������������217 Network Streaming �������������������������������������������������������������������������������������218 NFS �������������������������������������������������������������������������������������������������������������������218 macOS NFS Configuration ���������������������������������������������������������������������������219 NFS Configuration ������������������������������������������������������������������������������220 SMB ������������������������������������������������������������������������������������������������������������������223 UPnP �����������������������������������������������������������������������������������������������������������������223 Windows Setup ��������������������������������������������������������������������������������������������224 Connecting UPnP Media Server in Kodi �������������������������������������������������������226 Conclusion ��������������������������������������������������������������������������������������������������������228

Chapter 9: Project 3: Stream Music to the Tinker Board with Volumio �������������������������������������������������������������������������������������231 Support for the Tinker Board �����������������������������������������������������������������������������232 Installing the Volumio Disk Image ���������������������������������������������������������������������234 x Table of Contents

First Boot �����������������������������������������������������������������������������������������������������������236 Configure Playback and Wi-Fi ���������������������������������������������������������������������237 Navigating the Browser GUI ������������������������������������������������������������������������������240 UPnP and Internet Radio ������������������������������������������������������������������������������242 Streaming via Airplay ����������������������������������������������������������������������������������������244 Issues with AirPlay ��������������������������������������������������������������������������������������245 Connecting to Volumio with SSH �����������������������������������������������������������������246 Finishing Touches ���������������������������������������������������������������������������������������������249 Conclusion ��������������������������������������������������������������������������������������������������������249

Chapter 10: Project 4: Using an e-Paper Display for Weather Data ����251 What Is e-Paper? ����������������������������������������������������������������������������������������������251 SPI ���������������������������������������������������������������������������������������������������������������252 The e-Paper Display’s Hardware �����������������������������������������������������������������������254 Setting Up the EPD’s Software ��������������������������������������������������������������������������255 Ported Libraries �������������������������������������������������������������������������������������������257 OpenWeatherMap and pyowm ��������������������������������������������������������������������������267 Getting Your City ID ��������������������������������������������������������������������������������������269 Python Script for the Weather Display ��������������������������������������������������������������271 The Technical Parts of the Script �����������������������������������������������������������������278 Autorun Setup ����������������������������������������������������������������������������������������������280 Finishing Touches ����������������������������������������������������������������������������������������284

Chapter 11: Project 5: Build a Robot with a Streaming Camera Feed �������������������������������������������������������������������������������������287 Why a Robot? ����������������������������������������������������������������������������������������������������287 Robot Supplies ��������������������������������������������������������������������������������������������288 I2C ���������������������������������������������������������������������������������������������������������������289 Robot Extras ������������������������������������������������������������������������������������������������289

xi Table of Contents

Motor HAT Setup �����������������������������������������������������������������������������������������������290 Connecting the Hardware ����������������������������������������������������������������������������293 Running the Example Code �������������������������������������������������������������������������294 Robot Project Python Code �������������������������������������������������������������������������������296 Configuring the Camera ������������������������������������������������������������������������������������300 Webcam vs. Ribbon Cable Camera ��������������������������������������������������������������301 Start on Boot �����������������������������������������������������������������������������������������������������305 Bash Script for MJPG-Streamer ������������������������������������������������������������������306 Launching roboTinker.py with autostart ������������������������������������������������������������308 Bonus: Controller Coded with IDE ����������������������������������������309 Circuit ����������������������������������������������������������������������������������������������������������310 Robot Assembly ������������������������������������������������������������������������������������������������314 Final Thoughts ���������������������������������������������������������������������������������������������������316

Index �������������������������������������������������������������������������������������������������317

xii About the Author

Liz Clark has been creating and working with technology her entire life. Always wanting to learn more, she began a YouTube channel after college called Blitz City DIY to document and share her projects with the hopes of inspiring others to explore electronics, open source and all things DIY. When she isn’t coding or soldering a circuit, she can usually be found either playing guitar or hanging out with her two cats, who often make cameos in her work.

xiii Introduction

The goal of Practical Tinker Board is just what the title implies: to provide a realistic guide showing how to best approach and use the Tinker Board single-board computer. The approach that I took when writing this book was to ask myself what I wish I had known when I was getting started with the Tinker Board, from features to limitations in both software and hardware. As a result, this book contains introductions to many concepts that aren’t exclusive to the Tinker Board, because exploring a single-board computer is not a singly focused pursuit; it pulls from many concepts in the realms of open source development and electronics. After reading this book and following along with the tutorials and projects, you’ll have the skills and tools to go forward and create your own projects with the platform. It isn’t meant to be an all-encompassing encyclopedia, just to guide you to a point of independence using the Tinker Board. This book also attempts to ease some of the frustrations that often come with using a brand-new piece of hardware. I hope that it helps beginners by making those first steps more accessible and that it provides inspiration for more experienced users. Platforms like the Tinker Board hold so many possibilities that are only limited by the user’s imagination and skills. May this book be a resource to help you achieve your goals.

xv