Book Image

Hands-On Robotics with JavaScript

By : Kassandra Perch
Book Image

Hands-On Robotics with JavaScript

By: Kassandra Perch

Overview of this book

JavaScript has an effective set of frameworks and libraries that provide support for embedded device programming and the robotics ecosystem. You’ll be able to put your JavaScript knowledge to work with this practical robotics guide. The book starts by guiding you in setting up an environment to program robots with JavaScript and Rasberry Pi 3. You will build beginner-level projects, such as a line-following robot, and then upgrade your robotics skills with a series of projects that help you get to grips with the Johnny-Five library. As you progress, you’ll learn how you can improve your projects by enabling advanced hardware components and programming concepts. You’ll even build an advanced AI-enabled robot, connect its NodeBots to the internet, create a NodeBots Swarm, and explore Message Queuing Telemetry Transport (MQTT). By the end of this book, you will have enhanced your robot programming skills by building a range of simple to complex projects.
Table of Contents (19 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

What is the Raspberry Pi?


So, now you've got this green, credit-card-sized object with a bunch of ports that you recognize, and a bunch of pins, as shown in the following diagram. You can see some chips, and some parts you might not recognize. Before we talk about the power contained in this rather inconspicuous board, we need to clear up some vocabulary that we'll be using throughout the book:

 

Microcontrollers

Microcontroller is a term that encapsulates a bunch of devices. It's a term used to describe a device that contains a processor, memory, and input/output peripherals (or ways to interact with those peripherals) that is meant for a particular type of task. One extremely common microcontroller is the Arduino Uno, and the Raspberry Pi technically falls into this category as well.

 

General-Purpose Input/Output (GPIO) pins

Microcontrollers interface with devices such as sensors, LEDs, and buttons using electrical signals that are sent and received through pins designed for input and/or output signals. These pins can be broken into multiple subcategories, as we'll find out in subsequent chapters, but you can address them as GPIO pins as a whole. We'll use that abbreviation throughout the book.

Debian and Raspbian

Debian is a distribution of Linux that is considered extremely user friendly for those new to using Linux. It contains many utilities that are commonly used while working with Linux preinstalled, and is compatible with a lot of the peripherals that you would use with a computer, such as Wi-Fi cards and USB devices.

Raspbian is a modified version of Debian specifically designed to run on Raspberry Pi devices. There are drivers for the GPIO pins, USB Wi-Fi devices, and expansion slots on the Pi that allow you to attach a specific display and camera. 

There are two flavors of Raspbian—Raspbian Full and Raspbian Lite. Full has a graphical desktop with programs aimed at educational programming and development. Lite (which we will be using for the projects in this book) only has a command-line interface, but still has full functionality when it comes to Raspberry Pi peripherals. As of the time of writing, the current version of Raspbian is 4.14, nicknamed Stretch.

Johnny-Five and Raspi-IO

Back in 2012, Rick Waldron wrote a node-serialport program to operate an Arduino Uno with Node.js, and formed a library around it called Johnny-Five. Since then, the Johnny-Five library has grown to over 100 contributors, and can control over 40 platforms, including the Raspberry Pi! It can also control many kinds of sensors and peripherals that you can use to create the robotics project you've been dreaming of in Node.js!

One of the ways the Johnny-Five library has grown to support so many platforms is by creating what are called IO plugins. You create an IO plugin for each type of board you wish to control. For example, we will be installing and using the Raspi-IO plugin to use Johnny-Five with the Raspberry Pi.

 

What is great about this system is that the code you write in this book can be used on any other platform that Johnny-Five supports (you just need to change PIN numbers)! Writing code for Node.js botnets is much easier when you're using the same APIs for any devices you might use.

So, the Pi is technically a microcontroller...

Let's get back to the question of what the Raspberry Pi is. In short, it is a microcontroller. It has dozens of GPIO pins and can be used to interface with many physical peripherals in order to achieve specialized tasks. The low cost and small size allows the Raspberry Pi to be a versatile device, but the power involved allows you to use it for tasks that other microcontrollers may not pack the punch for.

...but it is also a computer!

An interesting fact about the Raspberry Pi is that, while it is a microcontroller, it can also be used as a fully fledged computer! While it certainly isn't the most powerful hardware, with full Raspbian installed, a Raspberry Pi attached to a monitor, keyboard, and mouse creates a great machine for kids and adults to learn programming on! The original intent of the Raspberry Pi was to create a low-cost educational machine to teach programming, and it exceeded every expectation in that regard. The fact that it's also a great microcontroller for the world of makers is a great bonus!