ebook img

Make: JavaScript Robotics: Building NodeBots with Johnny-Five, Raspberry Pi, Arduino, and BeagleBone PDF

487 Pages·2015·23.27 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Make: JavaScript Robotics: Building NodeBots with Johnny-Five, Raspberry Pi, Arduino, and BeagleBone

Make: JavaScript Robotics Rick Waldron, Anna Gerber, David Resseguie, Emily Rose, Susan Hinton, Sara Gorecki, Bryan Hughes, Andrew Fisher, Julian David Duque, Pawel Szymczykowski, Donovan Buck, Jonathan Beri, Kassandra Perch, Raquel Vélez, Lyza Danger Gardner Make: JavaScript Robotics by Backstop Media and Rick Waldron Copyright © 2015 Backstop Media, LLC. All rights reserved. Printed in Canada. Published by Maker Media, Inc., 1160 Battery Street East, Suite 125, San Francisco, California 94111. Maker Media books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our distributor’s corporate/institutional sales department: 800-998-9938 or [email protected]. Editor: Brian Jepson Production Editor: Melanie Yarbrough Copyeditor: Tracy Brown Hamilton Proofreader: Jasmine Kwityn Indexer: Meghan Jones, WordCo Indexing Interior Designer: David Futato Cover Designer: Brian Jepson Cover Photographer: Pawel Szymczykowski Illustrator: Rebecca Demarest April 2015: First Edition Revision History for the First Edition 2015-04-03: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781457186950 for release details. The Make logo and Maker Media logo are registered trademarks of Maker Media, Inc. Make: JavaScript Robotics and related trade dress are trademarks of Maker Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Maker Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. have been printed in caps or initial caps. While every precaution has been taken in preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. 978-1-45718695-0 [TI] Preface By Rick Waldron I love programming and I also love making things. When I discovered Chris Williams’ node-serialport module (for Node.js), I remember thinking, “Now I can program the things that I make.” So I did! I contributed an Arduino sketch that printed a photoresistor sensor value to the open serial port and a small JavaScript handler program that listened for data and printed a “graph” to the terminal. Months later, I started contributing to Cam Pedersen’s duino project, until Julian Gaultier approached me with his JavaScript implementation of the Firmata protocol. From there, we set out to build a collection of high-level component classes with one goal: to make it easy and fun to control hardware with JavaScript. This book will show you what we built and how to use it to program the things that you make. While the physical challenges of engineering a hardware project remain the same as they would for a project programmed in any other language, this book is going to show you how to think about that hardware in terms of objects that maintain state and provide control behaviors in the form of intuitively designed interfaces. So, how would you verbally describe adding an LED to a project and then turning it on? You might say, “Connect the LED to ground and pin 9, then turn it on.” Using the Johnny-Five framework, that would be written as: // Connect the LED to ground and pin 9 var led = new five.Led(9); // then turn it on led.on(); What about connecting a servo and then setting its horn to a specific angle in degrees? “Attach the servo to pin 10 and position its horn to 110°.” Here’s what that looks like: // Attach the servo to pin 10 var servo = new five.Servo(10); // position its horn to 110° servo.to(110); These examples both illustrate an output, but what about input? Consider how Arduino sketches work: they generally rely on a program loop and often introduce some form of delay when reading and processing input. This means that your Arduino sketch is blocked whenever it is waiting for input. When writing programs in JavaScript, the process is never blocked; instead, your handlers wait for data to arrive and process it asynchronously: var sensor = new five.Sensor("A0"); sensor.on("data", function() { console.log(this.value); }); These are trivial examples, but they illustrate the patterns that you will see repeated consistently throughout this book. Each project will show you how to construct it in the physical sense, then construct it in the abstract programming sense, and the latter will align with the former. With these concepts, you will build and program: Walkers, typers, swimmers, and rovers (Chapters 1, 2, 3, and 4) A dancing hexapod (Chapter 5) Voice-activated relay control (Chapter 6) An indoor sundial (Chapter 7) Holiday, mood, or anytime lighting (Chapters 8 through 10) A security and notification system (Chapter 11) Sonar-based artificial intelligence (Chapter 12) A delta bot (Chapter 13) Musical shoes (Chapter 14) For me, the most exciting part about this book is the authors themselves. This group is an excellent representation of NodeBots community members that have stood out since the very beginning. They are more than just writers or engineers: they are teachers, communicators, leaders, and (in my opinion) heroes. It would be an understatement to say that I couldn’t have done it without them. Enough talk, more rock. These projects do not have to be done in any specific order, so take a look at the Table of Contents, find a project that sounds like fun, order, so take a look at the Table of Contents, find a project that sounds like fun, and start building! Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values determined by context. This element signifies a tip, suggestion, or general note. This element indicates a warning or caution. The part numbers in each chapter use the following abbreviations: MS: Maker Shed AZ: Amazon AF: Adafruit SF: SparkFun Using Code Examples This book is here to help you get your job done. In general, you may use the This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from Make: books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Make: JavaScript Robotics by Jonathan Beri, Donovan Buck, Julian David Duque, Andrew Fisher, Lyza Danger Gardner, Anna Gerber, Sara Gorecki, Susan Hinton, Bryan Hughes, Kassandra Perch, David Resseguie, Emily Rose, Pawl Szymczykowski, Raquel Velez, Rick Waldron (Maker Media). Copyright 2015 Backstop Media, 978-1- 4571-86950.” If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at [email protected]. Safari® Books Online Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training. Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals. Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online. How to Contact Us Please address comments and questions concerning this book to the publisher: Maker Media, Inc. 1160 Battery Street East, Suite 125 San Francisco, CA 94111 Make: unites, inspires, informs, and entertains a growing community of resourceful people who undertake amazing projects in their backyards, basements, and garages. Make: celebrates your right to tweak, hack, and bend any technology to your will. The Make: audience continues to be a growing culture and community that believes in bettering ourselves, our environment, our educational system — our entire world. This is much more than an audience; it’s a worldwide movement that Make: is leading — we call it the Maker Movement. For more information about Make:, visit us online: Make: magazine: http://makezine.com/magazine Maker Faire: http://makerfaire.com Makezine.com: http://makezine.com Maker Shed: http://makershed.com All source code for the examples in this book can be found at: https://github.com/rwaldron/javascript-robotics. We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at: http://bit.ly/1KUV1p2. If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at [email protected]. Acknowledgments Julián Duque NodeBots is all about learning while having fun and especially for me it’s a way to achieve social impact. Everything started at NodeConf 2013 — it was my first time using Johnny-Five on a NodeBots workshop guided by Rick Waldron and Raquel Velez. My first attempt was with a piezo buzzer, but at that time the library didn’t support the Piezo class, so I asked Rick how to use it and he said to me, “I wasn’t able to make it work, how about a pull request?” That’s how I started contributing to the project. On the other hand, Raquel gave me my first Arduino kit as a gift and told me, “Take this with you and teach what you’ve learned in Colombia.” That humble action was so inspiring for me and I started a NodeBots chapter in Medellín, Colombia. I also helped create the communities in Uruguay, Guatemala, and Mexico through workshops and talks. Rick and Raquel, thank you so much for inspiring me and letting me be part of this Maker revolution.

Description:
JavaScript Robotics is on the rise. Rick Waldron, the lead author of this book and creator of the Johnny-Five platform, is at the forefront of this movement. Johnny-Five is an open source JavaScript Arduino programming framework for robotics. This book brings together fifteen innovative programmers,
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.