Virtually every Raspberry Pi project will require a network connection, and considerable flexibility can be gained by ignoring the Ethernet port in favour of a wireless USB dongle. Knowing which one to use and how to set it up could be make or break for your project.
Ethernet Or Wireless?
When you first acquire your Raspberry Pi, the best option is to use an Ethernet connection to ensure the operating system is correctly configured and up-to-date. You can then move onto a wireless USB connection once you’re happy.
The benefit of Ethernet over wireless LAN on the Raspberry Pi – as with most other platforms – is that there is zero configuration required. All you need to do is ensure the cable is connected to a correctly-configured router, plug it into your Pi and boot it up.
Conversely, setting up wireless LAN on the Raspberry Pi can be tricky. The first thing to do is make sure you have chosen a compatible wireless USB dongle.
Finding A Compatible Wireless USB Dongle
There are various way that you might have acquired your Raspberry Pi. You might, for example, have bought it as a standalone unit and purchased the required additional components, a tactic that can prove more expensive than expected but still cheaper than other computers.
Alternatively, you may have purchased a Raspberry Pi kit, containing the computer, a case, SD card, and other hardware, including the wireless dongle. In this case, you should be confident that the dongle will be compatible with the computer.
Many early buyers of the Raspberry Pi didn’t have the option of a dedicated Wi-Fi dongle, and had to rely on trial and error. This is how the list of compatible hardware was created at elinux.org, which includes a section on wireless USB dongles.
For the best results, you should get your hands on the USB Wi-Fi adaptor distributed through The Pi Hut. This is a Wireless N device that will also work on other platforms (Windows, other Linux distros, Mac OS X) and is available for around $10 plus shipping.
This is the most common Wi-Fi adaptor in use for the Raspberry Pi, and is the one used to outline the process of configuring your WLAN connection below. Note that the following steps are intended for Raspbian users – the general process should be largely the same on your chosen Raspberry Pi distro, however.
Configuring The WLAN Connection
Start by connecting your USB Wi-Fi adaptor to your Raspberry Pi, ensuring the Ethernet cable is also connected. Check your SD card is secure and connect to your power supply.
You’ll need to ensure your version of Raspbian is fully updated, so after you log on, enter:
sudo apt-get upgrade
Alternatively, you can launch into the GUI (enter startx)> and enter the same command in LXTerminal.
Next, check that the USB dongle is detected by your minicomputer – enter lsusb and check the results. The Wi-Fi device should be listed.
Recent versions of Raspbian come with WiFi Config installed, which is why the update is useful, to ensure this is present.
On the desktop, double-click WiFi Config and select wlan0 as the adaptor. On the Current Status tab click Scan and wait for the results – nearby wireless networks will be listed in a new window.
Select the network you wish to connect to, enter the password in the PSK field and then click Connect. Within seconds, your Raspberry Pi should be connected wirelessly, and you can remove the Ethernet cable.
Ensure The Wireless Adaptor Connects At Startup
Many people leave their Raspberry Pi computers running for quite some time without restarting. A result of this is that the newly configured wireless dongle will not require reconnecting as the connection has never dropped.
However, if you regularly shut down your Raspberry Pi, the wireless adaptor, in its current state, will not automatically reconnect. Therefore, attempts to communicate via SSH or VNC will prove fruitless.
Resolve this by switching to command line and entering
sudo cp /etc/network/interfaces /etc/network/interfaces.old
This will copy the existing interfaces file, renaming it to interfaces.old. Should a problem occur with the edits you’re about to make, the original can be renamed and reinstated.
Next, open the interfaces file in a text editor such as pico:
sudo pico /etc/network/interfaces
Here, find the section dedicated to your wireless device, replacing or amending so it reads as follows:
auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
(Note that this configuration is for WPA secured wireless networks.)
When you’re done, click CTRL+X, then Y to confirm your changes and Enter. Complete the change by restarting your Raspberry Pi:
sudo shutdown -r now
When the device reboots, the USB wireless dongle will automatically connect to the previously configured network!
Forget Ethernet – Make Your Raspberry Pi Wireless!
I’d used my Raspberry Pi for over a year before I finally got around to setting it up with a wireless dongle, and I haven’t looked back. I’m sure you won’t either. As long as you use the compatible hardware and take care setting up the SSID and passkey, you’ll wonder why you ever bothered with the Ethernet cable!
Don’t forget to complete your configuration by setting the wireless USB dongle to initialize automatically when your Raspberry Pi boots.
For more tips and information about setting up your Raspberry Pi, see our free guide, Raspberry Pi: The Unofficial Tutorial.