Configuring an Edimax EW-7811UN on a Raspberry Pi for WiFi

I was given a Raspberry Pi last year. I quickly got hold of an SD card, keyboard, mouse and a ten metre ethernet cable (to connect it to the router on the other side of the room). I installed the version of Raspbian released in July and set to work updating and installing software using apt-get. However whilst the Raspberry Pi seemed to be working fine, it appeared the the ten metre ethernet cable and/or my wireless router’s ethernet port weren’t so happy. Running sudo apt-get update took a long time. Running sudo apt-get upgrade to get to the latest version of the Raspbian kept timing out. Downloads speeds started fairly modestly (30-40Kb/s, quickly dropped to less than 1Kb/s and then gave out all together.

This was obviously somewhat frustrating. A big part of the appeal of the Raspberry Pi is that it connects to the internet. An ethernet should connection should work easily, but it appears that my router didn’t agree with that. Given that everything else in the house connects over WiFi it seemed like that was the route to take. It also meant I could lose the monster ethernet cable draped around the house.

So when I had a bit of free time again I got hold of an Edimax EW-7811UN Wireless Nano USB Adaptor and set about getting it working. It’s a really tiny little adapter, just barely larger the the USB plug itself. Which means that the Raspberry Pi can keep it’s diminutive form factor.

Of course though to get the adapter working I needed to upgrade to the latest version of Raspbian (which includes the WiFi drivers) – which in turn required a connection to the internet.

So to get a temporary network connection I connected the ethernet port on the Raspberry Pi to the ethernet port of of MacBook and turned on internet sharing to share the WiFi connection. This was great and I wish I’d thought of it sooner as it gave me a full speed connection (500Kb/s at least). Of course at this point I made sure the WiFi adapter was not plugged in.

So first job was upgrading everything using apt-get:

    sudo apt-get update
    sudo apt-get upgrade

That probably took about 20-30 minutes and included the drivers for the Edimax WiFi adapter.

I then rebooted the Raspberry Pi and plugged in the WiFi adapter. To see if the drivers were working I ran:

    sudo iwlist wlan0 scanning

Which listed all of the WiFi access points that could be seen by the adapter – which indicated that the adapter was working properly. The blue LED on the adapter also started flashing at this point.

The next job was to configure the adapter to connect using my WiFi network. I edited /etc/network/interfaces:

    sudo nano /etc/network/interfaces

And added the following to the end of the file (be careful here as you don’t want to mess up your network settings):

    auto wlan0
    iface wlan0 inet dhcp
    wpa-conf /etc/wpa.conf

That configures the wlan0 network interface to run and to use DHCP to automatically get a network address.

Next I had to add in the key and access point name (SSID) for the network:

    echo $(wpa_passphrase <ssid> <network password>) | sudo tee /etc/wpa.conf

The wpa_passphrase command is a handy way of generating the hexadecimal key that the configuration file wants (rather than the human readable password). I used sudo tee /etc/wpa.conf as simply redirecting the output directly to /etc/wpa.conf would not have enough permission otherwise.

This writes the settings on one line like this:

    network={ ssid="<ssid>" #psk="<network password>" psk=<long hex string> }

Which needs editing to break into more than one line (otherwise the # character will mess things up):

    sudo nano /etc/wpa.conf

The edited wpa.conf file ended up looking like:

    network={
    ssid="<ssid>"
    #psk="<network password>"
    psk=<long hex string>
    }

At this point that was all of the configuration done and it was time to fire up the wlan0 network interface (aka the WiFi adapter):

    sudo ifup wlan0

This thought about things for a bit (whilst it got a network address via DHCP) and then blue LED on the adapter lit up fully and I had a working WiFi connection!

2 thoughts on “Configuring an Edimax EW-7811UN on a Raspberry Pi for WiFi

  1. I’ve been trying forever to get my edimax adapter to work. I have been using the latest NOOB with raspian os installed. I went through your method (amongst dozens of others). When the steps are completed it always fails to authenticate.

    I do have a “?” in my password and my SSID contains a “_” but i don’t think that should matter. Any advice? I’ve tried connecting directly to the pi and using a USB hub.

    error message:
    DHCPDISCOVER on wlan0 to 255.255.255.255 port ## interval ##
    (repeat)…
    (repeat)…
    (repeat)…

    NO DHCPOFFERS received.
    No working leases in persistent database- sleeping.

  2. Hi Miles,

    hard to say what’s going on really – I had similar frustrating experiences trying to get things working on my Raspberry Pi. I had to do a certain amount of turning things on and off again and in fact never managed to get a stable wired/ethernet connection from my router.

    Based on what you’ve said you’re seeing it would imply that maybe your router isn’t sending out/responding DHCP requests?

    Did you get the blue light on the adapter?

    If they blue light is on and you’re seeing it talk about DHCP that probably means the wireless link is ok (and the password is ok). The error then is at the networking level.

    Hard to know for sure though…

    cheers,

    John

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>