Share E-Book

Designing Embedded Systems and the Internet of Things (IoT) with the ARM® Mbed™ (Perry Xiao)(Z-Library)

Author

OS
Language English

A comprehensive and accessible introduction to the development of embedded systems and Internet of Things devices using ARM mbed Designing Embedded Systems and the Internet of Things (IoT) with the ARM mbed offers an accessible guide to the development of ARM mbed and includes a range of topics on the subject from the basic to the advanced. ARM mbed is a platform and operating system based on 32-bit ARM Cortex-M microcontrollers. This important resource puts the focus on ARM mbed NXP LPC1768 and FRDM-K64F evaluation boards. NXP LPC1768 has powerful features such as a fast microcontroller, various digital and analog I/Os, various serial communication interfaces and a very easy to use Web based compiler. It is one of the most popular kits that are used to study and create projects. FRDM-K64F is relatively new and largely compatible with NXP LPC1768 but with even more powerful features. This approachable text is an ideal guide that is divided into four sections; Getting Started with the ARM mbed, Covering the Basics, Advanced Topics and Case Studies. This getting started guide: • Offers a clear introduction to the topic • Contains a wealth of original and illustrative case studies • Includes a practical guide to the development of projects with the ARM mbed platform • Presents timely coverage of how to develop IoT applications Designing Embedded Systems and the Internet of Things (IoT) with the ARM mbed offers students and R&D engineers a resource for understanding the ARM mbed NXP LPC1768 evaluation board.

