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 the operating system

In order to get started with Johnny-Five and the Raspberry Pi, we will need to set up the Raspbian operating system by burning it to a microSD card. Then, we'll need to edit some files on the SD card in order for the Raspberry Pi to boot with Wi-Fi and the ability to SSH in. Lastly, we'll need to boot up the Raspberry Pi and get some settings in place before finally installing Node.js, Johnny-Five, and Raspi-IO.

Downloading Raspbian Lite

The following steps will show you how to download Raspbian Lite:

  1. The first step is downloading the Raspbian Lite image so we can burn it to our microSD card. The best place to get the image from is https://www.raspberrypi.org/downloads/raspbian/, as shown in the following screenshot:
A screenshot of the Raspbian download page, with both Full and Lite download links
  1. Select RASPBIAN STRETCH LITE (or whichever version is the current one), which will replace the word STRETCH. Give yourself some time for this step to complete; although Raspbian Lite is much smaller than Raspbian Full, it is still several hundred megabytes, and can take time to download!
If you're preparing to run a class, hackathon, or some other event using the Raspberry Pi and Raspbian, it's best to predownload it and place it on a flash drive to hand around, as conference and event Wi-Fi can be a bit slower than normal, or even drop in and out, so be prepared!

Burning the image to an SD card

Luckily, the tools for burning OS images to SD cards have evolved arcane command-line tools that can overwrite your computer's hard drive as easily as it can the SD card. My current favorite is called Etcher, and it can be downloaded for any platform at https://etcher.io/, as shown in the following steps:

  1. The free version is more than enough for our needs, so download and install it as you download Raspbian Lite.
  2. Once they are both downloaded, you'll want to place the micro SD card in your computer, either by placing it into a full-sized SD adapter and then into a slot on your computer, or by using a USB-to-micro-SD adapter. Whichever you use, make sure your computer can see the volume as a drive before continuing. Then, boot up Etcher. The following screenshot shows Etcher running on a Mac:
A screenshot of the Etcher program running on a Mac
  1. Once you see a window similar to the preceding screenshot, you'll need to select the Raspbian Lite image you just downloaded. You don't even need to unzip the .zip file—Etcher can handle that outright! Once you've selected the image, Etcher should select your micro SD card drive, so long as your machine can see it! Once you've ensured that the image and micro SD card drive are properly selected, hit Flash! to begin the process.
Sometimes, with larger micro SD cards, you'll get a warning from Etcher about the drive being very large (this happens to me when I use 64 GB cards). This is to prevent you from overwriting your computer's hard drive. You can bypass the warning by going through a confirmation window—just be absolutely sure that your micro SD card drive is selected first!

A few minutes will pass as Etcher burns the image to your micro SD card, then verifies that it is present on the card. Once this is done, remove and reinsert the micro SD card so that your computer recognizes it as a drive again; the drive should be named boot. We're not quite done editing the image files yet, so Etcher's polite attempt to eject the micro SD card drive needs to be ignored.

Editing files on the SD card

We need to edit and create some files on our Raspberry Pi's image in order to be able to access it with SSH when we turn on the Raspberry Pi. First, we'll set up the Wi-Fi using the following steps:

If you're using an Ethernet cable and port to connect the Raspberry Pi to the internet, you can skip this step. If this doesn't get the Wi-Fi to work, you'll want to look at the information box under the section Booting up the Pi for troubleshooting steps and an alternative (if clunkier) way to set this up.
  1. In order to set up the Wi-Fi, you'll want to create a file in the root of the micro SD card drive called wpa_supplicant.conf that contains the following text:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={ ssid="yourNetworkSSID" psk="yourNetworkPasswd" }

  1. Replace yourNetworkSSID with the SSID of the Wi-Fi network you wish to connect to, and then replace yourNetworkPasswd with that Wi-Fi's network password.
The Raspberry Pi's Wi-Fi chip can only connect to 2.4 GHz networks at the time of writing, so you need to make sure that you input a network that operates on that bandwidth or your Raspberry Pi will not be able to connect!
  1. After you've set up the Wi-Fi network, you'll want to tell the Raspberry Pi to allow you to SSH into it. To do this, you'll want to create a file called ssh in the same root folder as the wpa_supplicant.conf file. Make sure that the ssh file is empty and has no extension. When you're all done, the root directory of the micro SD card drive will look similar to the following screenshot:
A list of files on the micro SD drive, once I've made my edits

Once this is all done, fully eject the microSD drive, take the microSD card and insert it into the Raspberry Pi. We're now ready to boot up the Raspberry Pi and start installing software.

Booting up the Pi

Once the micro SD card is inserted, plug your power source into your Raspberry Pi. A red and green LED should light up. The red LED should be solid—this is the power indicator. The green light will flicker on and off—this is the LED that indicates activity. The Raspberry Pi should take a maximum of a minute or so to boot up once you've plugged it in. Next, we'll SSH in. 

SSHing from a Linux or Mac

If you're on a Mac or Linux machine, you'll open up a Terminal and type the following:

ssh pi@raspberrypi.local

If you're successful, you'll see a question appear, asking about the authenticity of the host. Respond by typing yes and hitting Enter. You'll then be asked for a password, which is raspberry, as shown in the following screenshot: 

Successful SSH into a Raspberry Pi from a Mac Terminal

Once you've entered the password, you should see the following:

Successful login to a Raspberry Pi via SSH from a Mac

SSHing from Windows

In order to SSH from a Windows machine, you'll need to use a program called PuTTY. You can get it on https://putty.org/. But first, you'll want your Raspberry Pi's IP address. You'll need a monitor, an HDMI cable, and a USB keyboard. Once you have these, go through the following steps:

  1. Plug the monitor, HDMI cable, and USB keyboard into the Raspberry Pi before booting it up. Then plug in the power supply.
  2. When it prompts you for a username, type pi. When it asks for a password, enter raspberry. Once you are logged in, type ifconfig. You should see a lot of information appear.
  3. Look for the wlan0 section and the inet address under that heading. For the following output, the IP is 192.168.1.106, as shown in the following screenshot. Write this IP down. Then, you can unplug the display and the keyboard—you won't need them again:
Getting the IP address from the Terminal
  1. Once you have the IP address for your Raspberry Pi, you can boot up PuTTY. The window that opens is the configuration window, as shown in the following screenshot: 
The PuTTY configuration window
  1. Type the IP address that you obtained into the field labeled Host Name (or IP address) and click the Open button. You'll be asked about the authenticity of the host (only the first time you connect). Select Yes. Then enter Pi as the username and raspberry as the password when prompted. Once that's done, you should see the following:
Successful login to the Raspberry Pi with PuTTY

Now that everyone's logged in, let's set up our Raspberry Pi for our projects!

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