Reader small image

You're reading from  Learning JavaScript Robotics

Product typeBook
Published inNov 2015
Reading LevelIntermediate
Publisher
ISBN-139781785883347
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Kassandra Perch
Kassandra Perch
author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch

Right arrow

Chapter 4. Using Specialized Output Devices

Now that we know how output pins (both digital and PWM) work, we're going to take a look at specialized output devices. These devices use multiple pins for one device for a number of reasons: some use protocols that are widely known, some are proprietary, some just require a lot of pins to output a lot of data. We'll take a look at a few of the well-known protocols and build a project with one such device: a character LCD, reminiscent of a calculator. This chapter will cover the following topics:

  • Outputs that require multiple pins

  • Checking compatibility with Johnny-Five

  • Obtaining documentation, wiring diagrams, and so on

  • Project – character LCD display

What you'll need for this chapter


For the project in this chapter, you'll need your board, a USB cable, and a character LCD character display. A breadboard and a handful of breadboard wires will also come in handy.

We will go over how to use character LCDs with or without an I2C interface. An example of one with an I2C interface can be found here: http://www.amazon.com/SainSmart-Serial-Module-Display-Arduino/dp/B00813HBEQ. A way to quickly identify an I2C-compatible character LCD is by the backpack that is presoldered on to it, as shown in the following examples. It only uses four pins labeled as VCC, GND, SDA, and SCL:

Examples of I2C backpacks on character LCDs

An example of a character LCD without an I2C interface is available here: https://www.adafruit.com/products/181. The main visible difference is that these character LCDs use more than the four pins used by I2C interfaces.

Note

Note that these may also require assembly by soldering!

The following screenshot is an example of this:

A non...

Outputs that require multiple pins


There are many types of output, many of which only need one output pin for data, such as LEDs and the Piezo element that we used in the last few chapters. However, there are nearly an infinite number of output devices that we can use—many of them require more complicated instructions than one output pin is capable of sending.

These devices work in several different ways, and while the exact ways are well beyond the scope of this book, we'll go over a few very common types. For this chapter, however, we'll just go over the I2C, because it is the common format for the device that we will use in this chapter's project.

Inter-Integrated Circuits (I2C)

I2C, or Inter-Integrated Circuits, are output devices that can share the same set of two data pins. The data pins are usually called SCL (Serial Clock Line) and SDA (Serial Data Line), where SCL handles timing and SDA sends data. The reason you can wire many devices to one pair of digital output pins is because in...

Checking compatibility with Johnny-Five


It's easy to find a lot of different devices online, but how do you know what will work with Johnny-Five? and will it work on Johnny-Five for your particular board?

Luckily, the Johnny-Five website at www.johnny-five.io can easily tell you this, and you just need to follow a few steps in order to determine what type of device you are looking at.

First, let's take a look at the website at www.johnny-five.io. There are several tabs, but for now, we're looking for the Platform Support tab:

The johnny-five.io header

Once you are on the Platform Support page, look for the board you're using. If you're using Arduino Uno, your search should be short—it's at the top of the page!

The Platform Support page entry for Arduino Uno

As you can see, there's a table for compatibility with each board entry. If you're not using an Arduino Uno, quickly check whether or not your board has I2C compatibility before buying or trying to use an I2C character LCD.

Obtaining documentation, wiring diagrams, and so on


A good skill to have when building your own Johnny-Five projects is finding code and wiring diagrams for the components that you'd like to use. Luckily, the www.johnny-five.io website and the project provide a thorough and top-notch documentation right there on the site!

Let's take a look at the LCD documentation on the site to prepare us for building our project:

  1. In the header of the site, click on the API tab.

  2. Then, you'll see a list of components on the left (if you're on a desktop) or at the top (if you're on a tablet or phone).

  3. Find and click the LCD entry in this list.

    The API documentation page

Once you are on the LCD page, you'll see a bunch of different LCD components, a section on the LCD API, and some links to examples at the bottom. There is a page like this for every component in Johnny-Five, so it's easy to find out how to get started with just about every component that has already been adapted.

Let's take a look at the LCD API...

Project – character LCD display


For our project, we're going to connect our character LCD to our Arduino Uno board and use Johnny-Five to print some messages on it. I'll be using an I2C display, but will include wiring diagrams and code for non-I2C versions as well.

Wiring up – I2C LCDs

First, we'll describe how to wire up an I2C LCD. Note that the image diagram will look different, because no component exists in the imaging software for the I2C backpack. There is an accompanying diagram to clarify your queries.

You'll want to look for the pins labeled SCL and SDA on the back of your LCD unit—these pins need to be connected to two pins on the Arduino Uno that are not clearly labeled on all units. These pins are near the USB connector and the reset button. With the USB connector facing left, the pins are on the left-most side of the top rail of pins—on the left is SCL, and on the right is SDA. On newer boards, these are labeled on the side of the pin railing.

Once these are in place, you'll want...

Summary


In this chapter, we've looked at how to use specialized inputs by walking through the documentation on johnny-five.io. The knowledge used here will allow you to use many different components that you come across in your robotics adventures. Just be sure that, if you find a new component and write the code, you contribute it back to Johnny-Five to make it better for everyone else!

In the next chapter, we will learn how to use many different input devices and sensors in order to build Johnny-Five projects.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learning JavaScript Robotics
Published in: Nov 2015Publisher: ISBN-13: 9781785883347
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Kassandra Perch

Kassandra Perch is an open web developer and supporter. She began as a frontend developer and moved to server-side with the advent of Node.js and was especially enthralled by the advance of the NodeBots community. She travels the world speaking at conferences about NodeBots and the fantastic community around them.
Read more about Kassandra Perch