Format PDF
Size 24.6 MB
6
Views
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
(This page has no text content)
Page 3
Designing Embedded Systems and the Internet of Things (IoT) with the ARM® Mbed™
Page 4
(This page has no text content)
Page 5
Designing Embedded Systems and the Internet of Things (IoT) with the ARM® Mbed™ Perry Xiao London South Bank University UK
Page 6
This edition first published 2018 © 2018 John Wiley & Sons Ltd All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by law. Advice on how to obtain permission to reuse material from this title is available at http://www.wiley.com/go/permissions. The right of Perry Xiao to be identified as the author has been asserted in accordance with law. Registered Offices John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, USA John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, UK Editorial Office The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, UK For details of our global editorial offices, customer services, and more information about Wiley products visit us at www.wiley.com. Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Some content that appears in standard print versions of this book may not be available in other formats. Limit of Liability/Disclaimer of Warranty While the publisher and authors have used their best efforts in preparing this work, they make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives, written sales materials or promotional statements for this work. The fact that an organization, website, or product is referred to in this work as a citation and/or potential source of further information does not mean that the publisher and authors endorse the information or services the organization, website, or product may provide or recommendations it may make. This work is sold with the understanding that the publisher is not engaged in rendering professional services. The advice and strategies contained herein may not be suitable for your situation. You should consult with a specialist where appropriate. Further, readers should be aware that websites listed in this work may have changed or disappeared between when this work was written and when it is read. Neither the publisher nor authors shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. Library of Congress Cataloging-in-Publication Data Names: Xiao, Perry, author. Title: Designing embedded systems and the internet of things (IoT) with the ARM Mbed / by Perry Xiao. Description: First edition. | Hoboken, NJ : John Wiley & Sons, Inc., [2018] | Includes bibliographical references and index. | Identifiers: LCCN 2018008687 (print) | LCCN 2018015034 (ebook) | ISBN 9781119364016 (pdf) | ISBN 9781119364047 (epub) | ISBN 9781119363996 (cloth) Subjects: LCSH: Embedded computer systems–Design and construction | Internet of things–Equipment and supplies. | Microcontrollers. Classification: LCC TK7895.E42 (ebook) | LCC TK7895.E42 X56 2018 (print) | DDC 006.2/2–dc23 LC record available at https://lccn.loc.gov/2018008687 Cover design by Wiley Cover image: © matejmo/Getty Images; © Raimundas/Shutterstock Set in 10/12pt WarnockPro by SPi Global, Chennai, India 10 9 8 7 6 5 4 3 2 1
Page 7
This book is dedicated to my family. To my wife, May, my son, Zieger, and my daughter, Jessica, who make my life complete—without them, life would be meaningless. To my parents and my brother, who have shared their life and love with me that ultimately made me what I am today. To my friends and colleagues, who supported me throughout my career.
Page 8
(This page has no text content)
Page 9
vii About the Author xiii Preface xv Author’s Acknowledgments xix About the companion website xxi Part I Introduction to Arm® Mbed™ and IoT 1 1 Introduction to Arm® Mbed™ 3 1.1 What is an Embedded System? 3 1.2 Microcontrollers and Microprocessors 4 1.3 ARM® Processor Architecture 8 1.4 The Arm® Mbed™ Systems 10 1.4.1 NXP LPC1768 11 1.4.2 NXP LPC11U24 14 1.4.3 BBC Micro:bit 15 1.4.4 The Arm® Mbed™ Ethernet Internet of Things (IoT) Starter Kit 17 1.5 Summary 21 1.6 Chapter Review Questions 21 2 Introduction to the Internet of Things (IoT) 23 2.1 What is the Internet of Things (IoT)? 23 2.2 How Does IoT Work? 24 2.3 How Will IoT Change Our Lives? 25 2.4 Potential IoT Applications 27 2.4.1 Home 27 2.4.2 Healthcare 28 2.4.3 Transport 28 2.4.4 Energy 28 2.4.5 Manufacture 28 2.4.6 Environment 28 2.5 Summary 29 2.6 Chapter Review Questions 29 Contents
Page 10
Contentsviii 3 IoT Enabling Technologies 31 3.1 Sensors and Actuators 31 3.2 Communications 31 3.2.1 RFID and NFC (Near‐Field Communication) 32 3.2.2 Bluetooth Low Energy (BLE) 32 3.2.3 LiFi 33 3.2.4 6LowPAN 33 3.2.5 ZigBee 34 3.2.6 Z‐Wave 34 3.2.7 LoRa 34 3.3 Protocols 35 3.3.1 HTTP 35 3.3.2 WebSocket 36 3.3.3 MQTT 37 3.3.4 CoAP 38 3.3.5 XMPP 38 3.4 Node‐RED 39 3.5 Platforms 41 3.5.1 IBM Watson IoT—Bluemix (http://www.ibm.com/internet‐of‐things/) 41 3.5.2 Eclipse IoT (https://iot.eclipse.org/) 42 3.5.3 AWS IoT (https://aws.amazon.com/iot/) 42 3.5.4 Microsoft Azure IoT Suite (https://azure.microsoft.com/en‐us/suites/iot‐suite/) 42 3.5.5 Google Cloud IoT (https://cloud.google.com/solutions/iot/) 44 3.5.6 ThingWorx (https://www.thingworx.com/) 44 3.5.7 GE Predix (https://www.predix.com/) 44 3.5.8 Xively (https://www.xively.com/) 44 3.5.9 macchina.io (https://macchina.io/) 45 3.5.10 Carriots (https://www.carriots.com/) 45 3.6 Summary 45 3.7 Chapter Review Questions 45 Part II Arm® Mbed™ Development 47 4 Getting Started with Arm® Mbed™ 49 4.1 Introduction 49 4.2 Hardware and Software Required 49 4.2.1 Hardware 49 4.2.2 Software 50 4.3 Your First Program: Blinky LED 53 4.3.1 Connect the Mbed to a PC 53 4.3.2 Click “mbed.htm” to Log In 53 4.3.3 Add the FRDM‐K64F Platform to Your Compiler 54 4.3.4 Import an Existing Program 54 4.3.5 Compile, Download, and Run Your Program 57
Page 11
Contents ix 4.3.6 What Next? 57 4.4 Create Your Own Program 57 4.5 C/C++ Programming Language 58 4.6 Functions and Modular Programming 58 4.7 Manage Platforms 61 4.8 Clone Your Program 63 4.9 Search and Replace 64 4.10 Compile Your Program for Multiple Platforms 65 4.11 Delete Your Program 65 4.12 Disaster Recovery Procedure 67 4.13 Upgrade Firmware 67 4.14 Help 67 4.15 Summary 69 5 Inputs and Outputs 71 5.1 Digital Inputs and Outputs 71 5.1.1 Digital Inputs 71 5.1.2 Digital Outputs 74 5.1.3 BusIn, BusOut, and BusInOut 79 5.2 Analog Inputs and Outputs 81 5.2.1 Analog Inputs 81 5.2.2 Analog Outputs 82 5.3 Pulse Width Modulation (PWM) 86 5.4 Accelerometer and Magnetometer 88 5.5 SD Card 96 5.6 Local File System (LPC1768) 99 5.7 Interrupts 100 5.8 Summary 101 6 Digital Interfaces 103 6.1 Serial 103 6.2 SPI 106 6.3 I2C 108 6.4 CAN 111 6.5 Summary 113 7 Networking and Communications 115 7.1 Ethernet 115 7.2 Ethernet Web Client and Web Server 119 7.3 TCP Socket and UDP Socket 124 7.4 WebSocket 128 7.5 WiFi 131 7.6 Summary 135 8 Digital Signal Processing and Control 137 8.1 Low‐Pass Filter 137 8.2 High‐Pass Filter 141
Page 12
Contentsx 8.3 Band‐Pass Filter 143 8.4 Band‐Stop Filter and Notch Filter 146 8.5 Fast Fourier Transform (FFT) 149 8.6 PID Controller 160 8.7 Summary 164 9 Debugging, Timer, Multithreading, and Real‐Time Programming 165 9.1 Debugging 165 9.2 Timer, Timeout, Ticker, and Time 167 9.3 Network Time Protocol (NTP) 171 9.4 Multithreading and Real‐Time Programming 173 9.5 Summary 179 10 Libraries and Programs 181 10.1 Import Libraries and Programs 181 10.2 Export Your Program 181 10.3 Write Your Own Library 182 10.4 Publish Your Library 188 10.5 Publish Your Program 190 10.6 Version Control 192 10.7 Collaborations 196 10.8 Update Your Library and Program 201 10.9 Summary 202 Part III The IoT Starter Kit and IoT Projects 203 11 Arm® Mbed™ Ethernet IoT Starter Kit 205 11.1 128×32 LCD 205 11.2 Joystick 207 11.3 Two Potentiometers 208 11.4 Speaker 209 11.5 Three‐Axis Accelerometer 211 11.6 LM75B Temperature Sensor 211 11.7 RGB LED 212 11.8 Summary 214 12 IoT Projects with Arm® Mbed™ 215 12.1 Temperature Monitoring over the Internet 215 12.2 Smart Lighting 224 12.3 Voice‐Controlled Door Access 230 12.4 RFID Reader 237 12.5 Cloud Example with IBM Watson Bluemix 242 12.5.1 IBM Quickstart Service 243 12.5.2 IBM Registered Service (Bluemix) 245 12.5.3 Add IBM Watson IoT Service to Your Application 252 12.5.4 Add Your Mbed Device to Your Watson IoT Organization 252
Page 13
Contents xi 12.5.5 Adding Credentials onto Your Mbed Device 257 12.5.6 Link Your IBM IoT Watson Application to Your Mbed Device 257 12.5.7 Sending Commands from Your IBM IoT Watson Application to Your Mbed Board 261 12.5.8 More with Node-RED 261 12.6 Real-Time Signal Processing 271 12.7 Summary 277 Part IV Appendices 279 Appendix A: Example Codes 281 Appendix B: HiveMQ MQTT Broker 285 Appendix C: Node‐RED on Raspberry Pi 295 Appendix D: String and Array Operations 303 Appendix E: Useful Online Resources 311 Index 313
Page 14
(This page has no text content)
Page 15
xiii Dr. Perry Xiao is an associate professor and course director at the School of Engineering, London South Bank University, London, United Kingdom. He got his BEng degree in Opto‐Electronics, MSc degree in Solid State Physics, and PhD degree in Photophysics. He is a chartered engineer (CEng), a Fellow (FIET) from Institution of Engineering and Technology (IET) and a Senior Fellow (SFHEA) from Higher Education Academy (HEA). He has been teaching electronics, software, computer networks, and telecom- munication subjects at both undergraduate level and postgraduate level for nearly two decades. He is also supervising BEng final project students and MSc project students every year. His main research interest is to develop novel infrared and electronic sens- ing technologies for skin bioengineering applications and industrial nondestructive testing (NDT). To date, he has finished seven PhD student supervisions, obtained two UK patent applications, published more than 100 scientific papers, been editorial reviewer for nine journals, and generated nearly £1 million in research grants. He is also a director and co‐founder of Biox Systems Ltd., UK—a university spin‐off company that designs and manufactures state‐of‐the‐art skin measurement instru- ments, AquaFlux and Epsilon, which have been used in more than 70 organizations worldwide, including leading cosmetic companies, universities, research institutes, and hospitals. About the Author
Page 16
(This page has no text content)
Page 17
xv When I first got the Arm® Mbed™ Lab‐in‐a‐Box (LiB) kits from a colleague a few years ago, I could not hide my excitement. It was a box of mbed NXP LPC1768 development boards donated through the ARM University Program. One of the key features of the Arm® Mbed™ system is that you can write and compile your code online through a web browser. This was completely new to me. I have been using vari- ous microcontrollers throughout my life. I did my BEng final year project on laser energy control using Intel’s 8051 single‐chip microcontroller back in the 1980s. The concept was very simple: read the voltage value from the laser power monitor, com- pare it with a desired value, and calculate the required adjustment to feed back to the laser to increase or decrease the laser output. But we had to design and make our own printed circuit boards (PCB) and to write our own code that would run on 8051. At that time, programming microcontrollers was not a trivial task. You needed to write the program in assembly language and punch in the corresponding hexadecimal code into the microcontroller. We spent many sleepless nights in the lab, mainly for debug- ging the code. I have since worked with many other microcontroller‐based embedded systems, and the experiences were very mixed. Some of the embedded systems were so difficult to use that you would need to download this software, download that toolchain, etc. Using my students’ words, you needed a PhD just to get the compiler software running. The code was also sophisticated—you would need to configure this register, and configure that port. You could produce lines of lines of code, which did not even do much! The two embedded systems that impressed me most were Raspberry Pi and Arduino. Raspberry Pi is very attractive for its price and its compact, credit‐card size. With a full Debian‐based Linux operating system and graphical user interface, it is a great kit for people to learn computing and coding. But for many of our student projects, we don’t need a full operating system, and a lack of analog to digital converter (ADC) and digital to analog converter (DAC) are also major drawbacks. Arduino is also attractive for its price and size, but what impressed me most is its simplicity, both in hardware and soft- ware. I have read many “24 hours” books, and Arduino is genuinely one of the things that you can truly learn in 24 hours. It is just that simple. However, the limited memory size means you cannot write too‐long programs, and 10‐bit ADC is often proven to be inadequate in many applications. So when I introduced the Arm® Mbed™ NXP LPC1768 development boards to my students, they loved them. They liked the web‐based compiler. The very fact that you Preface
Page 18
Prefacexvi don’t need to download and install any software on your computer in order to run it is amazing. It makes life so much easier. The code was also much simpler, much more understandable. As it is claimed on the Arm® Mbed™ website (https://os.mbed.com/ platforms/FRDM‐K64F/), it can really just take 30 seconds to get the development board out of the box, and run an application without installing any software! The Arm® Mbed™ NXP LPC1768 is one of the most popular microcontroller devel- opment boards, widely used among students and electronic hobbyists. It is based on 32‐bit ARM® Cortex™‐M3 microcontroller with 96 MHz clock speed, 512 KB flash, 32 KB RAM, and, most importantly, 12‐bit ADCs. It is more powerful and runs much faster than Arduino. It also has lots of interfaces, including Ethernet, USB, CAN, SPI, I2C, DAC, PWM, and other I/O interfaces. However, the 32‐bit ARM® Cortex™‐M3 microcontroller is gradually reaching its shelf life; its replacement is the 32‐bit ARM® Cortex™‐M4 microcontroller. So this book will be focusing on the new, exciting Arm® Mbed™ Ethernet Internet of Things (IoT) Starter Kit, which includes an Arm® Mbed™ NXP FRDM‐K64F development board and an Arm® Mbed™ application shield. The Arm® Mbed™ NXP FRDM‐K64F is the next generation, flagship development board, which is based on ARM® Cortex™‐M4 micro- controller with a CPU frequency up to 120 MHz, 1024 KB Flash, 256 KB RAM, and astonishing two 16‐bit ADCs. It is much faster and more powerful than NXP LPC1768. It also has DACs and Timers, as well as other interfaces such as Ethernet, USB device crystal‐less, and Serial. The Arm® Mbed™ Ethernet IoT Starter Kit is a cloud‐based development kit jointly developed by ARM and IBM. It provides the user with a slick experience, sending data from the onboard sensors into the IBM cloud. It allows you to access the IBM cloud applications through IBM’s BlueMix platform. It is particularly suitable for developers with no specific experience in embedded or web development, as it provides a platform for learning new concepts and creating working prototypes. The starter kit hardware can also be modified and extended to satisfy your specific requirements. For backward compatibility reasons, many example codes also work for NXP LPC1768 development board and its mbed application board. As of the time this book was written, the Arm® Mbed™ had just released its latest Arm® Mbed™ OS (operating systems) version 5.7, which has quite a few changes com- pared with the previous version mbed OS 3.0 and 2.0. This book is mainly based on the Arm® Mbed™ OS 5.7, and more details about the new OS are available at the Arm® Mbed™ documentation website (https://os.mbed.com/docs). I have thoroughly enjoyed working with the Arm® Mbed™ development boards, and I hope you will enjoy it too. How This Book Is Organized This book aims to teach students how to design and develop embedded systems as well as Internet of Things (IoT) applications using Arm® Mbed™ development boards. It is divided into three parts. Part I: Introduction to Arm® Mbed™ and IoT (Chapters 1–3) gives an introduction of embedded systems, microcontrollers and microprocessors, Arm® architecture and
Page 19
Preface xvii Arm® Mbed™ system. It also provides an overview of the Internet of Things (IoT), including IoT applications and IoT enabling technologies. Part II: Arm® Mbed™ Development (Chapters 4–10) illustrates how to get started with Arm® Mbed™ development, as well as how to work with analog inputs/outputs, digital inputs/outputs, communication interfaces, debugging, online libraries, and project managements. Part III: The IoT Starter Kit and The IoT Projects (Chapters 11–12) introduces the Arm® Mbed™ Ethernet IoT Starter Kit and provides some example IoT projects. Part IV: Appendices Appendix A: Example Codes Appendix B: HiveMQ MQTT Broker Appendix C: Node‐RED on Raspberry Pi Appendix D: String and Array Operations Appendix E: Useful Resources Example Codes All the example source codes are available on the website that accompanies this book. Appendix A has more details on how to use the codes. Who This Book Is For This book is intended for university/college students as well as amateur electronic hob- byists. It assumes readers have a basic concept of how computers work and can compe- tently use a computer, i.e., can switch the computer on, log in, run some programs, and copy files to and from a USB memory stick (without losing their temper!). It assumes that readers have some electronics experience, such as handling a bread- board, wires, resisters, power supply, and LEDs. It also assumes readers have some basic programming experiences (ideally in C/C++, but other languages are also fine), and know the basic syntax, the different types of variables, the conditional selections, and the loops and subroutines. Prior knowledge and experiences of microcontrollers are desirable, but not necessary. Finally, it assumes readers have a basic concept of computer networks and the Internet, i.e., understand the concept of IP addresses and port numbers, know how to find out the IP address of a computer, and can use some of the most commonly used Internet services such as the World Wide Web, email, file download/upload, online audio, online video, and even some cloud‐based services. This book can be used as a core textbook as well as a background‐reading textbook. Suggested Prerequisite Readings Electronics: Electronics All‐in‐One for Dummies, 2nd edition, Doug Lowe, ISBN: 978‐1‐119‐32079‐1, March 2017.
Page 20
Prefacexviii C/C++ Programming: Beginning Programming with C for Dummies, Dan Gookin, ISBN: 978‐1‐118‐73763‐7, November 2013. C++ Primer, 5th edition, Stanley B. Lippman, Josée Lajoie, Barbara E. Moo, Addison Wesley, ISBN: 978‐0‐321‐71411‐4, August 2012. Computer Networks and Internet: Computing Fundamentals: Digital Literacy Edition, Faithe Wempen with Rosemary Hattersley, Richard Millett, Kate Shoup, ISBN: 978‐1‐118‐97474‐2, August 2014. Understanding Data Communications: From Fundamentals to Networking, 3rd edition, Gilbert Held, ISBN: 978‐0‐471‐62745‐6, October 2000. What You Need In this book, you will need: ● Arm® Mbed™ Ethernet IoT Starter Kit – NXP FRDM‐K64F development board – Mbed application shield ● Breadboard with jump wires ● Various sensors ● A digital or analog oscilloscope (optional) ● NXP LPC1768 development board and its Application board (optional) ● Raspberry Pi (https://www.raspberrypi.org/) (optional) ● Java JDK software (http://www.oracle.com/technetwork/java/javase/downloads/index .html) ● Python software (https://www.python.org/downloads/) (optional)
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List