So you think you love Pi?

Raspberry Pi

Raspberry Pi component architecture

A gentle getting-started guide to the Raspberry Pi

The Raspberry-Pi is a low cost, credit card sized, single board computer, initially marketed as an introductory level computer science gadget for schools, but increasingly being adopted by hobbyist worldwide for various purposes. This high adoption is attributed to its simplicity, cost effectiveness, and almost non-existent knowledge barrier to entry. You can find out all about the Raspberry Pi here.

Adopters of the pi have executed projects ranging from the obvious - building an all-in-one computer, to imaginative - home automation or making black and white mural arts from photos, to remarkable - building a super-computer with 64 serially attached Raspberry-Pis. A recurring theme among hobbyists is the usage of the Pi to make something in their everyday routine easier or much more fun, afterall “the supreme accomplishment is to blur the lines between work and play” - Arnold J Toynee. Therefore as a programmer, who spends far too much time thinking, typing and moving/editing files around and, for a lack of time at the moment to program my own mind into a Raspberry-Pi, I thought I'd write a gentle introduction for those just getting on the Pi bandwagon and detail the hurdles I faced trying to get things to work.

The “issue” which took up quite a bit of my time was setting up the wifi so that's what I'll be discussing in this post. Subsequent posts will cover setting up a web server and source code repository configuration, migration and management.

I'm assuming you already have a Pi so lets get started. Initial startup is farly basic and straight forward. A detailed step-by-step guide is provided here

Note, some of the commands stated below are specific to debian-based flavours of Linux, so if you happen to have an RPM-based distribution installed on your SD card, the commands might vary slightly but the general idea is the same. Find information on operating systems for your Raspberry Pi here.

Also, I'm assuming you're running all the commands as the root user. The root user is disabled by default on the Pi and if you choose to keep it that way simply prepend each command with sudo, otherwise to activate your root account, enter

pi@raspberrypi ~ $ sudo passwd root

Type a root password twice, and you're done. Now switch users using

pi@raspberrypi ~ $ su root

And provide the root password. At this point, your prompt should have changed from 

pi@raspberrypi ~ $

to

root@raspberrypi:/home/pi#

And on a final note (more like a warning) as the root user, keep in mind that “with great power, come's great responsibility” - Uncle Ben Parker. You've been warned.

Lets proceed.

Requirements

You'll need a Raspberry-Pi (obviously), a keyboard, a usb wifi dongle, and optionally a mouse. A cabled connection will be required to retrieve drivers for your usb wifi dongle.

Attach your wifi dongle, and then connect the power cord to boot the system. The Pi is powered through a micro-usb cable, so basically, your phone charger will do for power.

After booting into the Pi, you're provided with a prompt. This is not to say you can't have a Graphical User Interface (GUI) on the pi, its just that the window manager (the package responsible for managing GUI interactions) is quite resource hungry and as such isn't the default boot mode (i.e. runlevel). You could easily switch to the gui by typing the following at the command prompt.

root@raspberrypi:/home/pi# startx

or

root@raspberrypi:/home/pi# telinit 5

You can return to the prompt with CTRL + ALT + F1 (through to F6). F7 will take you back to the GUI.

On acquiring a Pi, the first, absolutely essential, thing to do is to set up internet connectivity. Expectedly you should have gotten a wifi dongle with your Pi, but if said dongle happens not to work, then the first step would be to get drivers.

The default operating system provided for the Pi is a stripped down version of debian “Wheezy” linux distribution, and as such, you'll be required to install most of the packages you'll need, hence the requirement to set up internet connectivity.

The Grind

Now perform the following operations:

1. Figure out the type of device being used. This will provide you with information on what driver to install.

root@raspberrypi:/home/pi# lsusb

This will return a list of devices connected to usb hubs. Note the entry that describes your connected device. In my case:

...

Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter.

...

2. Connect your wired cable to the ethernet port and update the package manager before we proceed.

If you don't get allocated an IP address by your router, then the cable you're using is probably wrong. Do an ifconfig and see if the entry eth0 has any IP information associated with it. If you do get allocated an IP address but can't ping www.google.com, try a reboot.

If you still don't get a connection, its definitely the router (probably connected to a wrong ASDL socket) or something trivial like that. Resolve that by confirming you can get internet connectivity on other machines, and then connect the ethernet cable for a package manager update.

root@raspberrypi:/home/pi# apt-get update

3. Search for your wifi dongle's firmwire drivers. The package name can be modified until your search returns a useful result. In my case, I searched realtek, other people have reported searching RTL818.

