Notes on the Raspberry Pi

You know if someone hadn't given this to me for a project, I wouldn't have looked at it. Dreadful name! But it turns out to have some real merits for geeks. Also with an HDMI to DVI/VGA adapter it makes a superb thin client.

The board was intended as a small controller in a real-time data acquisition project, managing a network of XBees (it was never actually chosen in the end). There are a number of linux distributions now available for it, the main one being a Debian distro providing X and a desktop environment. Due to the use of SD cards for the permanent storage, there are few limits in the size of the installed OS, but the RAM is only about 500MB and the board overall is a lot slower than a full PC.

For this project a desktop is overkill. The work needing doing by the board is potentially heavy, so later we will look at other light-weight distros.

Setup

Firstly download and write the Linux distro onto an SD card. SDs are now very low cost thanks to volume marketing, and I picked up a 4GB class 6 for only $7. An 8GB class 10 was only $18. Pull down the Debian Wheezy Raspbian (Debian for Raspberry Pi) distro that has been cross-compiled: 2012-10-28-wheezy-raspbian.zip. Instructions for installation and setup can be found in a number of places. One good set is http://elinux.org/RPi_Easy_SD_Card_Setup. Under Linux:

$ wget http://mirror.aarnet.edu.au/pub/raspberrypi/images/raspbian/2012-10-28-wheezy-raspbian/2012-10-28-wheezy-raspbian.zip
$ unzip
2012-10-28-wheezy-raspbian.zip
$ dd if=
2012-10-28-wheezy-raspbian.img of=/dev/sdb

where /dev/sdb is the place where the card was mounted (be careful that it is the correct one to avoid wiping one of your disks).

Headless Access

Next plug into an ethernet LAN, go into the LAN router, or wherever the DHCP server is,  and work out what the IP address was given to it. The ssh server should already be active, so find the IP address of the machine from the local router or wherever it is issued, and connect in:

$ ssh pi@192.168.2.18

with default password raspberry (what else!). I changed the root password (using sudo passwd) to ensure I could do extensive administrator work later.

I couldn't find X2GO so I installed the xrdp server:

$ apt-get install xrdp

Then from outside invoke a remote desktop client:

$ rdesktop -g 1240x960 -u pi 192.168.2.18

and so you have your remote desktop without needing a monitor.

WiFi

This is more challenging. Most people will need to purchase a dongle so be careful to select one that is known to work on the Raspberry Pi. Don't rely on the fact that Debian Wheezy supports it.

The one I picked in a hurry was a D-Link DWA-125 which includes an Ralink RT5370 chip. This didn't appear to be supported by this particular distro as shown by:

$ aptitude show firmware-ralink

however some forum posts and blogs seem to indicate that it is supported. Nevertheless I compiled and installed the source package from Ralink as described below.

Load DWA-125 Drivers

Once installed, check the ID numbers for the particular dongle:

$ lsusb | grep -i ralink
Bus 001 Device 004: ID 2001:3c19 D-Link Corp. DWA-125 Wireless N 150 Adapter(rev.A3) [Ralink RT5370]

Then setup the dongle to be recognised using these numbers:

$ sudo modprobe rt2800usb
$ lsmod | grep -i rt2
rt2800usb              13009  0
rt2800lib                47242  1 rt2800usb
rt2x00usb              11075  1 rt2800usb
rt2x00lib                41057  3 rt2x00usb,rt2800lib,rt2800usb

The lsmod shows the module has been loaded. The following command puts these into the driver directory (the tee command is needed to overcome permission problems, acknowledgements to poster argief in RT5370 (D-link DWA-125) WiFi):

$ echo 2001 3c19 | sudo tee /sys/bus/usb/drivers/rt2800usb/new_id

Then iwconfig should show an entry for wlan0 although it will not be associated at this time.

