Adding a WiFi option to the Raspberry Pi is an easy way to set your raspberry free so you dont have to worry about running network cables when deploying a raspberry pi project.
You are going to need the following:
- A Raspberry Pi
- A USB WiFi Adapter (I use the Edimax - Wireless 802.11b/g/n nano USB adapter)
- A SD Card flashed with the Raspbian OS (Here is a guide if you need)
- Access to the Raspberry either via keyboard and a monitor or remotely
Adding WiFi adapter to the Raspberry Pi
Plug the USB WiFi adapter into one of the free USB ports on the Raspberry Pi. Power up the Raspberry Pi - remember at this point the WiFi adapter does not work yet. You are still going to need some other means of being able to control the Raspberry Pi either via a keyboard or remotely using a wired network connection.
To verify the WiFi adapter was detected after boot run the following command:
dmesg | more
You can use the spacebar to scroll down a page at a time - towards the end you will see something similar to the following lines:
[ 3.282651] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
[ 3.394810] usb 1-1.2: New USB device found, idVendor=7392, idProduct=7811
[ 3.407489] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3.420530] usb 1-1.2: Product: 802.11n WLAN Adapter
This means that the operating system recognized the USB WiFi Adapter. All that is left is to configure your WiFi connection.
Configuring the WiFi network
On the Raspberry Pi (and on Linux in general) you configure your network settings in the file "/etc/network/interfaces".
Edit the file using the following command:
sudo nano /etc/network/interfaces
To configure you wireless network you want to modify the file such that it looks like the following:
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0 auto
wlan0 iface wlan0 inet dhcp
wpa-ssid "Your Network SSID"
wpa-psk "Your Password"
You will need to put your own SSID and password into the appropriate places.
At this point everything is configured - all we need to do is reload the network interfaces. This can be done by running the following command (warning: if you are connected using a remote connection it will disconnect now):
sudo service networking reload
To check the status of our WiFi connection after reloaded run:
The command should output something similar to this:
wlan0 Link encap:Ethernet HWaddr 80:1f:02:aa:12:58
inet addr:192.168.1.28 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:154 errors:0 dropped:173 overruns:0 frame:0
TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:32399 (31.6 KiB) TX bytes:13036 (12.7 KiB)
If you see a valid IP address under "inet addr" you are good to go!
For more a few more details take at How-To: Add WiFi to the Raspberry Pi over at raspberrypihq.com.