Learning JavaScript Robotics
3/5
()
About this ebook
Related to Learning JavaScript Robotics
Related ebooks
Swift 2 Design Patterns Rating: 0 out of 5 stars0 ratingsLearning Behavior-driven Development with JavaScript Rating: 5 out of 5 stars5/5Node Web Development, Second Edition Rating: 0 out of 5 stars0 ratingsJasmine JavaScript Testing - Second Edition Rating: 0 out of 5 stars0 ratingsModular Programming with PHP 7 Rating: 0 out of 5 stars0 ratingsApplication Development with Qt Creator - Second Edition Rating: 4 out of 5 stars4/5MongoDB High Availability Rating: 5 out of 5 stars5/5AngularJS Deployment Essentials Rating: 0 out of 5 stars0 ratingsBuilding Scalable Apps with Redis and Node.js Rating: 0 out of 5 stars0 ratingsModern Web Development with Deno: Develop Modern JavaScript and TypeScript Code with Svelte, React, and GraphQL (English Edition) Rating: 0 out of 5 stars0 ratingsLearning Node.js for Mobile Application Development Rating: 0 out of 5 stars0 ratingsGame Development with Three.js Rating: 0 out of 5 stars0 ratingsMobile Application Development: JavaScript Frameworks Rating: 0 out of 5 stars0 ratingsLearning NHibernate 4 Rating: 0 out of 5 stars0 ratingsBox2D for Flash Games Rating: 0 out of 5 stars0 ratingsEmber.js in Action Rating: 0 out of 5 stars0 ratingsInstant Highcharts Rating: 0 out of 5 stars0 ratingsHaxe Game Development Essentials Rating: 0 out of 5 stars0 ratingsInstant StyleCop Code Analysis How-to Rating: 0 out of 5 stars0 ratingsCorona SDK Mobile Game Development Beginner's Guide Rating: 5 out of 5 stars5/5Mastering MeteorJS Application Development Rating: 4 out of 5 stars4/5PhantomJS Cookbook Rating: 0 out of 5 stars0 ratingsGetting Started with Ionic Rating: 0 out of 5 stars0 ratingsMockito Essentials Rating: 3 out of 5 stars3/5Metaprogramming in .NET Rating: 5 out of 5 stars5/5Building Python Real-Time Applications with Storm Rating: 0 out of 5 stars0 ratingsFlutter for Jobseekers: Learn Flutter and take your cross-platform app development skills to the next level (English Edition) Rating: 0 out of 5 stars0 ratingsiOS in Practice Rating: 0 out of 5 stars0 ratingsKotlin In-depth [Vol-II]: A comprehensive guide to modern multi-paradigm language Rating: 0 out of 5 stars0 ratingsPhaser III Game Prototyping Rating: 0 out of 5 stars0 ratings
Hardware For You
Fitbit For Dummies Rating: 0 out of 5 stars0 ratingsSamsung Galaxy S23 Ultra User Guide for Beginners and Seniors Rating: 3 out of 5 stars3/5iPhone Photography: A Ridiculously Simple Guide To Taking Photos With Your iPhone Rating: 0 out of 5 stars0 ratingsComputer Science: A Concise Introduction Rating: 4 out of 5 stars4/5CompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5Raspberry Pi Mechatronics Projects HOTSHOT Rating: 5 out of 5 stars5/5iPhone X Hacks, Tips and Tricks: Discover 101 Awesome Tips and Tricks for iPhone XS, XS Max and iPhone X Rating: 3 out of 5 stars3/5Tor Darknet Bundle: Master the Art of Invisibility Rating: 0 out of 5 stars0 ratingsTI-84 Plus CE Graphing Calculator For Dummies Rating: 0 out of 5 stars0 ratingsUsing the TI-84 Plus Rating: 0 out of 5 stars0 ratingsExploring Arduino: Tools and Techniques for Engineering Wizardry Rating: 4 out of 5 stars4/5Raspberry Pi for Secret Agents - Second Edition Rating: 3 out of 5 stars3/5Raspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5iPhone For Seniors For Dummies: Updated for iPhone 12 models and iOS 14 Rating: 4 out of 5 stars4/5Embedded Systems: World Class Designs Rating: 5 out of 5 stars5/5Dancing with Qubits: How quantum computing works and how it can change the world Rating: 5 out of 5 stars5/5Exploring Windows 10 May 2020 Edition: The Illustrated, Practical Guide to Using Microsoft Windows Rating: 0 out of 5 stars0 ratingsBeginning x64 Assembly Programming: From Novice to AVX Professional Rating: 0 out of 5 stars0 ratingsExploring Apple iPad: iPadOS 15 Edition: The Illustrated, Practical Guide to Using your iPad Rating: 0 out of 5 stars0 ratingsExploring Apple Mac - Ventura Edition: The Illustrated, Practical Guide to Using MacOS Rating: 0 out of 5 stars0 ratingsChip War: The Fight for the World's Most Critical Technology Rating: 4 out of 5 stars4/5CompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5iPhone 14 Pro Max User Guide for Beginners and Seniors Rating: 0 out of 5 stars0 ratingsComputer Organization and Design: The Hardware / Software Interface Rating: 4 out of 5 stars4/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Raspberry Pi Cookbook for Python Programmers Rating: 0 out of 5 stars0 ratingsMacs All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsAmazon Web Services (AWS) Interview Questions and Answers Rating: 5 out of 5 stars5/5iPad and iPad Pro For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Learning JavaScript Robotics
1 rating0 reviews
Book preview
Learning JavaScript Robotics - Kassandra Perch
Table of Contents
Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with JS Robotics
Understanding JS Robotics, NodeBots, and Johnny-Five
What a NodeBot is, and other basic vocabulary
Johnny-Five and the NodeBot revolution
What we'll be using in this book
Setting up your development environment
Installing Node.JS
Setting up your project and installing Johnny-Five
Connecting your Microcontroller and installing Firmata
Hello, World! – Blinking an onboard LED
Writing the Johnny-Five script
Running the script
Summary
2. Working with Johnny-Five
What you'll need for this chapter
How a Johnny-Five program works
Objects, functions, and events
Going over our blink-LED script
Understanding events in Johnny-Five
Why events?
Wiring up an external LED
Setting up the hardware
Using the Read-Eval-Print-Loop (REPL)
Making components available to the REPL
Using the REPL
Summary
3. Using Digital and PWM Output Pins
What you'll need for this chapter
How GPIO pins work
Digital output pins
PWM output pins
How to tell the difference between Digital and PWM pins
Multiple pins with several LEDs
Setting up the hardware for the project
Writing the script for the project
Exploring more about LED objects in Johnny-Five
Using PWM pins with the Piezo element
Setting up the hardware
Writing the script
What's going on with the pin?
Exploring the Piezo API
Summary
4. Using Specialized Output Devices
What you'll need for this chapter
Outputs that require multiple pins
Inter-Integrated Circuits (I2C)
Checking compatibility with Johnny-Five
Obtaining documentation, wiring diagrams, and so on
Project – character LCD display
Wiring up – I2C LCDs
The code
The I2C version
The non-I2C version
Running the code
Summary
5. Using Input Devices and Sensors
What you'll need for this chapter
How analog input pins work
Johnny-Five sensor events
Using basic inputs – buttons and potentiometers
Wiring up our button and LED
Coding button-led.js
Wiring the potentiometer and the LED
Coding our dimmer switch
Using sensors – Light and Temperature
Wiring up our photocell
Coding our photocell example
barcli
Coding everything together
Wiring up the temperature sensor
Coding our temperature example
Summary
6. Moving Your Bot
What you'll need for this chapter
The different kinds of servos and motors
Defining motors and servos
Things to keep in mind
Types of motors
Types of servos
Do I use a servo or a motor?
Servo and motor controllers
Motor and servo shields
Special concerns when using motors and servos
Power concerns
Tethering and cables
Wiring up servos and motors
Wiring up servos
Wiring up motors
Creating a project with a motor and using the REPL
Exploring the motor API
Creating a project with a servo and a sensor
Exploring the servo API with the REPL
Summary
7. Advanced Movement with the Animation Library
What you'll need for this chapter
What is the Animation API?
Why do we need an Animation API?
Why animation?
Looking at the Animation API
Learning the terminology
The difference between .to() and the Animation API
Using the ServoArray object
Project – wiring up three servos and creating an array
Writing Servo Animations
Writing keyframes
The keyframe object
Keyframe shorthand
Examples of writing keyframes
Writing segments
Segment options
Multiple servos in one segment
Examples of writing segments
The Animation object
Project – animating our servo array
Animation events
Building a servo array with an informative LCD readout
Summary
8. Advanced Components – SPI, I2C, and Other Devices
What you'll need for this chapter
Why do we need the I2C and SPI protocols?
Exploring SPI (Serial Peripheral Interface) devices
How SPI works
How Johnny-Five does SPI
Benefits and drawbacks of SPI
Building with an SPI device – an LED matrix
The build
The API
Formatting data for the LED matrix
The Drawing functions
The Code
Exploring I2C devices
How I2C works
Pins used by I2C
How I2C devices send and receive data
Benefits and drawbacks of I2C
Benefits
Drawbacks
Building with an I2C device – Accelerometer
Wiring up our accelerometer
Coding up our example
External Devices
Why External Devices?
node-serialport
node-hid
Building a USB gamepad
The hardware
The node-gamepad API
The code
Summary
9. Connecting NodeBots to the World, and Where to Go Next
What you'll need for this chapter
Connecting NodeBots to the Web
It's just a Node Server!
Using Twilio
Building the WeatherBot
Using the TextBot
Johnny-Five and the wide world of microcontrollers
Moving our WeatherBot to the Particle Photon
Tethering and Johnny-Five
Other JS libraries and platforms
Espruino
Tessel
Cylon.js
JerryScript
Tiny Linux computers
Vendor libraries
Where to go from here
Index
Learning JavaScript Robotics
Learning JavaScript Robotics
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2015
Production reference: 1231115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-334-7
www.packtpub.com
Credits
Author
Kassandra Perch
Reviewers
Chris S. Crawford
Tomomi Imura
Commissioning Editor
Neil Alexander
Acquisition Editor
Aaron Lazar
Content Development Editor
Mayur Pawanikar
Technical Editor
Menza Mathew
Copy Editor
Kausambhi Majumdar
Project Coordinator
Nidhi Joshi
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Manu Joseph
Cover Work
Manu Joseph
About the Author
Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them. When she's not building bots, she's knitting, sewing, sculpting, or playing video games with her cats.
I'd like to thank my mentor—as I've said in the past, I don't know where I'd be without you, but I certainly know my life is better with you in it. My parents supported me as a child who took things apart, and their support lets me continue to do so, as well as build things of my own.
The NodeBots community deserves a huge thank you: your sense of wonder and joy in learning new things keeps me going. Special thanks to Rick and Raquel for getting me started.
About the Reviewers
Chris S. Crawford (@chris_crawford_) is a PhD student in Human-Centered Computing at the University of Florida. He is currently a graduate researcher in Brain-Computer Interface Research Group in Human-Experience Research Lab. His research focus is Brain-Robot Interaction, which consists of investigating the ways in which physiological signals such as electroencephalogram (EEG) can be used to enhance human-robot interactions. Chris has experience of working in various areas including perceptual computing, 3D computer graphics, televoting, and native/web app development. Currently, he also serves as a lead software engineer for SeniorGeek Communications, LLC.
Tomomi Imura (@girlie_mac) is an avid open web and open technology advocate, a frontend engineer, and a creative technologist, who has been active in the mobile space for more than 8 years, before she started working with Internet of Things. She loves to hack with hardware and occasionally gives talks at conferences and workshops on prototyping IoT with Raspberry Pi.
She works as a senior developer evangelist at the San Francisco-based data stream provider, PubNub, to support the best developer experiences.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt atwww.PacktPub.com, you can use this to access PacktLib today and view 9entirely free books. Simply use your login credentials for immediate access.
Preface
Hello! Welcome to Learning JavaScript Robotics. In this book, you'll learn how to write code for Arduino and other robotics platforms in JavaScript using Johnny-Five. We'll cover the basics of Johnny-Five, input and output devices, and even movement devices such as servos and motors. Finally, we'll cover how to connect your bots to the Internet and move your Johnny-Five code between different platforms.
What this book covers
Chapter 1, Getting Started with JS Robotics, will get you started by setting up an Arduino Uno and exploring the world of NodeBots.
Chapter 2, Working