In /etc/udev/rules.d add a file 80-dlink-wifi for udev rules to mount the dongle when inserted (see http://www.reactivated.net/writing_udev_rules.html). Use the Vendor and Product IDs determined above to identify the dongle (an entry ACTION=="add" could also be added to cause it to activate only when the dongle is inserted):

ATTRS{idVendor}=="2001", ATTRS{idProduct}=="3c19", SUBSYSTEMS=="usb", RUN+="/bin/mount-dlink-wifi"

and create /bin/mount-dlink-wifi (set to executable with chmod +x /bin/mount-dlink-wifi) with:

modprobe rt2800usb
echo 2001 3c19 | tee /sys/bus/usb/drivers/rt2800usb/new_id

This didn't seem to fire when powering up if the dongle was already inserted, so I also added a call to /bin/mount-dlink-wifi in /etc/rc.local to cause it to run at startup.

Wicd

The simplest and most reliable way to proceed is to install Wicd. This provides a GUI which detects the networks available and allows for automatic connection once the SSID and Key have been entered.

Setup Networking

If Wicd doesn't work, networking can be setup directly, although this removes the flexibility that a GUI provides. None of the following worked for me before I discovered Wicd, so I can't guarantee anything. These are a distillation of the different forum posts, all of which gave different suggestions. Success seemed to depend on what particular dongle was used.

In /etc/network/interfaces, the interface for wlan0 can be specified to connect and get the DHCP address:

auto wlan0
iface wlan0 inet dhcp
wpa-ssid <whatever>
wpa-psk <WPA Key>

However this is insecure, so as an alternative use wpa-supplicant. In /etc/wpa_supplicant/wpa_supplicant.conf put:

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
network={
  ssid="whatever"
  psk="
WPA Key"
  proto=WPA
  key_mgmt=WPA-PSK
  pairwise=TKIP
  group=TKIP
}

The settings here varied according to the dongle and chip, depending on what protocols and algorithms were available.

Add to /etc/network/interfaces (or leave the default settings):

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

The following posts by Shig and Bilbao respectively were followed to install the firmware. This did seem to work OK for me. First install the Linux headers, then compile the new firmware.

Linux Header for 3.2.27

RT5370 (D-link DWA-125) WiFi

The essence is repeated here for posterity. First install the Linux source:

# cd /usr/src
# wget https://github.com/raspberrypi/linux/tarball/rpi-3.2.27
# tar xzf rpi-3.2.27
# cd raspberrypi-linux-*
# zcat /proc/config.gz > .config
# make oldconfig
# make modules_prepare
# wget https://github.com/raspberrypi/firmware/raw/master/extra/Module.symvers
# KSRC=`pwd`
# pushd /lib/modules/`uname -r`
# ln -s ${KSRC} source
# ln -s ${KSRC} build
# popd
# pushd /usr/src
# ln -s ${KSRC} linux-`uname -r`
# ln -s ${KSRC} linux
# popd

Then compile the firmware. Look for the package on the Ralink site under downloads-Linux 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2. There are copies around other places but I preferred not to trust them.

# tar xjvf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO.bz2
# cd 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DPO/

Go to /opt/linux/ and edit config.mk to change the following lines:

# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=n

# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n

to enable them. Then

sudo make; make install

Use of RAM

General opinion is that the SD card flash memory has an endurance of over a million writes and with balancing this should last many years of normal use. Nevertheless to save a bit on wear and also to speed things up, parts of the filesystem can be placed into RAM. From this site the instructions needed to move logs and tmp directories into RAM were given. A /data directory was created with open permissions to allow user programs access to ramdisk storage also. The following lines placed in /etc/fstab do all this

tmpfs           /tmp            tmpfs   defaults,noatime,mode=1777 0 0
tmpfs           /var/log        tmpfs   defaults,noatime,mode=1777 0 0
tmpfs           /var/tmp        tmpfs   defaults,noatime,mode=1777 0 0
tmpfs           /data           tmpfs   defaults,noatime,mode=1777 0 0

Then stop the syslog service, clear out the old log and tmp directories by deleting their contents, and restart.

Alternate Distro

A number of distros are currently available but I haven't tried any. The Berry terminal is oriented to thin client applications and is quite small.
First created 18 December 2012
Last Modified 25 April 2013
Ken Sarkies 2012