Programming the Photon
Programming the Photon
Getting Started with the Internet of Things
Christopher Rush
New York Chicago San Francisco
Athens London Madrid
Mexico City Milan New Delhi
Singapore Sydney Toronto
Library of Congress Control Number: 2016933233
McGraw-Hill Education books are available at special quantity discounts to use as premiums and sales promotions or for use in corporate training programs. To contact a representative, please visit the Contact Us page at www.mheducation.com.
Programming the Photon: Getting Started with the Internet of Things
Copyright 2016 by McGraw-Hill Education. All rights reserved. Printed in the United States of America. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication.
McGraw-Hill Education, the McGraw-Hill Education logo, TAB, and related trade dress are trademarks or registered trademarks of McGraw-Hill Education and/or its affiliates in the United States and other countries and may not be used without written permission. All other trademarks are the property of their respective owners. McGraw-Hill Education is not associated with any product or vendor mentioned in this book.
1 2 3 4 5 6 7 8 9 0 DOC DOC 1 2 1 0 9 8 7 6
ISBN 978-0-07-184706-3
MHID 0-07-184706-5
e-ISBN 978-0-07-184707-0
e-MHID 0-07-184707-3
This book is printed on acid-free paper.
Sponsoring Editor
Michael McCabe
Editorial Supervisor
Stephen M. Smith
Production Supervisor
Lynn M. Messina
Acquisitions Coordinator
Lauren Rogers
Project Manager
Hardik Popli
Copy Editor
Lisa McCoy
Proofreader
Rajni Negi,
Cenveo Publisher Services
Indexer
Jack Lewis
Art Director, Cover
Jeff Weeks
Illustration
Cenveo Publisher Services
Composition
Cenveo Publisher Services
Information has been obtained by McGraw-Hill Education from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill Education, or others, McGraw-Hill Education does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information.
About the Author
Christopher Rush has a degree in computer science and has spent the last 10 years working for an electronics distribution company as a product manager for single-board computing. He also runs a MakerSpace blog (www.rushmakes.com) providing reviews, tutorials, and user guides for popular development boards and accessories, including Raspberry Pi, Arduino, BeagleBone, and others. Mr. Rush is the author of 30 BeagleBone Black Projects for the Evil Genius, also published by McGraw-Hill Education.
CONTENTS AT A GLANCE
CONTENTS
PREFACE
This book is the perfect introduction to programming the Particle Photon development board. The Particle Photon is a true Internet of Things device that lets you write code and create electronic projects using the cloud. It is fully capable of acting as the brains of your projects while expanding their capabilities by using the Internet to remotely control and collect data.
Luckily, the Photon platform has adopted the Arduino-style programming language while also introducing its own programming features. This opens you up to the vast amount of resources from the world of Arduino that are available to you, including existing projects and examples.
Why the Photon? The Photon board was developed by the team at Particle and was introduced to the world in November 2014, priced at only $19. It is one-of-a-kind, offering a unique hardware and software experience to you using the Particle cloud, which can be programmed through the Web IDE. The Photon board supersedes the Particle Core, which was funded through a Kickstarter campaign that raised over half-a-million U.S. dollars, and it comes equipped with the Broadcom BCM43362 Wi-Fi chip rather than the TI CC3000.
The purpose of this book is to get you started with creating your own hardware projects with the Particle Photon. You do not need any previous experience wiring circuits or programming, but a general use of computer skills would be highly advantageous. Programming the Photon is written to give you a wide variety of experiences and a basic understanding of the many capabilities of the Photon board. This book covers only the basics of how to program the board, on the assumption that you will then expand those skills on your own for your future projects.
I would love to hear your thoughts on this book and would encourage you to contact me through www.rushmakes.com or Twitter (https://twitter.com/chrisrush85).
Christopher Rush
ACKNOWLEDGMENTS
I would like to thank Mike McCabe and the team at McGraw-Hill Education, who have been very supportive and a pleasure to work with once again.
I would also like to dedicate this book to my partner Jennifer Wozniak, who, as always, gives me encouragement and motivation throughout; I would be lost without her by my side.
Programming the Photon
1
Introduction to the Photon
In this chapter you will learn a bit about microcontrollers such as the Arduino as well as the Internet of Things (IoT). The Photon board is a new development board based on its predecessor, the Core, with some new hardware and software features that make it far superior. We will take a look at all those features and compare both boards.
Microcontrollers
A microcontroller is essentially a computer that can control multiple inputs and outputs using some form of programming language. Microcontrollers come in all sorts of shapes and sizes, with the most popular platform being the Arduino. Arduino boards provide a low-cost, easy-to-use technology to create small electronic projects. Modern conventional microcontrollers can be connected to a computer using universal serial bus (USB) to power the board as well as to program the microcontroller; however, they can also easily be removed from USB once the program has been uploaded and powered using some sort of portable battery device and work independently.
Other popular microcontrollers are the Raspberry Pi and BeagleBone boards. Both of these boards are more advanced than the standard Arduino boards and have some video output for connecting to a visual display with a basic operating system such as Debian. These boards feature a vast array of hardware abilities, which can take your electronic projects to another level by providing more storage, input/output pins, faster processing, and audio/video output. All of these options are great, but when you need to connect your projects to the Web, you almost certainly need extra hardware, such as shields or USB dongles, and this adds considerable cost to your projectssometimes more than the microcontroller boards cost themselves. Some variations of boards do include built-in Wi-Fi or Bluetooth technology, such as the Arduino Yun, but this board is still rather expensive at more than $70; once you have added your electronic hardware and various other costs, then your project can easily be in excess of $100.