Learning JavaScript Robotics
eBook - ePub

Learning JavaScript Robotics

  1. 160 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Learning JavaScript Robotics

Book details
Book preview
Table of contents
Citations

About This Book

Design, build, and program your own remarkable robots with JavaScript and open source hardware

About This Book

  • Learn how to leverage Johnny-Five's Read, Eval, Print Loop, and Event API to write robot code with JavaScript
  • Unlock a world of exciting possibilities by hooking your JavaScript-programmed robots up to the internet and using external data and APIs
  • Move your project code from the Arduino Uno to a multitude of other robotics platforms

Who This Book Is For

If you've worked with Arduino before or are new to electronics and would like to try writing sketches in JavaScript, then this book is for you! Basic knowledge of JavaScript and Node.js will help you get the most out of this book.

What You Will Learn

  • Familiarise yourself with Johnny-Five Read, Eval, and Print Loop (REPL) to modify and debug robotics code in real time
  • Build robots with basic output devices to create projects that light up, make noise, and more
  • Create projects with complex output devices, and employ the Johnny-Five API to simplify the use of components that require complex interfaces, such as I2C
  • Make use of sensors and input devices to allow your robotics projects to survey the world around them and accept input from users
  • Use the Sensor and Motor objects to make it much easier to move your robotics projects
  • Learn about the Animation API that will allow you to program complex movements using timing and key frames
  • Bring in other devices to your Johnny-Five projects, such as USB devices and remotes
  • Connect your Johnny-Five projects to external APIs and create your own Internet of Things!

In Detail

There has been a rapid rise in the use of JavaScript in recent times in a variety of applications, and JavaScript robotics has seen a rise in popularity too. Johnny-Five is a framework that gives NodeBots a consistent API and platform across several hardware systems.

This book walks you through basic robotics projects including the physical hardware builds and the JavaScript code for them. You'll delve into the concepts of Johnny-Five and JS robotics.

You'll learn about various components such as Digital GPIO pins, PWM output pins, Sensors, servos, and motors to be used with Johnny-Five along with some advanced components such as I2C, and SPI. You will learn to connect your Johnny-Five robots to internet services and other NodeBots to form networks. By the end of this book, you will have explored the benefits of the Johnny-Five framework and the many devices it unlocks.

Style and approach

This step-by-step guide to the Johnny-Five ecosystem is explained in a conversational style, packed with examples and tips. Each chapter also explores the Johnny-Five documentation to enable you to start exploring the API on your own.

Frequently asked questions

Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Learning JavaScript Robotics by Kassandra Perch in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation Open Source. We have over one million books available in our catalogue for you to explore.

Information

Year
2015
ISBN
9781785883347

Learning JavaScript Robotics


Table of Contents

Learning JavaScript Robotics
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with JS Robotics
Understanding JS Robotics, NodeBots, and Johnny-Five
What a NodeBot is, and other basic vocabulary
Johnny-Five and the NodeBot revolution
What we'll be using in this book
Setting up your development environment
Installing Node.JS
Setting up your project and installing Johnny-Five
Connecting your Microcontroller and installing Firmata
Hello, World! – Blinking an onboard LED
Writing the Johnny-Five script
Running the script
Summary
2. Working with Johnny-Five
What you'll need for this chapter
How a Johnny-Five program works
Objects, functions, and events
Going over our blink-LED script
Understanding events in Johnny-Five
Why events?
Wiring up an external LED
Setting up the hardware
Using the Read-Eval-Print-Loop (REPL)
Making components available to the REPL
Using the REPL
Summary
3. Using Digital and PWM Output Pins
What you'll need for this chapter
How GPIO pins work
Digital output pins
PWM output pins
How to tell the difference between Digital and PWM pins
Multiple pins with several LEDs
Setting up the hardware for the project
Writing the script for the project
Exploring more about LED objects in Johnny-Five
Using PWM pins with the Piezo element
Setting up the hardware
Writing the script
What's going on with the pin?
Exploring the Piezo API
Summary
4. Using Specialized Output Devices
What you'll need for this chapter
Outputs that require multiple pins
Inter-Integrated Circuits (I2C)
Checking compatibility with Johnny-Five
Obtaining documentation, wiring diagrams, and so on
Project – character LCD display
Wiring up – I2C LCDs
The code
The I2C version
The non-I2C version
Running the code
Summary
5. Using Input Devices and Sensors
What you'll need for this chapter
How analog input pins work
Johnny-Five sensor events
Using basic inputs – buttons and potentiometers
Wiring up our button and LED
Coding button-led.js
Wiring the potentiometer and the LED
Coding our dimmer switch
Using sensors – Light and Temperature
Wiring up our photocell
Coding our photocell example
barcli
Coding everything together
Wiring up the temperature sensor
Coding our temperature example
Summary
6. Moving Your Bot
What you'll need for this chapter
The different kinds of servos and motors
Defining motors and servos
Things to keep in mind
Types of motors
Types of servos
Do I use a servo or a motor?
Servo and motor controllers
Motor and servo shields
Special concerns when using motors and servos
Power concerns
Tethering and cables
Wiring up servos and motors
Wiring up servos
Wiring up motors
Creating a project with a motor and using the REPL
Exploring the motor API
Creating a project with a servo and a sensor
Exploring the servo API with the REPL
Summary
7. Advanced Movement with the Animation Library
What you'll need for this chapter
What is the Animation API?
Why do we need an Animation API?
Why animation?
Looking at the Animation API
Learning the terminology
The difference between .to() and the Animation API
Using the ServoArray object
Project – wiring up three servos and creating an array
Writing Servo Animations
Writing keyframes
The keyframe object
Keyframe shorthand
Examples of writing keyframes
Writing segments
Segment options
Multiple servos in one segment
Examples of writing segments
The Animation object
Project – animating our servo array
Animation events
Building a servo array with an informative LCD readout
Summary
8. Advanced Components – SPI, I2C, and Other Devices
What you'll need for this chapter
Why do we need the I2C and SPI protocols?
Exploring SPI (Serial Peripheral Interface) devices
How SPI works
How Johnny-Five does SPI
Benefits and drawbacks of SPI
Building with an SPI device – an LED matrix
The build
The API
Formatting data for the LED matrix
The Drawing functions
The Code
Exploring I2C devices
How I2C works
Pins used by I2C
How I2C devices send and receive data
Benefits and drawbacks of I2C
Benefits
Drawbacks
Building with an I2C device – Accelerometer
Wiring up our accelerometer
Coding up our example
External Devices
Why External Devices?
node-serialport
node-hid
Building a USB gamepad
The hardware
The node-gamepad API
The code
Summary
9. Connecting NodeBots to the World, and Where to Go Next
What you'll need for this chapter
Connecting NodeBots to the Web
It's just a Node Server!
Using Twilio
Building the WeatherBot
Using the TextBot
Johnny-Five and the wide world of microcontrollers
Moving our WeatherBot to the Particle Photon
Tethering and Johnny-Five
Ot...

Table of contents

  1. Learning JavaScript Robotics