Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Hands-On Robotics with JavaScript

You're reading from   Hands-On Robotics with JavaScript Build robotic projects using Johnny-Five and control hardware with JavaScript and Raspberry Pi

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789342055
Length 214 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Kassandra Perch Kassandra Perch
Author Profile Icon Kassandra Perch
Kassandra Perch
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Setting Up Your Development Environment FREE CHAPTER 2. Creating Your First Johnny-Five Project 3. Building Interactive Projects with RGB LED 4. Bringing in Input with Buttons 5. Using a Light Sensor to Create a Night-Light 6. Using Motors to Move Your Project 7. Using Servos for Measured Movement 8. The Animation Library 9. Getting the Information You Need 10. Using MQTT to Talk to Things on the Internet 11. Building a NodeBots Swarm 12. Assessments 13. Other Books You May Enjoy

Installing Node.js, Johnny-Five, and Raspi-IO

So, now that our Raspbian OS is installed and set up, it's time to install Node.js (which comes bundled with npm), Johnny-Five, and Raspi-IO!

Installing Node.js and npm

In days past, you would have to compile the Node.js source on your Pi, to varying degrees of success because of the nonexistence of binaries for the ARM processor that Raspberry Pi uses. Luckily now, because of a rousing amount of third-party support in the past few years, you can easily download the binary from the https://nodejs.org/en/ website! But how are we going to do this from the command line of our Raspberry Pi? 

Detecting your version of ARM processor

If you're using the Raspberry Pi 3 Model B recommended by this book, you're most likely on ARM v8 (the Raspberry Pi 3 original is ARMv7, which is fine too!). But you should always double-check (doubly so if you're using a different Raspberry Pi, such as the Pi Zero or Pi 2/1 series). To check the ARM version on your Raspberry Pi, run the following in your SSH Terminal:

uname -m

You'll see a return message that looks like armv#, where # is a number (possibly followed by a letter). That number is what is important, because that number tells us which Node.js binary we will need. Once you have your ARM version, go through the following steps:

  1. Head to the Node.js download page at https://nodejs.org/en/download/, as shown in the following screenshot:
A snapshot of the Node.js binary download page
  1. Right-click on the ARM version link you need and copy the URL. Then, run the following in your Raspberry Pi's SSH Terminal:
wget <binary-download-url>

Replace <binary-download-url> (carats, too!) with the URL you copied from the Node.js download website. Once it's downloaded, we need to extract the archive using the following code:

tar -xvf node-v****-linux-armv**.tar.xz
  1. The asterisks will differ depending on the current LTS version of Node.js and your ARM version. The Raspberry Pi will spit out a lot of filenames to the console, then give you back your shell prompt. This means that the binaries have been extracted into your home folder. We need to place them into the /usr/local folder. To do that, run the following:
cd node-v****-linux-armv** 
sudo mv ./lib/* /usr/local/lib
sudo mv ./share/* /usr/local/share
  1. This will move all of the precompiled binaries to their new homes on your Raspberry Pi. Once this is done, run the following:
node -v
npm -v

You should see something like the following:

Successful Node.js installation results
  1. If that's all well and good, you now have Node.js and npm installed! Let's wrap this up with Johnny-Five and Raspi-IO! Note that you can absolutely clean up the binary downloads by running the following:
cd ~
rm -rf node-v**-linux-armv**
rm -rf node-v****-linux-armv**.tar.xz

Some of you with more Debian experience may be asking, well, why can't we just use apt-get? The short answer is that the package with the name node was taken a very long time ago, and because that is the case, and because sudo apt-get install nodejs is outdated (at the time of writing, using this command will install v4 when we need v8+, if it installs Node.js at all), we need to download the binaries and move them ourselves.

Installing Johnny-Five and Raspi-IO

To install Johnny-Five, once you've made sure Node.js and npm are installed, run the following command:

npm i -g johnny-five raspi-io

This installs the libraries globally; you won't have to reinstall it every new project. And that's it! You're ready to start developing Node.js robotics projects on the Raspberry Pi with Johnny-Five!

You have been reading a chapter from
Hands-On Robotics with JavaScript
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789342055
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime