Category Archives: Raspberry Pi

A model train set in a suitcase – a seemingly never ending project

Over the past two years I’ve been working on my largest and most complicated electronics project yet.  My work on the project has ebbed and flowed, but it’s mostly finished.  So I thought I’d start writing up some notes on it.

The initial inspiration was seeing Jeff Faust’s Arduino controlled z-scale train set. I’d been toying with the idea of getting a train set even since my first child was born, but space was very much a premium in the house. So z-scale appealed greatly. It didn’t take much of a leap to then consider putting the train set inside a suitcase, so it’d be easy to store. So after saving up for a little bit, I picked up a Marklin z-scale starter set. I also picked up a turnout, a decoupler and a bit more track, so there was a little bit more interest to the layout.

Seeing what the z-scale layout looks like in suitcase with scenery mostly done

Although, it’s not finished, I wanted to get some of this written up now. If I wait till it’s actually finished it may be a long time. Hopefully I’ll go into more detail on a few bits at a later date as well. From an electronics point of view there are quite a few “modules” that would justify individual blog posts. For now I’m just going to provide an overview of my progress to date.

Continue reading

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!