Getting started with a Raspberry Pi

Raspberry Pis are awesome little machines. Even with the Aussie Tax™ increasing the price, for about $50 you get a surprisingly capable computer in a tiny form factor.

There are a few gotchas getting up and running, though – particularly if you haven’t used Linux before. For example I didn’t know the right terminology for packages and using apt-get, which made searching for help a bit annoying at first.

This post is basically a list of things I’d have liked to know when I bought my first Pi, just to get up and running faster. Hopefully these tips will save someone some time…

First, choose your Pi

Currently there are three models to choose from: A, B and B+. There’s a comparison chart, but the short version is: if in doubt, get the B+.

While most of the B+ specs are the same as the B, the form factor’s neater; the B+ has more GPIO pins and USB ports; and it resolves some niggles around power. If you can’t get hold of a B+ you’ll probably still be fine with a B, but you might as well get the newer version if you can.

So what about the Model A? It’s the cheapest option but has lower specs – half the RAM, no ethernet and just one USB port. It’s not really a ‘budget Pi’, it’s for projects where power consumption and weight are key considerations. So unless you’re looking for a Pi to attach to your quadcopter, you probably don’t need an A.

In the end I paid a few extra dollars for the red Pi manufactured by Egoman. After all, shouldn't all Pis be red?

Red Raspberry Pi by Egoman

Basic supporting hardware

The full list of hardware depends a little on how you plan to use your Pi, but the basics you need:

  • Decent 4gig+ SD card (for Model A or B) or micro SD card (for Model B+).
    • 4-8gigs is plenty for the OS, just avoid the very cheapest SD cards with lower write speeds.
    • If you’re loading the OS yourself, don’t forget a reader for your SD card.
    • If you don’t want to load the OS yourself, you can buy Pi kits with a preloaded OS (it’s not hard to do though!).
  • Cables for power and display:
    • HDMI cable
    • A power supply. You can power the Pi with a dedicated 5v power supply, but any powered USB port or a good-quality charger will do. I’ve used USB ports on my router, laptop, desktop and TV; and chargers for my phone and kindle.
    • Avoid really cheap chargers or USB ports on cheap power boards, as they tend to fluctuate below their supposed specifications and the Pi will brown out and reboot.
  • There’s no on-board wifi, so you need an ethernet cable or a wifi dongle like the Wi-Pi.
  • USB keyboard and mouse (see considerations below)
  • A case/enclosure for the Pi is optional but worth considering… of course you can just put one together with Lego ;)

If you’re geeky buying a Pi, you probably have a lot of that stuff already.

Hardware considerations

  • The Model B only has two USB ports, so you run out before you can connect a keyboard, mouse and wifi dongle. It also won’t power high-draw devices like hard drives. Solutions include:
    • Get a keyboard with integrated mouse. I use the Logitech K400r, which was plug and play with Occidentalis. The K400r’s dongle coexists quite happily with a WiPi dongle.
    • Use a powered USB hub to add more ports and provide more power (avoiding brownouts).
  • Be careful about using power off a PC, TV etc – if it’s something that’s going to be turned on and off a lot, you will need to remember to shut down the Pi first. Otherwise you’re doing the equivalent of shutting down your computer by yanking the power cable out of the wall.
  • If you’re going to be shuffling a lot of data on or off the Pi, do yourself a favour and use ethernet.
  • The Pi only outputs HDMI and RCA composite video, which means some old monitors might need an adaptor.

Choosing an OS

Raspberrypi.org has a list of common OS options along with installation guides.

  • Raspbian/NOOBS is the ubiquitous and recommended choice. NOOBS stands for New Out Of Box Software and aims to make the setup process as easy as possible. Note NOOBS is an installer/config manager and Raspbian is the actual OS. Raspbian is Debian Linux optimised for the Pi.
  • If you plan to use the Pi to work with electronics, you may want to look into Occidentalis. Created by Adafruit, it packages up some extra libraries etc for working with electronics.
  • If you plan to use the Pi as a media centre, look into RASPBMC, which is the popular XBMC ported to Pi.

It is worth noting the Pi-friendly Linux distributions are bare bones, optimised for the low-power hardware. This makes them feel a bit less polished than common desktop distros like Ubuntu, so don’t judge the current state of desktop Linux based on the Pi!

Initial setup

