Home‎ > ‎Dabbles‎ > ‎RaspberryPi‎ > ‎

WiFi My Pi! - Adding WiFi to the RaspberryPi

posted Dec 7, 2014, 7:35 PM by Joshua ‎(Admin)‎   [ updated Dec 14, 2014, 5:55 AM by Joshua S ]
This post demonstrates how to add WiFi functionality to a RaspberryPi.  This will be very helpful when you want to use a Pi in a location not located directly next to the router or with an available LAN cable.

This is the sixth project in the series and assumes the elements performed in several earlier ones are in place and integrated into the template (see the template projects) in order to work.  In this particular example, we are adding WiFi to the RetroPi created in the previous lesson, but the same steps will work on any Pi.

Most of these projects can be performed in any order, but if you follow the order outlined here it will all definitely work.  I've found a number of guides to help me, but many have partial documentation, skip key steps, etc.  The goal is to build out a guide with everything you need to complete each step, but let me know if I miss something or it isn't clear.

For each template and initial setup, I used an 8GB memory card.  With the B+, the image you back up will be the full size of the card whether you expand the file system or not.  For the actual projects, I use a mix of card sizes -- generally 32GB, but I like my templates and initial setup configs to be 8GB to reduce the storage size of my backups.

Note, this project is really all about a configuration and not about a full system build, key component installation, etc.  As a result, the normal steps of creating the SD card at the beginning and saving the image at the end are not necessary.

Supply List:
  • MicroSD Card  A digital memory card, initially designed for media (think a camera) but which will serve as the hard drive for the RaspberryPi.  All tutorials will focus on the 8GB size, but you can easily use this process for a larger format also.  This should be pre-loaded with the template image created in the previous project (template step 01).
  • PuTTY  A free SSH client which is excellent for working at the command line.  I know, I know, no one loves the Command Line any more, but the more you use the RaspberryPi the more you will quickly learn that CommandLine > GUI.
  • RaspberryPi B+  The actual RaspberryPi hardware this will all be built around.
  • WiFi Module  There are a number of USB modules compatible with the RaspberryPi.  In this case, we're using the EDiMAX EW-78811Un.
Project:
  • Before we get started, insert the USB WiFi Module into the Pi and power it on.  Give it a short time to boot and then move onto the next step.
  • Using PuTTY (or whatever SSH client you prefer) connect to the IP address of the RaspberryPi.  You should know this from the previous step (192.168.84.158 in this example), but if you do not, follow the steps at the beginning of the first lesson which show how to use AngryIP scanner to locate the IP address.
  • Once connected, log onto the Pi using:
    • UserID:  pi 
    • Password:  raspberry

  • First things first, let's run the ifconfig command to make sure all of our drivers are set up.  If you see a wlan0 section, then you know the drivers and hardware is functioning but not configured.  If you do not see this section, there is a hardware or driver issue.  If there are issues, try working through the "Problems?" section of this site.
  • Many network related settings can be found in your /etc/network/interfaces configuration.  Navigate to this file and open it to edit with Nano. 

  • Note -- your wired connection is configured in the first "eth0" section.  The Add (or update) the wlan0 (wireless) section with the following lines.  Note -- this assumes you are running WPA2 (I haven't tried it with any others).  
    • allow-hotplug wlan0 (remove)
    • auto wlan0 (add)
    • iface wlan0 inet dhcp
    • wpa-ssid "<WiFi Name>"
    • wpa-psk "<Password>"
  • Now that the config is complete, we need to cycle the wireless network in order to connect.  Use the following commands:
    • sudo iwconfig (shows the network is still not set up)
    • sudo ifup wlan0 (gets the wifi card ready to configure)
    • sudo ifdown wlan0 (takes down the wifi card)
    • sudo ifup wlan0 (brings up the wifi card and begins the process to connect)
    • sudo iwconfig (shows the network is set up and has an IP address assigned)
    • sudo ifconfig (shows the network has an IP address assigned)

  • Congratulations!  You have now WiFi'd your Pi!

Comments