Tips and tricks

The Raspberry Pi is just about the most Linux fun that someone can have for $35.

If you just purchased your Raspberry Pi (RPi), congratulations! Here are some tips and tricks which will help you to get the most out of the RPi and to make life easy.

Accessories

I started out with just the essentials: a Raspberry Pi model B and a Modcomp case. I cobbled the rest of the system from parts around the house including:

  • An Energizer USB charger and cable,
  • A Logitech EX100 wireless keyboard and mouse,
  • An HP monitor,
  • A CAT5 networking cable, and
  • A pair of SD cards.

Thus, I only needed to spend $42 (USD) on Raspberry Pi-specific hardware. Not bad!

The wireless keyboard and mouse communicate through a receiver which plugs into the RPi. The receiver takes only one USB port, leaving the other USB port available for a USB flash drive or whatever.

Power

Raspberry Pi needs a 5 Volt power supply. The power input is a USB micro-B port. I bought the Energizer USB charger and cable on clearance at Target for about $6 (USD). I get some of my best and cheapest hardware that way — on clearance. You just need to keep your eyes open for a bargain!

I would recommend an adapter/charger which can provide at least 1A of current. Be sure to check the adapter’s rating. Computer USB ports are often limited to 1A of current or less, and probably are not the most reliable way to power your RPi.

Some USB flash drives (AKA “jump drives”) draw a fair amount of current and can cause your RPi to crash. For example, my PNY flash drive works just fine, but my Kingston Data Traveler causes the RPi to crash every time. There are two solutions:

  • Use only low power USB flash drives.
  • Use a powered USB hub.

A powered USB hub shifts the load to the hub’s adapter and also provides a few more ports.

SD cards

A lot has been written about SD card compatibility and the Raspberry Pi. Definitely check out one of the lists of compatible SD cards.

Maybe I was lucky, but I found two class 10 SD cards on clearance at Walmart (“clearance,” that word, again) that work with the RPi:

  • Sandisk Ultra SDHC Card SDSDRH-008G-AW11
  • Sandisk “elevate” Ultra SDHC Card SDSDU-008G-T11NK

Both cards are 8GB and neither card appears on any of the lists of compatible cards. They seem to be working fine with RPi and Raspbian Wheezy.

Why class 10? Flash memory reads are pretty darned quick, but write speed can be slow. SD cards are classified by speed with class 4 being relatively slow and class 10 being relatively fast. Even if RPi can’t use all of the speed right now, a class 10 card has better long-term potential and usability.

Operating system

I chose Raspbian Wheezy for the operating system. It has a strong user community and the start-up tutorials are excellent. In fact, I recommend writing your own SD cards. Just follow the “Raspberry Pi Quick Start.” Although you will need to download the operating system (OS), you will be able to quickly clear and overwrite the SD card with the OS in case something goes terribly wrong. Don’t worry because a large part of the fun is having complete control over your own Linux system!

Configuration

Raspbian Wheezy provides a program, raspi-config, which configures certain important aspects of operating system behavior.

  • expand_rootfs: Lets the OS access all of the space on the SD card.
  • change_timezone: Sets your time zone.
  • change_locale: Determines how dates, time, money and other location-specific entities are displayed.
  • configure_keyboard: Sets the keyboard layout.

raspi-config uses a text-oriented, quasi-GUI to select menu items and options. Use the arrow keys to navigate around. The space bar selects items and the enter key confirms choices.

As mentioned in the tutorials, the Raspbian Wheezy image (as downloaded) only uses the first 2GB of space on the SD card. The expand_rootfs menu item reconfigures the operating system to use all of the space available on the SD card. A restart is required to make the reconfigure take effect.

The change_timezone menu item is self-explanatory. The change_locale menu item adjusts the way money, dates and time are displayed. When downloaded, Raspbian Wheezy is configured for the United Kingdom. You should change the locale to your own location or conventions. Since I’m in the USA, I have chosen the locale “en_US.UTF-8 UTF-8“.

You might not think to configure the keyboard at first. I sure didn’t. However, when I went to pipe data between Linux commands, the vertical bar key did not produce a vertical bar (“|”). The keyboard layout in the Raspbian Wheezy image is configured for the United Kingdom. I first selected the Logitech Cordless Desktop EX110, which is the keyboard that would most closely match my hardware set-up. Next, I chose “English (US)” as the keyboard layout. Finally, I rebooted. During the restart, the OS generates a new keymap. This step requires a modest amount of time, but is performed only once. It will not be performed during subsequent boot-ups.

sudo

During configuration and set-up, you need to perform several tasks with administrator privileges. On Linux, the administrator is called the “super user”. Back in the old days, you could log in as the superuser and merrily enter commands. However, security has since been tightened and the sudo command is standard practice.

sudo runs any other Linux command (which is given on the same command line) with administrator privileges. So, for example, you need to enter:

sudo raspi-config

to run raspi-config from the command line. You also need to use sudo to install new software, create a new user, and so forth. sudo prompts you for your password. The privilege (credential) is cached for a period of time (default: 15 minutes). So, if you run sudo during that 15 minute period, you will not be prompted for your password again. This is very handy because you often need to enter several administrator-level commands to accomplish a task, then go back to being a regular user.

Add a new user

Raspbian Wheezy downloads with one user named “pi” with the default password “raspberry”. You can change the password from the command line using the passwd command.

You may also create new users from the command line. The following commands create a new user named xyz:


sudo useradd xyz -m
sudo passwd xyz
sudo usermod -aG sudo xyz

The second command changes the password for the user and the third command makes the user an su-doer (somebody who can perform magic with sudo.)

apt-get

Linux distributes code and applications in the form of “packages”. apt-get is the command for installing and removing packages. While you are first setting up Raspbian Wheezy, you should enter the commands:


sudo apt-get update
sudo apt-get upgrade

to bring your distribution up to date. Then, you’re all set to start installing new applications and other packages. For example, I can’t live without the EMACS editor. The following command installs EMACS:


sudo apt-get install emacs

nano is a good, lightweight text editor in case you need to quickly modify a file or two.

There is also a GUI-level application, synaptic, for package management. I recommend installing synaptic:


sudo apt-get install synaptic

Synaptic lets you browse available packages, select the packages that you want to install, and then installs them. Synaptic also shows you which packages are already installed. Its a good tool for system management.

The desktop

When you first started Raspbian Wheezy, you got the good old Linux login prompt and command line interface. You were probably wondering, “Where’s the desktop GUI?” The desktop is run under the X windows system. Start the desktop by entering the startx command. The desktop appears and you are off to the races!

How do I turn Raspberry Pi off?

All operating systems want to be turned off in an orderly way. An operating system often keeps information cached in primary memory — information that needs to be flushed to permanent storage before the lights go out.

I like to use the shutdown command to halt or reboot Linux. If you are in the desktop, first log out by choosing the logout item in the main desktop menu. The desktop will terminate and return you to the command line interface. Then, enter the shutdown command through sudo:

sudo shutdown -h now

The -h option tells Linux to halt the processor after shutting down. The now argument tells Linux to shut down immediately. If multiple users are logged, they will be informed of the impending shutdown. You can tell Linux to reboot by using the -r option instead of the -h option.

After the processor halts, pull the adapter plug or flip the switch on the power strip. I don’t recommend unplugging the USB micro-B plug from the RPi because PC board connectors are not very rugged.

How do you reset a Raspberry Pi? I strongly recommend using the shutdown sequence. If the machine is totally hung, then you will need to unplug, wait a second or two and then plug the adapter back in. This is known as a (very) “hard reset”.

Copyright © 2013 Paul J. Drongowski