Book Image

Learning JavaScript Robotics

By : Kassandra Perch
Book Image

Learning JavaScript Robotics

By: Kassandra Perch

Overview of this book

Table of Contents (16 chapters)
Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding JS Robotics, NodeBots, and Johnny-Five


JavaScript as a robotics language truly began a few years ago with the creation of node-serialport—an NPM module written by Chris Williams. This module allows Node.JS to communicate with devices over a serial connection; this can include the typical serial connections from older computers, or the USB and Bluetooth connections that we use every day. What exactly is a NodeBot though, and how do we get started with using them with Johnny-Five?

What a NodeBot is, and other basic vocabulary

A NodeBot is any piece of hardware that is controlled using JavaScript and/or Node.JS. This can encompass a wide variety of projects; there are hundreds of ways to create a NodeBot. In this book, we are going to use the Johnny-Five library, an open source project created by Rick Waldron.

Note

For those readers who are new to robotics, a microcontroller is a small computer that contains a processor, memory, and input/output pins. This serves as the brain of our project—our programs will communicate with or will be loaded onto this microcontroller. Microcontrollers come in many shapes and sizes, and with multiple capabilities.

We're going to use a microcontroller for our projects. What microcontroller should you use? Luckily, our use of Johnny-Five means that we can choose from a large array of different microcontrollers and still write the same code as you'll see in this book!

What exactly is Johnny-Five, and how does it make our lives easier?

Johnny-Five and the NodeBot revolution

Johnny-Five (http://johnny-five.io) is an open source robotics library for Node.JS. It was created by Rick Waldron and has a thriving community of contributors and supporters. This module has been known to work on Windows, Mac, and Linux computers without any issues at the time of writing this book using Node.JS version 4.x.

Johnny-Five was built on top of node-serialport and allows us to write JavaScript applications that communicate with different microcontrollers using different types of connection. For some microcontrollers, such as Arduino-compatible boards, Johnny-Five uses a serial connection. For some newer boards, Johnny-Five emulates this serial connection over an Internet service!

The capability of Johnny-Five to use multiple board types is implemented using its wrapper system. Once the core system is installed, you can install a wrapper for your particular microcontroller, and the APIs will remain the same. This is a powerful concept—you can write code for one platform and quickly move it to another without having to change it.

What we'll be using in this book

For the examples in this book, we'll use an Arduino Uno board. You can get these boards from sites such as Adafruit (www.adafruit.com), SparkFun (www.sparkfun.com), and so on. You can also use a board that is Arduino Uno-compatible. SainSmart, for instance, sells Uno-like boards that will work fine for our purposes. For this chapter, you'll need the board itself and a USB cable for it.

In later chapters, we'll be using other components—there will be a table in each chapter with an accessible list of materials for the projects within.