The precise details vary between the distributions, but you should ensure you:

  • set a new password (recommended). You can do this any time with passwd at the command line. You can generally ignore the complex password requirement prompt, but do treat the Pi like any other ‘real’ computer or device and protect it accordingly.
  • choose whether the Pi should boot to the command line or the GUI by default
  • decide if you want to enable SSH

If you were prompted for these things during setup, no worries… but if not, try running sudo raspi-config from the command line. This should open a configuration menu.

Your wifi dongle should have its own instructions, but I found many don’t include the commands for listing USB and network devices:

  • lsusb – lists attached USB devices
  • iwconfig – lists network devices. Be careful as each network device gets its own persistent name/reference, so if you plug in two different dongles the second will not be accessible at wlan0. Not a big deal, except every tutorial seems to assume you’re doing a fresh setup and says your wifi dongle will be wlan0 rather than getting you to actually check. This caused a serious headache for me as I’d used a borrowed WiPi then bought my own, thinking I could just swap them out.

Don’t be afraid of the command line

It’s almost guaranteed you’ll need to use the command line interface as well as the GUI, even if only to do the initial setup. So, it’s handy to know a few CLI basics:

  • If the Pi doesn’t boot into a GUI, the command startx will usually start the GUI.
  • Once you’ve started the GUI, you might need to run CLI commands – you don’t need to shut down the GUI, just start up a command or console window within the GUI.
  • You manage software/packages using apt-get. This tip is so basic people regularly forget to mention it.
    • apt-get update – update the list of available packages (you need to run this first)
    • apt-cache search thing – search the list of available packages for ‘thing’, eg. “synaptic”
    • apt-get install thing – install ‘thing’
    • Note you’ll probably need to run apt-get commands with sudo, eg. sudo apt-get install thing. This gives the command elevated system privileges required for updates.
  • Many distributions provide a GUI wrapper for apt-get; but if yours does not, you can use apt-get to install one (eg. Synaptic).
  • Not all distros will remind you to update the OS and packages. To upgrade everything, automatically saying ‘yes’ to any prompts, with dependencies managed for you (note this will probably take a while so don’t do it if you’re in a hurry):
    • sudo apt-get update && sudo apt-get -y dist-upgrade

Command Line text editors

  • Help! I’m stuck in some kind of text screen and can’t get out! ... You’re probably in Vi or Vim. Try: q, q [enter], :q [enter], esc :q [enter], ctrl+c [enter] or ctrl+d [enter] … one of them should get you out. Consider this one an ‘achievement unlocked’ moment of learning the command line. Everyone gets stuck in vim when they’re new to the CLI!
  • Even if you didn’t have the “help I’m stuck” moment, you may encounter Vi or Vim pretty early on in your experience. Vi(m)‘s a ubiquitous CLI text editor and many tutorials will tell you to use it to edit configuration files and so forth. It’s worth looking up an intro tutorial. If in doubt between the two, use vim.
  • You may be able to use nano instead, it’s less powerful but relatively user-friendly. Run “nano —version” to see if it’s available. If it’s not you should be able to install it with apt-get.
  • You can override the default editor, eg. to load nano by default instead of vi.
  • Never ask anyone the difference between vim and emacs, nor which one is better.

General tips

  • You can’t hot-swap USB devices on the Pi A/B. Plug things in before you power up the Pi. Otherwise it will reboot as soon as you try to plug/unplug something.
  • There’s no on/off button, it’s either plugged into power or it’s not…
    • For a clean shutdown, run sudo shutdown -h now before you pull the plug.
    • To reboot, sudo reboot
  • You may need to plug the Pi in to HDMI before booting it, sometimes it won’t recognise HDMI later on.
  • Sharing files over your network isn’t too hard, eg. you can use Samba (you may need to install the samba package on the Pi first). Set up a shared location on your mac or pc then connect from the Pi back to the host machine, logging in with the user accounts set up on the host machine (usually your own login). Use the Pi’s File Manager and Go menu; or you can try going straight to smb://computername/
  • If you’re installing things like Nodejs, remember to get distributions for ARM processors (or ideally distros specifically for the Pi). Avoid compiling from source on the Pi if you possibly can, as it tends to be slow as in all-night-to-compile-nodejs slow.

Some useful links

Last thoughts

Hopefully these tips will help get you up and running; but remember that any problem you have with a Pi has probably happened before. Google for help, you will almost certainly find it.

The next challenge is deciding what to do with your Pi… have fun!

about

Web development and standards, as seen by Ben Buchanan.