root@raspberrypi:/home/pi# apt-cache search realtek

Feel free to modify your search query to suit your device id. Once a match is found, proceed with installation. Your result might look something similar to this:

Firmware-realtek - Binary firmware for Realtek wired and wireless network adapters

Install the driver.

root@raspberrypi:/home/pi# apt-get install firmware-realtek

4. You can confirm a successful install if you wish.

root@raspberrypi:/home/pi# lsmod

This shows your device id in the response device list.

Module   Size Used by...rtl8187 44897 0

...

or

Module   Size Used by...8192cu 485042 0...

depending on the driver installed for your device.

And to be extra sure the module is loaded, you may wish to load the module manually.

root@raspberrypi:/home/pi# modprobe 8192cu

5. Now a config file needs to be created for the wireless adapter. Lets first create the file:

root@raspberrypi:/home/pi# nano /etc/wpa.config

Look under your router (or ask a sys admin) for your wireless SSID (Service Set Identifier) - this is the public name of your wireless network. The SSID and password would be required in the config file entry.

Update the config file with the following: (Remember to retain the quotes on your SSID and password)

network = {
    ssid ="YOUR_SSID"
    proto= RSN
 key_mgmt= WPA-PSK
 pairwise= CCMP TKIP
    group= CCMP TKIP
    psk  ="WPA_PASSWORD"
}

CTRL + O to save, and CTRL + X to exit.

Now lets add a reference to the newly created file, in the network interface descriptor.

Open the interface file for editing:

root@raspberrypi:/home/pi# nano /etc/network/interfaces

Update the file with the following entries and save the file. Note, this should be inserted at the end of the file to override pre-defined settings.

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

In some cases, the first line which reads auto wlan0 may have to be modified to read allow-hotplug wlan0 to ensure you have a wifi-connection at boot-up.

Detach the network cable from the RJ45 ethernet port and restart the network.

root@raspberry~# /etc/init.d/networking restart

If you still don't have an internet connection, considering you've installed drivers for your wifi dongle, you can switch to the GUI and start up the wpa_gui application

i.e. Start Menu > Internet > wpa_gui.

If you're using a mouse, you will have to keep swapping your mouse and keyboard to use thesame USB port.

Scan for connections and select your SSID from the list.

Enter your router password in the PSK field and click Add. This should now take care of internet connectivity.

Save the modified settings.

i.e. File > Save Configuration.

Thats it! We're done! Easy right? ... okay almost done. Optionally, you may want to provide a static IP address for your ethernet port so other machines in your cabled network can find it.

To do that, modify your interface description file with the following (Assuming your Pi will have an IP address of 192.168.10.1 in a class C network with address 192.168.10.0):

iface eth0 inet static
address 192.168.10.1
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255

The full /etc/network/interfaces file should now read as follows:

auto lo

iface lo inet loopback

iface eth0 inet static
address 192.168.10.1
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

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

So now you're set and ready to go!

I use the console for almost everything on the Pi (and I'll recommend you do the same too since x-windows is bound to snag up precious resources), so I went ahead to install a text browser as well. My choice after much speculation was w3m.

Now that we've got our internet working - providing online access to various package repositories, we can avoid the compile/make/make install cycle or hunting down dependencies to do a decent package install. Installation of any package simply involves these three magic words:

apt-get install [insert package name]

Okay maybe not that magical. Moving on.

Install w3m:

root@raspberry~# apt-get install w3m

... and for the bravehearts, install google chrome (though I guarantee you'll uninstall it once you start it up in the GUI)

root@raspberry~# apt-get install google-chrome

Handy commands to remember are:

To switch to the GUI -

startx

or

telinit 5

To configure system settings -

raspi-config

... and to shut down cleanly (i.e. kill the power) -

shutdown -hP 0
In conclusion

The Raspberry Pi is an entry level machine (to be honest its got more components than the computer I started programming on, and is like 100 times smaller) primarily marketed as a useful introduction to basic computer science for students, but is been taken up by hobbyists for various interesting projects.

I talked about the absolutely essential operation after the initial startup - setting up internet connectivity, since the package manager depends on it for dependency resolution during package installation among other obvious reasons.

In the next related post, I'll be talking about setting up or migrating a repository, installing the Apache webserver, and configuring a repository browser to provide remote access to your repo on the Pi.

References

Tags : hardware linux raspberry-pi wifi

Comments


    Leave a comment


html comments are not allowed

Submit