Learning Javascript Robotics: Design, build, and program your own remarkable robots with JavaScript and open source hardware
3/5
()
About this ebook
Kassandra Perch
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.
Related to Learning Javascript Robotics
Related ebooks
Internet of Things Programming with JavaScript Rating: 0 out of 5 stars0 ratingsRaspberry Pi :Raspberry Pi Guide On Python & Projects Programming In Easy Steps Rating: 3 out of 5 stars3/5Simulation-Driven Electronics Design: The easy way to design your own electronics projects (English Edition) Rating: 0 out of 5 stars0 ratingsSmart Internet of Things Projects Rating: 4 out of 5 stars4/5Raspberry Pi: The complete guide to raspberry pi, including raspberry pi projects, tips, troubleshooting, and more! Rating: 0 out of 5 stars0 ratingsProgramming Constructs in Java Rating: 1 out of 5 stars1/5Deploying Node.js Rating: 5 out of 5 stars5/5Practical XMPP Rating: 0 out of 5 stars0 ratingsApache Solr PHP Integration Rating: 0 out of 5 stars0 ratingsNodeJS: Programmare Web-App Con Javascript: Programmazione Web, #3 Rating: 0 out of 5 stars0 ratingsNode Cookbook Rating: 0 out of 5 stars0 ratingsCorona SDK Mobile Game Development: Beginner's Guide - Second Edition Rating: 0 out of 5 stars0 ratingsWeb Development with Blazor: A practical guide to building interactive UIs with C# 12 and .NET 8 Rating: 0 out of 5 stars0 ratingsResponsive Design High Performance Rating: 0 out of 5 stars0 ratingsProjects with IOTA Rating: 0 out of 5 stars0 ratingsNoSQL Essentials: Navigating the World of Non-Relational Databases Rating: 0 out of 5 stars0 ratingsMastering Google App Engine: Build robust and highly scalable web applications with Google App Engine Rating: 0 out of 5 stars0 ratingsJavascript Mastery: In-Depth Techniques and Strategies for Advanced Development Rating: 0 out of 5 stars0 ratingsMastering jQuery UI Rating: 0 out of 5 stars0 ratingsNode Web Development, Second Edition Rating: 0 out of 5 stars0 ratingsNW.js Essentials Rating: 0 out of 5 stars0 ratingsNode.js Blueprints Rating: 0 out of 5 stars0 ratingsLearning AngularJS Animations Rating: 4 out of 5 stars4/5Instant Hands-on Testing with PHPUnit How-to Rating: 0 out of 5 stars0 ratingsIonic 2 Cookbook - Second Edition Rating: 0 out of 5 stars0 ratings
Hardware For You
iPhone 16 Pro Max User Manual: The Complete Step-By-Step Guide to Maximize your New iPhone 16 Pro Max and iOS 18 Rating: 0 out of 5 stars0 ratingsMastering ChatGPT Rating: 0 out of 5 stars0 ratingsChip War: The Fight for the World's Most Critical Technology Rating: 4 out of 5 stars4/5Electrical Engineering | Step by Step Rating: 0 out of 5 stars0 ratingsCompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5Unlock Any Roku Device: Watch Shows, TV, & Download Apps Rating: 0 out of 5 stars0 ratingsBuild Your Own PC Do-It-Yourself For Dummies Rating: 4 out of 5 stars4/5Exploring Arduino: Tools and Techniques for Engineering Wizardry 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/5Macs All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsLinux All-in-One For Dummies Rating: 3 out of 5 stars3/5Linux All-In-One For Dummies Rating: 2 out of 5 stars2/5Raspberry Pi Cookbook for Python Programmers Rating: 0 out of 5 stars0 ratingsLearning Android Forensics Rating: 4 out of 5 stars4/5CompTIA A+ Complete Study Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 0 out of 5 stars0 ratingsmacOS Sequoia For Dummies Rating: 0 out of 5 stars0 ratingsAmazon Web Services (AWS) Interview Questions and Answers Rating: 5 out of 5 stars5/5iPhone For Dummies, 2025 Edition Rating: 0 out of 5 stars0 ratingsHacking Electronics: Learning Electronics with Arduino and Raspberry Pi, Second Edition Rating: 0 out of 5 stars0 ratingsLearning RSLogix 5000 Programming Rating: 5 out of 5 stars5/5Creative Selection: Inside Apple's Design Process During the Golden Age of Steve Jobs Rating: 5 out of 5 stars5/53D Printing For Dummies Rating: 4 out of 5 stars4/5CompTIA A+ Complete Practice Tests: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 0 out of 5 stars0 ratingsINSTANT PLC Programming with RSLogix 5000 Rating: 4 out of 5 stars4/5M2 Mac Book Air User Guide: Features, Tips, and Tricks With Pictures Rating: 0 out of 5 stars0 ratingsArduino Essentials Rating: 5 out of 5 stars5/5iPhone For Dummies Rating: 0 out of 5 stars0 ratingsmacOS Ventura 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.
Support files, eBooks, discount offers, and morehttps://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