Adding Wi-Fi
In This Chapter
The one built-in feature the Raspberry Pi lacks is wireless internet. And that’s rather inconvenient these days, when Wi-Fi is available on just about every other device you own, from your phone to your video game systems—even some kitchen and laundry room appliances have wireless built in. Yet to keep costs down, the Raspberry Pi only includes a wired network adapter.
Don’t worry though. Although this might sound like a big pain, it’s actually very easy to set up wireless on your Raspberry Pi using an inexpensive Wi-Fi USB adapter. (You can usually get a Wi-Fi USB adapter for under $10.)
In this chapter, I show you how to choose a Wi-Fi adapter that works with your Raspberry Pi, install it, and set it up so it works every time you boot up your Raspberry Pi. As you learn throughout this book, not everything is perfect with the Raspberry Pi, so I also share some common testing and troubleshooting tips that enable you to handle any issues you might have with Wi-Fi.
When was the last time you actually used a wired internet connection for your computers? Unless you can’t have Wi-Fi in your home, chances are, you use it for pretty much all of your devices.
With your Raspberry Pi, having wireless is incredibly helpful because you’re not always going to have access to a wired connection. This is especially the case when you’re using your Raspberry Pi for projects you want to keep mobile. But without a built-in wireless adapter, you have to add an external, third-party wireless adapter to your Raspberry Pi. A USB adapter is just what you need to add wireless to your Raspberry Pi.
It’s important to note here that if you have a Model A+, the USB adapter will take up the only USB slot available on your specific model. And even on the Model B, you only have two ports, so you might not be able to connect a USB Wi-Fi adapter, a keyboard, and a mouse all at once. The solution is a powered USB hub, or a hub with its own power adapter. A powered hub provides the power to your USB devices so your Raspberry Pi doesn’t have to. You can find USB hubs at most electronics stores for under $10.
HARDWARE HELPER
A powered USB hub is handy if you want to connect several peripherals to your Raspberry Pi. With a powered hub, you can connect as many USB devices as it supports, which is nice if you want to plug in a keyboard, mouse, and Wi-Fi adapter.
A Wi-Fi adapter won’t work unless it has something to connect to. To set up a wireless network in your home, you’ll need either a router or a built-in router and modem combination unit from your internet provider.
Now let’s pick out a Wi-Fi adapter to work with your Raspberry Pi.
USB Wi-Fi Adapters
Walk into an electronics store, and you’ll find a variety of options for USB Wi-Fi adapters. These range in price based on speed, software support, and compatibility. On almost all of them, you’ll see a bunch of different text and numbers, so let’s take a second to demystify exactly what it all means.
802.11b/g/n/ac: 802.11 is a wireless standard that makes it possible for computers to communicate with each other in the same language. The b/g/n/ac part refers to a version and a data transfer speed.
Mbps: Mpbs stands for “megabits per second.” A megabit is the unit of measurement used for digital information. It’s the standard used for most wireless transfer protocols and the same number you’ll see from your internet provider. The higher the number, the faster the data transfer rate—or the faster you can access websites online. For wireless, you’ll see these letters and numbers on both your Wi-Fi adapter and your router. B is 11 Mbit/s, G is 54 Mbit/s, N is 600 Mbit/s, and AC is 1 gigabit per second. That said, the speed is still limited by your internet connection speed.
DEFINITION
A megabit is 1 million bits, or 1,000 kilobits, which is the equivalent of about 100 pages of plain text. This measurement is usually used when talking about data transfer, so you’ll see it places like your internet service provider bills. For context, a megabyte—the word we use to describe data storage—is 8 megabits combined.
Wireless operating frequency: This refers to the wireless channels in which the adapter can operate. In most cases, this is 2.4 gigahertz (Ghz), which means it can operate in channels 1 through 11. Channels 12 through 14 are restricted by the Federal Communications Commission (FCC) in the United States, but they are allowed in some other countries, including Japan. Canada allows channels 1 through 12, while the UK allows channels 1 through 13. Typically, all this isn’t anything to worry too much about. It just refers to the frequencies at which your router operates. All wireless adapters operate in the same range as your router, so you can typically ignore this setting when you’re buying an adapter.
PI POINTER
It can be useful to change the frequency to get a stronger signal when you’re in an area with a lot of other wireless networks. Think of it like tuning your television by moving or turning the antenna around a little.
Support for WPA-PSK/WPA2-PSK, and WEP Security: These are three different security protocols for your wireless network. When you set up your router, you’ll usually also set up a password or passcode to authenticate certain users so everyone can’t get into your network. WPA stands for “wireless protected access,” and WEP stands for “wired equivalent privacy.”
Nowadays, WPA-PSK isn’t used much and instead, WPA2-PSK is the most commonly used security method. WEP should be avoided because it’s unsecure and prone to unauthorized access. Which system you use depends on your router, but every Wi-Fi adapter is compatible with whichever you use.
Now that we’ve got all the technical language sorted out, it’s time to pick up an adapter to pair with your Raspberry Pi.
Choosing the Right Adapter
The Raspberry Pi is compatible with hundreds of different Wi-Fi adapters, but unlike Windows and OS X, you won’t find a note about compatibility on the adapter’s box. Instead, you’ll need to do some research yourself to find an adapter that works with your Raspberry Pi.
Thankfully, most of that research has already been done for you. You can find a massive list of compatible USB Wi-Fi adapters at elinux.org/RPi_USB_Wi-Fi_Adapters.
If you don’t feel like sorting through that entire list, you can follow the crowd. Many Raspberry Pi users have opted for the Edimax EW-7811Un 150Mbps wireless 11n nano-size USB adapter. This adapter works out of the box with Raspbian and typically costs under $10 at most retailers. You basically can just plug it in and it’ll work right away without an additional setup process.
Where to Buy Your Adapter
You can purchase a Wi-Fi adapter from pretty much any retailer that sells them, but if you want to be certain it will work well with your Raspberry Pi, a few different retailers cater to that. Here are a few worth checking out:
Adafruit: Adafruit (adafruit.com) is a DIY electronics store packed full of all kinds of Raspberry Pi accessories. Everything Adafruit sells is verified to work with the Raspberry Pi.
MCM Electronics: Like Adafruit, MCM Electronics (mcmelectronics.com) offers a ton of Raspberry Pi accessories and verifies that they work with the Raspberry Pi.
element14: element14 (element14.com) is not just an electronics retailer; it’s also a landing spot for all kinds of Raspberry Pi content. You can order just about everything you need from them, including a selection of Wi-Fi adapters guaranteed to work with the Raspberry Pi.
Once you have your Wi-Fi adapter in hand, it’s time to set it up.
HARDWARE HELPER
Don’t spend a lot of money on an adapter. Any inexpensive adapter will do what you need, and any benefits of a more expensive adapter won’t be useful on the Raspberry Pi because it’s such a low-powered device.
You have to do some minor setup for your Wi-Fi adapter before you can access the internet wirelessly. First, you need to connect your Wi-Fi adapter to your Raspberry Pi’s USB port. Then boot up your Raspberry Pi.
You can use Raspbian’s graphical interface or the command line to set up Wi-Fi for your Raspberry Pi, and it works in both places. So if you set it up with the graphical interface and then exit out to the command line, your wireless connection will continue to work.
Setting Up Wi-Fi with Raspbian’s Graphical Interface
Most modern versions of Raspbian include drivers for Wi-Fi adapters, so it’s actually very easy to set up. Here’s how:
Setting up your Wi-Fi adapter with Raspbain’s graphical interface takes just a few clicks of your mouse.
You should now have wireless internet access on your Raspberry Pi.
Setting Up Wi-Fi with the Command Line
If you’re not using Raspbian, or if you just want to get a little more familiar with the command line, you can set up your Wi-Fi adapter right from the command line. In this case, you’ll just need to edit a few lines of code:
sudo nano /etc/network/interfaces
This opens an editor screen of your Wi-Fi configuration file.
It’s easy to set up your Wi-Fi adapter using the command line.
Reboot your Raspberry Pi by typing in Reboot
at the command line. When it’s finished booting, your Wi-Fi adapter should now work.
Now that your Wi-Fi adapter is up and running, it’s time to check that it’s working properly. You can do this in one of two ways—via the Midori web browser or the command line.
Here’s how to test your connection using Midori:
Here’s how to test your connection using the command line:
ping
, followed by a website address. For example, tryping google.com
.Now your Raspberry Pi’s Wi-Fi should be working correctly.
Troubleshooting
With the newest versions of Raspbian, setting up Wi-Fi is a pretty smooth experience. However, things can go wrong. An adapter might not be included with the Raspbian drivers, or you might run into a problem where the Wi-Fi drops off periodically. Likewise, other Raspberry Pi operating systems don’t always come with the drivers needed to use a Wi-Fi adapter out of the box.
In this section, I show you how to manually find and install drivers for your adapter as well as give you a fix for one of the Raspberry Pi’s most common Wi-Fi problems.
PI POINTER
Troubleshooting on the Raspberry Pi can be very difficult because there’s often not a lot of support from manufacturers. Thankfully, there is a lot of community support for the Raspberry Pi, so if you search online for an answer, you’ll likely find responses in forums and on blogs. These are usually just as useful as an official response, so if you’re having trouble, be sure to give them a try.
Manually Finding and Installing Drivers
If your Wi-Fi adapter isn’t supported out of the box—that is, if your Raspberry Pi doesn’t immediately recognize or work well with your adapter—you’ll need to do a little bit of digging to find the necessary drivers for your adapter to start the setup process. This is most likely only going to happen if you buy a brand-new Wi-Fi adapter that uses a different technology from the older ones your Raspberry Pi already knows, or if you’re not running Raspbian.
DEFINITION
A driver is a small bit of software that tells your computer how to interact with hardware. Without a driver, the computer doesn’t understand that a new piece of hardware is connected and can’t use it.
You’ll work from the command line. And you’ll need your Raspberry Pi connected to the internet through the Ethernet cable. (If you’re using the Model A+, you’ll need to use your USB Wi-Fi adapter.) You can run these commands from either LXTerminal or the regular command line:
ifconfig
and look for your wireless adapter listed in the wlan0 section. If it’s there, your device is recognized, so go back to the setup section and run through the process again. If it’s not listed, proceed to step 2.
Use the ifconfig
screen to check for your adapter.
sudo apt-get update
to update your package list.sudo apt-get install
to install the new package list.sudo apt-cache search
your wi-fi adapter name
, replacing “your wi-fi adapter name” with the manufacturer name. You should see a list that includes your Wi-Fi adapter. You might need to try a few different variations of the name to find it. Make a note of the name listed in the search results.sudo apt-get -install
name from previous step
, replacing “name from previous step” with the name you wrote down in step 4. It should look something like sudo apt-get -install firmware-ralink
.This should get your Raspberry Pi’s Wi-Fi up and running. If not, head to the website of your adapter’s manufacturer and look for specific setup instructions.
Fixing Common Drop-Out Issues
One common problem that plagues the Raspberry Pi is random drop-outs, or when your wireless connection loses the connection to the router. This is a pain when you’re trying to do just about anything.
Thankfully, the fix is pretty simple. You’re going to turn to the command line again and edit a file.
At the command line, type in the following:
sudo nano /etc/modprobe.d/8192cu.conf
This edits the configuration file. Then, type this:
#Disable power saving
options8192cu rtw_power_mgnt=ø rtw_enusbss=1
rtw_ips_mode=1
Tap Ctrl+X to save and exit the editor. Then reboot your Raspberry Pi. Your connectivity problems should now be resolved.