How To Set Up WiFi on the Raspberry Pi

Raspberry Pi WiFi SetupSetting up WiFi on your Raspberry Pi is easier than you think

Setting up WiFi on the Raspberry Pi can be a little tricky for new users, especially those not using the main Desktop interface.

It involves editing files in the Terminal which is a normal task for most of us, but probably a bit daunting for anyone just starting out. It’s easier than you think, and takes no more than 10 minutes.

There are lots of benefits of having a WiFi enabled Raspberry Pi. A very common use is to run the Pi without a monitor, allowing you to SSH in to the Pi or even use VNC to see the full desktop on your PC/Laptop.

WiFi on the Pi also lets you make cool ‘connected’ projects – I’ve seen it used in bird house monitors, fish tanks and also in my Raspberry Pi CCTV system!

Media Centres benefit as well. Using a WiFi adapter lets me set up a RaspBMC media centre connected to my NAS in rooms with no ethernet ports, which is great for streaming music and videos around the home.

Let me show you how to set up WiFi on your Raspberry Pi!

What You Need
There isn’t much kit involved in this tutorial, mostly standard stuff you’ve probably already got. To get WiFi up and running, you’ll need:

  • A Raspberry Pi running Raspbian
  • A USB WiFi Adapter – I recommend an Edimax adapter. They’re cheap, low power, and also have a blue indication light which can be handy for troubleshooting (and looks cool!)
  • A Keyboard
  • A Mouse
  • A HDMI screen
  • Your WiFi SSID (i.e. ‘BTHomeHub12345’)
  • Your WiFi password

Skipping The Unnecessary
 
As always, I’m going to try and bring you a simple version of the truth here. There are lots of additional steps you can take when setting up WiFi, but I don’t really find them necessary.

For example, there is a process you can follow to make sure that your WiFi adapter is being recognised by the Pi correctly, and the driver loaded. I used to do this every time, but soon stopped bothering as I’ve never had an adapter not recognised on any of my Pis, using all different kinds of adapters.
 
This tutorial is showing you the simple steps I take every time, which works (for me) – every time.
 
Set Up
 
First, connect your screen, keyboard, mouse and WiFi adapter to the Pi, turn it on, and log in to the Terminal as usual. 

Set Up The Adapter

Run the following command to open the network interfaces configuration file, where we make sure the adapter is set up:
 sudo nano /etc/network/interfaces  

Once you’re in there, you want to edit the text lines so it looks the same as my screenshot example below – you’ll have most of it in there already. This part sets up Ethernet as well in case you ever need to use it (thanks to Dougie Lawson for the ‘auto eth0’ tip).

Here’s the text if you want to copy and paste:

 auto lo  
 iface lo inet loopback  
 
 auto eth0  
 iface eth0 inet dhcp  
 
 auto wlan0  
 allow-hotplug wlan0  
 iface wlan0 inet manual  
 wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf  
 
 iface default inet dhcp  


And here’s the screenshot:

Raspberry Pi Interfaces File

Edit the interfaces file to match what I have here


Press ‘Ctrl+X’, then ‘Y’ to save, then finally press ‘Enter’ to save the file under the same name.

Add Network Information

The next step is to add your WiFi details to the wpa_supplicant file so that your adapter knows which network to connect to, and the password to get access. (As the title suggests, this setup is for WPA protected networks)

Run the following command to open up the wpa_supplicant file:

 sudo nano /etc/wpa_supplicant/wpa_supplicant.conf  

 

This file will probably only contain the following lines just now:

 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  
 update_config=1  

 

What we need to do is add your router information and password after this text. Here is the ‘template’ text which you can simply copy and paste in – all you need to do is change the sections for the SSID and Password sections in red:

 network={  
 ssid="YOUR-SSID"  
 proto=RSN  
 key_mgmt=WPA-PSK  
 pairwise=CCMP TKIP  
 group=CCMP TKIP  
 psk="YOUR-PASSWORD"  
 }

 

Press ‘Ctrl+X’, then ‘Y’ to save, then finally press ‘Enter’ to save the file under the same name.

You can add more blocks of this text if you want to set up your Raspberry Pi for multiple networks – good if you travel with your Pi and want it to automatically connect to different networks depending on where you are.

Here’s what mine looks like – I have 2 routers set up here:
Raspberry Pi SSID File

Here I have two routers set up, which is as simple as making a new block of text after the first


**UPDATE 12/01/15 – Additional Step – Setting Non-Default parameters**

Although up to this point my method of getting WiFi working had been fine (i.e. the rest of this guide), I always found it somewhat unreliable at times. WiFi would hang, drop out and generally perform poorly.

I also noticed that the light on my Edimax WiFi adapter would go into ‘sleepy mode’ – a constant flash with no real activity ‘flickering’. After asking the question on the Raspberry Pi forum, Dougie Lawson (a VERY good guy to know!) gave me these instructions which fixed my problem:

Create a new file using the following command:

 sudo nano /etc/modprobe.d/8192cu.conf  


Then paste this line in (just paste it in one line as it is):

 options 8192cu rtw_power_mgnt=0 rtw_enusbss=0 rtw_ips_mode=1  


Save the file by pressing Ctrl+X, under the same file name.

That should sort out any iffy WiFi connections – it did for me!

Reboot

As before, I’ve skipped some of the steps to initially test that the adapter is working as I’ve never come across an instance where this hasn’t worked (unless I’ve got my SSID/Password wrong). We do run a quick test after reboot though.

Run the following command to reboot your Raspberry Pi, then give it a couple of minutes to come back to life:

 sudo reboot  

 

Test

To test if your Pi is now indeed WiFI enabled and connected to your network, I usually use an Android app called ‘Fing’ which shows all devices on your network. You can do this the traditional way by logging in to your router, but I find using my phone quicker.

Here’s my Raspberry Pi showing on Fing – easily identifiable by the ‘Edimax Technology’ line:

Fing IP Address

The ‘Fing’ app gives me the IP address and name of the device

Done!

That’s it – your Raspberry Pi is now running WiFi! You can now use tools like Putty to SSH in remotely just using the IP address, username and password.

I hope you’ve found this tutorial easy to follow – I think some of the other guides out there give you a lot of steps that aren’t necessary for the ‘average’ user just wanting to get WiFi up and running…although I’ll probably eat my words if I come across problems one day!

Lastly, if you want to configure WiFi using the GUI – Raspberry Pi Spy has a great tutorial over on his site.

If you get stuck, please comment below.

Average Man

5 Comments on "How To Set Up WiFi on the Raspberry Pi"

  1. …or you can do it with my script automatically 😉 -> http://goo.gl/T2g1ou

  2. You need to add

    auto eth0

    to your interfaces file. If you don't have WiFi and choose to use an ethernet cable the interface won't come up active and you won't get a default route assigned.

  3. Ah yes, good shout. I'll update now. I rarely use Ethernet which is probably why it isn't in there.

  4. Hi,
    I’m preparing myself for the RasPi3…
    How do I set a special Channel? In Germany we can also use channel 12 and 13.
    Do I have to configure something somewhere?
    /H.

    • Hi Herbert

      I haven’t done that myself – I’m actually using my only Pi 3 as a media centre as I couldn’t resist the extra power!

      Try the official forums, I imagine you’d get a reply the same day.

Leave a comment

Your email address will not be published.


*