Home Page Icon
Home Page
Table of Contents for
Contributors
Close
Contributors
by Kassandra Perch
Hands-On Robotics with JavaScript
Title Page
Copyright and Credits
Hands-On Robotics with JavaScript
Dedication
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Setting Up Your Development Environment
Technical requirements
What is the Raspberry Pi?
Microcontrollers
General-Purpose Input/Output (GPIO) pins
Debian and Raspbian
Johnny-Five and Raspi-IO
So, the Pi is technically a microcontroller...
...but it is also a computer!
How we will use the Raspberry Pi
Taking advantage of all that the Raspberry Pi has to offer!
Johnny-Five – letting us code hardware in Node.js
Installing the operating system
Downloading Raspbian Lite
Burning the image to an SD card
Editing files on the SD card
Booting up the Pi
SSHing from a Linux or Mac
SSHing from Windows
Setting up your password and hardware interfaces
First things first – change your password!
Updating the Raspberry Pi
Turning on the hardware interfaces
Installing Node.js, Johnny-Five, and Raspi-IO
Installing Node.js and npm
Detecting your version of ARM processor
Installing Johnny-Five and Raspi-IO
Summary
Questions
Further reading
Creating Your First Johnny-Five Project
Technical requirements
Creating a project folder
Setting up npm to manage our modules
Getting started with Johnny-Five and Raspi-IO
Gathering resources and documentation
Taking a look at the LED-blink project
Raspberry Pi pin numbers
Wiring up an LED
Putting together and attaching the cobbler
Attaching the resistor and LED
Making the LED blink
Putting your code on the Raspberry Pi
Running your code
Summary
Questions
Further reading
Building Interactive Projects with RGB LED
Technical requirements
Looking at the LED and LED.RGB API
The LED object
The Led.RGB object
PWM pins and GPIO expanders
How do PWM pins work?
Why we need a GPIO expander
Wiring up our GPIO expander and RGB LED
Bringing in other node packages
Project – building a rainbow
Using the color npm module
Getting our Johnny-Five code started
The REPL – a powerful tool in Johnny-Five
How does the REPL work?
Adding our RGB LED to the REPL
Controlling our LED from the command-line interface
Summary
Questions
Further reading
Bringing in Input with Buttons
Technical requirements
Using inputs in robotics projects
Digital versus analog input
How to handle analog input with the Raspberry Pi
Analog GPIO expanders
Using input devices with digital interfaces
How Johnny-Five handles input
The structure of a typical Johnny-Five project
The beginning – including libraries and creating our board object
The board ready event handler
Constructing our component objects
Input event handlers and output device manipulation
The Johnny-Five button object
The button object
Button events
Wiring up buttons
Putting a button on a breadboard
Using a pull-down resistor
Adding buttons to our RGB LED project
Wiring everything up
Using the power and ground side rails
Wiring up the buttons
Button 1 – stop and start rainbow 
Refactoring the rainbow cycle
Button 2 – next color
Summary
Questions
Further reading
Using a Light Sensor to Create a Night-Light
Technical requirements
Using an analog sensor with the Pi
Finding the right sensors for your Pi project
I2C devices
SPI 
How to determine if your sensor will work with Johnny-Five
The ambient light sensor
Wiring up the sensor
Writing a program to get readings and print them to the command line
The Johnny-Five sensor events
Handling sensor data in the event handler
Using and formatting Johnny-Five sensor data
Using .scaleTo() and .fscaleTo() to fine-tune measurements
Printing sensor data to the command line
Using barcli to make the data easier to see
Importing barcli and constructing our barcli graph
Getting the bar graph to update
Creating our night-light
Wiring up the LED
Coding this project
Summary
Questions
Further reading
Using Motors to Move Your Project
Technical requirements
More about motors
How to control a motor with a microcontroller
Preparing for a motor-driven project with Raspberry Pi
Putting the hat together
Putting the hat on the Pi
The Johnny-Five motor object
Constructors for our hat
Functions that move the motor
Adding REPL control
Loading and running your motor
Troubleshooting your motorized projects
Project – cat toy
Putting a piece of paper on the motor shaft
Coding the randomness to start/stop the motor
Project – using two gearbox motors and the motors object
Wiring up your TT motors
The motors Johnny-Five object
Writing some functions
Running our motors project
Summary
Questions
Using Servos for Measured Movement
Technical requirements
Differences between motors and servos
Calculated movements
Regular versus continuous servos
Powering servos and motors
Getting a servo working with Johnny-Five
The Johnny-Five servo object
Wiring the servo to our PWM hat
Coding your first servo sweep
Project – two servos and the REPL
Wiring up a second servo
Using the Johnny-Five servos object
Adding the Servos object to our code
Adding in REPL functionality
Playing with our servos on the command line
Project – light meter with the servo
Adding in the light sensor
Making the servo into a meter
Coding the project
Running and using our light meter
Project – the continuous servo
Wiring up the servo
Continuous servo constructor and methods
Using the REPL with the continuous servo
Playing with the continuous servo in the REPL
Summary
Questions
The Animation Library
Technical requirements
Animating movement
Why we need the animation library
Moving servos with true precision
Implicit use of the animation library
Using servo.to() to implicitly create an animation
Playing with implicit animations
Playing with implicit animations, take two
The terminology of the animation library
The construction of the animation object
Creating the animation object
Planning out the animation sequence
Creating keyframes
Using null and false as positions in keyframes
Programming our keyframes 
Setting cue points and duration
Putting it all together to make an animation
Watching your animation at work
Easing into your servo animations
How easing fits into an animation segment
Adding easing to our first animation
Easing an entire animation segment
Learning more about queuing and playing animation segments
Looping animation segments
Changing the speed of animation segments
Playing, pausing, and stopping animation segments
Tying it all together in the REPL
Summary
Questions
Getting the Information You Need
Technical requirements
Why connect your NodeBots to the internet?
Using the power of npm modules
Using the data you collect
Some things to keep in mind
Getting weather data on our Pi with OpenWeatherMap
Getting an OpenWeatherMap API key
Bringing in request
Parsing the response
Building a weather dashboard with an LCD
Adding an LCD to the Pi
The LCD object
Constructing our LCD
Setting up the LCD
Printing to and clearing the LCD
Coding it all together
Project – scraping data from websites with your Pi
Scraping downforeveryoneorjustme.com for johnny-five.io
Making the HTTP request
Using Cheerio to get the element we want
Parsing the HTML and showing the result
Summary
Questions
Further reading
Using MQTT to Talk to Things on the Internet
Technical requirements
IoT device communications
Long polling
Websockets
MQTT - an IoT PubSub protocol
The basics of MQTT
Setting up MQTT on the Pi with AdafruitIO
Creating an account and a feed
Subscribing to the feed using the mqtt npm module
The mqtt module
The dotenv module 
Testing our connection
Project – adding an LCD and button to see and send MQTT events
Wiring it all up
Coding it all together
Project – social media notifier bot with IFTTT
Getting started with IFTTT
Linking IFTTT to Adafruit
Setting up feeds for your social media MQTT messages in AdafruitIO
Creating our IFTTT Applets
Wiring up our project
Coding our social media notifications to show on the LCD
Running your social media bot
Summary
Questions
Further reading
Building a NodeBots Swarm
Technical requirements
Project – connecting multiple NodeBots
Optional – setting up a second Raspberry Pi
Setting up your project files and folders
If you're using one Pi
If you're using two Pis
Adding a light sensor to the Pi
Creating an MQTT broker on the Pi
Programming the MQTT client – have the Pi Report Home
If you're using one Pi
If you're using two Pis
Running our MQTT project
If you're using one Pi
If you're using two Pis
Expanding your NodeBots knowledge
Using Johnny-Five on other boards
Figuring out pin numbers
Checking the platform support page
Other node robotics platforms
The Tessel 2
The Espruino ecosystem
Programming graphically with Node-RED
Continuing on your NodeBots adventure
Figuring out what to build
Reaching out to the NodeBots community
Where to go to learn more about Electronics
Summary
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Other Books You May Enjoy
Leave a review - let other readers know what you think
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
PacktPub.com
Next
Next Chapter
About the author
Contributors
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset