Chapter 8. Going Truly Mobile – The Remote Control of Your Robot

Based on the previous chapters, you now have mobile robots that can move around, accept commands, see, and even avoid obstacles. This chapter will teach you how to electronically communicate with your robot without using any wires.

As you send your device out into the world, you may still want to communicate with it electronically without connecting a cable. If you add this capability, you can change what your mobile robot is doing without any physical contact but still remain in complete control of your project.

In this chapter, we will cover the following points:

  • Connecting Raspberry Pi to a wireless USB input device
  • Using the wireless USB input device in order to issue commands to your project
  • Connecting to your robot over wireless LAN
  • Connecting to your robot over Zigbee

Gathering the hardware

In this chapter, you'll learn how to connect to your device wirelessly. There are several ways to accomplish this. The first way that we'll cover in this chapter is to do this with a standard USB wireless input device. This is, perhaps, the easiest way to control your robot but only provides basic functionality with a limited range. The second way to connect to your robot that you will learn is via a wireless LAN device; this provides an excellent bandwidth and good range but requires a bit more hardware. This will provide you with the opportunity to both control your robot and see what it is seeing.

Finally, in this chapter, we will cover communicating with your robot wirelessly via a dedicated wireless link called ZigBee. It will provide the same sort of control as with the wireless USB device but with a much greater range.

No matter what you choose, you will probably want to purchase a small LCD display first for your Raspberry Pi. This will allow you to monitor what is going on with your project. In the previous chapters, you used a separate computer monitor for this. However, the monitor is just too big and not really designed for mobile use. Fortunately, there are several inexpensive choices for small LCDs with SVideo input that connect right to Raspberry Pi. The following is an image of the device I have used for some of my projects:

Gathering the hardware

This type of LCD is available on Amazon and other online electronics stores, so you should be able to get it at almost any place. One of the challenges, however, is that most of these are designed for auto applications and may require 12 volts to operate. I have been lucky; each one of the devices that I have ordered has worked just fine at 5 volts. However, if you want to make sure that you get one that is compatible, you can order it from adafruit.com; they have a set of devices that is compatible with Raspberry Pi. Also, there are several versions of LCDs that are made for Raspberry Pi as a plugin cape, but I like the standalone versions better, only because they give me more flexibility in mounting the unit. However, there is one challenge. You will need to power the LCD, which is one of the reasons why I like to choose a dual-output USB battery for my projects. The following is an image of such a battery:

Gathering the hardware

You'll also need to order a power adapter for your LCD screen, depending on how it accepts power. The LCD shown in the previous image comes with an adapter that has a red and a black wire connector output. If the unit can work at 5 volts, you can connect the LCD to your cell phone battery USB connector using a USB-to-TTL Serial cable. In this case, you'll plug the red and black connectors out of your LCD into the red and black connectors on the USB-to-TTL serial cable. You can also plug the LCD into the battery connector that is set up for your robot if it supplies between 5 to 12 volts.

Just a quick note on battery selection. You'll need to keep in mind two key characteristics when you buy your battery. The first is the size of the battery, normally noted in mAh or milliAmpHours. This is a measure of the capacity of the battery, which will tell you how long a battery might last while drawing a certain current. For example, if you purchased a 2000 mAh battery and drew an average of 100 mAmps, this battery would theoretically last for 20 hours. However, it won't last that long. For, as the battery discharges, the voltage will start to drop as well, and eventually, you won't be able to power your system. The voltage drop depends on the quality of the battery.

The second key characteristic is the amount of current you can draw at any given time. Most batteries give a C rating, and if you divide the mAh rating by this value, you will get the amount of instantaneous current that you can draw. This value is important because this will need to estimate the amount of power you need to draw from your electronics. For example, Raspberry Pi can draw as much as 500 mAmps, so you'll need to make sure you get a battery that can supply this kind of current.

Now that you have a screen, you can display the results on the robotic platform itself. No extra programming is needed; the Raspbian release will automatically send signals to the LCD screen and boot with the screen acting as a display. After the system boots, it will look something like what is shown in the following screenshot:

Gathering the hardware

Now that you can display what is going on inside Raspberry Pi, you need to choose the wireless connection that you'd like to use. If you just need to send basic control signals to your device and you are always going to be close, a 2.4 GHz wireless keyboard is the best choice.

The following image is of a standard 2.4 GHz wireless keyboard:

Gathering the hardware

This is a Logitech keyboard. Logitech generally makes very reliable keyboards, and these connect well to Raspberry Pi. This keyboard is available online on Amazon and at most electronics or computer stores. You'll notice that this version has a built-in mouse pad.

Another option is a small keyboard that looks more like a game controller. It will make your projects look amazing and will make it easier to control. The following is an image of such a keyboard:

Gathering the hardware

This 2.4 GHz wireless keyboard by HausBell is small, about the size of a game controller, relatively inexpensive and is sold online, again by Amazon.

For this application, there are several choices that you could make for wireless technology to communicate with Raspberry Pi. Bluetooth is quite popular and works well. However, it comes with the added complexity of having to pair the device with the Bluetooth USB dongle and the system. The 2.4 GHz wireless technology comes with the keyboard and wireless USB receiver already paired. So, the device only works with the USB dongle that is shipped with the device, and the system automatically recognizes the device as long as the USB receiver is plugged into the USB port of Raspberry Pi.

The 2.4 GHz wireless devices work with the same frequency range as many 2.4 GHz wireless LAN devices, although they do not use the same modulation or protocol that is used by the standard 2.4 GHz wireless LAN. Rather, they use a proprietary modulation and protocol that is specific to the device and company that manufactures the device. There are more details on the 2.4 GHz wireless keyboards at http://www.logitech.com/images/pdf/emea_business/2.4ghz_white_paper.pdf.

While each device is different, most use the same overall approach where they define a number of different channels or small frequency ranges inside the overall range of 2.4 GHz. The keyboard communicates with the USB receiver on one of these frequencies. However, if either the keyboard or the USB receiver senses that some other device is transmitting on that frequency, the device will move to a different channel to try and avoid the interference.

The transmissions between the wireless keyboard and USB receiver are encrypted, so no device except the paired keyboard and USB receiver can understand the messages that are being sent between the two devices. The range of the keyboard and receiver pair is dependent upon the amount of power both use for transmission; the higher the power, the longer the range. Unfortunately, the higher the power, the less is the time for which the batteries in the wireless device last. Most wireless keyboards are designed to work for up to 10 meters or around 30 feet.

Sometimes, you may want to have a physical connection with your Raspberry Pi, and want not only to control your robot but also connect via VNC Viewer, so you can access the display of Raspberry Pi; in such a case, wireless LAN is the best choice. For this, you'll need to purchase a supported wireless LAN device. The following is an image of such a device:

Gathering the hardware

It is best to choose a device that is known to be supported by your Raspbian release. Check the http://elinux.org/RPi_USB_Wi-Fi_Adapters link for a list of these devices. Note that you'll need access to a wireless LAN signal, so you'll need to supply this by connecting to your own wireless LAN. This can come from a wireless LAN router that you have already set up, a spare wireless LAN router that can set up an ad hoc network, or many of today's smart cell phones, which also allow you to turn your device into a hotspot that can provide this signal.

If you'd like to have basic communication with your device but want to do it at a significant distance, ZigBee provides a possible solution. There are a number of different types of devices; one is a USB stick-type ZigBee device (www.zigbee.org), and the following is an image of such a device:

Gathering the hardware

Also, there are devices made to connect with Linux systems such as Raspberry Pi. The following is an image of one of these devices:

Gathering the hardware

This is the device we will use in this chapter. Make sure you purchase an XBee Series 1 device as it is the easiest device to configure and use, and there is a great open source community support for the device too. If you choose a different device, you'll need to follow the directions for that device from the manufacturer. Also, if you want to use this type of point-to-point communications, you'll need two units, one for Raspberry Pi and the other for the host computer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.113.166