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
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.
Set Up The Adapter
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:
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:
" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP TKIP group=CCMP TKIP psk="
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:
**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!
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:
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:
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.