You are on page 1of 36

Raspberry Pi

User Guide

Getting
started
Operating Systems
& Installation

Learn
the ropes
Linux &
Packages

Making the
most of your Pi
Pi Projects

element14.com

Raspberry Pi User Guide.indd 1 08/07/2014 14:43


CONTENTS

Unpack the box 3

Operating Systems 4

Installation 6

Loading the O/S 7

Raspbian 8

Command line: Learn the ropes 10

Packages: How do they work? 16

RaspBMC 20

Camera controller 22

Sending output 26

Minecraft Pi 30

Postscript 32

Raspberry Pi User Guide.indd 2 08/07/2014 14:43


Unpack the box
Inside the box you will find the Raspberry Pi board,
a 5V Power Supply (optional) and a 8GB microSD card.
Depending on which bundle you might have purchased you might
also receive a case or other accessories. Feel free to put those items
together prior to starting up your Pi. The Pi requires 5V 1A power
so if you did not purchase a power supply you will need to locate
one that has a Micro USB tip on the end. Many smartphone and
tablets use Micro USB charging cables, those will work just fine.

Raspberry Pi is a trademark of the Raspberry Pi Foundation. Parts of this manual are reproduced from Raspberry Pi Beyond the Manual and
is copyright of or licensed by Future Publishing Limited (a Future plc group company), UK 2013. All rights reserved. The rest of this manual is
copyright of Premier Farnell UK Limited, 2014 and all rights are reserved. No part of this manual may be sold, licensed, transferred, copied
or reproduced in whole or in part in any manner or form or in or on any media without the prior written consent of the copyright owner.

Raspberry Pi User Guide.indd 3 08/07/2014 14:43


Operating Systems
Lets take a look at a sweet selection of
tasty operating systems for the Raspberry Pi.
The Raspberry Pi phenomenon appears to go from
strength to strength; like a runaway train, its ploughing
ahead and forging itself a place in the record books. OUR SELECTION

Raspbian
Its hardly surprising the hardware operating system, creating, learning and Risc OS
alone is developed perfectly for the goals programming, and strapping the poor wee
of the Raspberry Pi Foundation, the beast on to a weather balloon and sending Arch
pricing is pitched perfectly, and having it to the outer edge of the atmosphere. RaspBMC
the unique versatility of Linux as the What many RPi users dont realize, though,
operating system seals the deal nicely. is that theres a wealth of other operating OpenELEC
systems available for their beloved Pi.
Most buyers, once they get their hands Pidora
on their new RPi, make a move towards We thought, therefore, that those users who
the official Raspberry Pi site and follow the arent aware of these other sweet toppings
getting started instructions therein; the for the Raspberry Pi need to be informed,
end result is the user running Raspbian and whats more, they need to have a
Wheezy, the Foundations recommended chocolate box selection presented to them.

How we tested...
Therefore, to get a true all-round
perspective, we took the time to install
the operating systems on a fresh 8GB
microSD Card card. The areas were
looking at are installation, default
software, media playback (out-of-the-
box), looks and usability, the community
behind the OS and their respective
attitudes toward software freedom.
Basically, the very stuff that makes a Linux
user decide on what system to use.
We also want to gauge this from the point
of view of someone whos not as familiar
with Linux as other people are, so that
they can jump into the project without too
much hassle, and not end up leaving it
feeling disheartened.

Raspberry Pi User Guide.indd 4 08/07/2014 14:44


Raspbian RaspBMC
This is the recommended The Raspberry Pi may
distro by the Raspberry have been designed
Pi Foundation. Unless as an educational tool,
you have good reason but hobbyists have
to use a different one, its been pretty quick to
probably your best bet. make it a toy. This distro
Its based on Debian Wheezy, so you can easily is designed to turn your Pi into a media center
install anything from the huge Debian repositories. that can be used to control your TV. Its based
on XBMC, which allows you to play music and
The default desktop environment is LXDE,
videos that you have as files, or stream them
which is very lightweight, but a little basic for
from the internet. The image can be downloaded
some tastes. Xfce is available for people who
from: www.raspbmc.com. For details of how to
like a few more graphical niceties. It has the
install it and set it up, see the following pages.
raspi-config program, which is probably
If you have a MythTV back-end set up, you can
the easiest way of configuring your Pi.
use XBMCPi to provide a front-end interface.
The Raspberry Pi was designed to get
Depending on what type of media you
children into programming, and Raspbian
want to play, you may need to purchase
was designed with this in mind. Youll find Idle
the codec packs that provide access to
(a Python IDE) and Scratch (a programming
patent-protected video and audio algorithms.
environment for young children) on the desktop.
Its available from: www.raspberrypi.org.

Arch Linux Risc OS


While Raspbian has The difference with the
been created to try Risc OS is that it is small
to shield users from and fast. Developed
the internal setup of when the fastest desktop
the OS, Arch Linux is computer was an 8MHz
designed to help users ARM2 with 512KB of
understand how the system works. RAM. The core system including windowing system
and a few apps fits inside 6MB. That means its fast
The initial image, available from
and responsive on modern hardware. The memory
www.raspberrypi.org, includes just the basic
taken by apps is usually counted in the kilobytes.
system to get your Pi running and connected
to the network. It doesnt include much of To Risc OS a 700MHz 512MB Raspberry Pi is
the software you may want to use, such as a luxury, what to do with all that memory? Risc OS like
graphical environment, for example. You should Raspbian, takes you to a nice GUI at the startup.
find the information you need at bit.ly/9APmgA. One feature of the Risc OS is that it boots to the
desktop in 1080P by default. The Risc desktop
Taking it from this initial state to a working
is a little retro but is functional in its default mode.
system will require a bit of work, but along
The Risc OS take a little getting used it, one caveat
the way youll learn about how the internals
is that the Ethernet port is disabled at launch so
of a Linux distribution fit together.
it requires some configuration before using.
Whether or not this is worth all the work,
does of course, depend on you.

Raspberry Pi User Guide.indd 5 08/07/2014 14:44


Installation
Do you need a PhD to install the OS?

The NOOBS operating system installation is as easy


as copying files onto your SD card.

The installation of an operating system simply click on the Configure icon and
image is fairly well documented, as per begin to alter any settings we see fit.
the area on the Raspberry Pi site titled
Arch Linux for the RPi is a different beast,
Guide for beginners which can be found
booting the user into a terminal environment
here: goo.gl/53xgp, along with the simple
and leaving them to download, install
installation routine of using either ddon
and configure their OS. Arch, once fully
Linux, or with the new NOOBS image you
appreciated, is one of the best operating
simply unzip the image download and copy
systems available, but it takes some
the files onto a blank formatted microSD
tweaking to get to a standard desktop.
card in Windows. The process is relatively
painless, its what happens after you insert OpenELEC is the simplest version of XBMC,
the microSD card into the Raspberry Pi starting directly into the XBMC GUI without
and apply some power that the fun starts. any additional configuration required.
The six operating systems on the NOOBS RaspBMC makes it easy for you, once
card Raspbian, Risc OS, Arch Linux, you select this operating system you
OpenELEC, RaspBMC and Pidora each are taken directly to the GUI, no scary
have their own nuances, and methods by terminal prompts to deal with. Once
which to install and provide the user with you have completed the configuration
a base working graphical desktop. While screens and RaspBMC has checked
having a GUI isnt absolutely necessary, it for updates, you will be ready to go.
does cover the large percentage of users
Pidora which is a remix of the Fedora Linux
who are new to Linux. That being the case,
distribution is fairly easy to configure. Once
the definition of installation must include
you select this O/S, you will be presented
getting to the point whereby the new user
with several configuration screens and then
can recognize the operating system as
the desktop will load. One thing to watch
they would a standard Linux desktop in
out or here is the terminal commands are
other words, be presented with a graphical
a little different than the other operating
user interface. In a world where easing
systems (distros in Linux language). The
the user into the bath water of Linux is
foundation that compiled Pidora has
paramount, Raspbian has the most user
a good tutorial here bit.ly/1piC2LA.
friendly desktop, but the other offerings
have just as good a start for the user. In summary, Raspbian would be the easiest
to use and has the most support from
Risc OS, for example; once transferred
the Raspberry Pi Foundation. OpenELEC
to the SD card and booted, we are rapidly
offers the most media support if that is
launched into a colorful and friendly
the route you would like to go. The other
GUI, with relatively detailed messages
operating systems all have their advantages
informing us of any issues during the
and disadvantages. It is up to you to
initial boot and setup. From here, we can
decide which way you would like to go.

Raspberry Pi User Guide.indd 6 08/07/2014 14:44


Loading the O/S
The memory card is affectionately
referred to as NOOBS.
NOOBS is a way to make setting up a RaspberryPi for the first
time much, much easier. You wont need network access, and
you wont need to download any special imaging software.

Insert the microSD card in the memory slot provides a handy tool to let you edit the
underneath the board. Plug your power config.txt configuration file for the currently
cord into the port next to the HDMI video installed operating system, and even a
port. When you boot up for the first time, web browser so you can visit the forums
youll see a menu prompting you to install or Google for pointers if you get stuck.
one of several operating systems into
Once the installation is complete your Pi will
the free space on the card. The choice
restart and a bunch of strange looking text
means you can boot the Pi with a regular
will appear on your screen. If you are new to
operating system like Raspbian, or with a
Linux this might take you back to the DOS
media-center specific OS like RaspBMC.
days. Not to fear this is called the command
Once youve selected the O/S youd like line You will see at the bottom of the page
(see the O/S section for more information), the last line reads raspberrypi login:
make sure you check the dialogue box
Next you will need this information.
at the bottom of the page for the proper
Thedefault username and password are:
language that you prefer. The installer will
build the O/S that you selected (a good Username: pi
time for a sandwich or a cup of coffee). Password: raspberry
Once youve installed an operating system, When you hit the enter key you
your Pi will boot as normal. However, will see the following line
NOOBS stays resident on your card, by Pi@raspberrypi ~ $
holding Shift down during boot you can
return to the recovery interface. This allows Type the following to launch the desktop:
you to switch to a different operating startx
system, or overwrite a corrupted card with Congratulations! You now have started
a fresh install of the current one; it also up your Pi! Now go explore.

The microSD card


slot is located on
the underside of the
Raspberry Pi board.

Raspberry Pi User Guide.indd 7 08/07/2014 14:44


Raspbian
For the majority of people who use it, Raspbian
will be the graphical face of the Raspberry Pi.
It can be obtained and installed on to an SD card by
following the instructions on the previous page.

Once its up and running, its a good overscan This option can be used on
idea to grab the latest versions of all the some displays to make the graphics
software by connecting your Pi to the expand to fill the whole screen. You can
internet, opening a terminal and running: safely ignore it unless you have problems.
sudo apt-get update overclock Get an extra 50 per cent
sudo apt-get upgrade performance at no extra cost! See
Overclocking for more details.
The killer feature of Raspbian is the
raspi-config program. This will start boot_behaviour This rather
automatically the first time you boot, cryptically named option changes
or can be run at any time by typing whether your Pi boots into a graphical
sudo raspi-config in a terminal. environment or a text one.
It has got quite a few options,
The installed software has been kept
but the most important are:
to a minimum. This is a good idea, but
expand_rootfs Because of the way you may find that tools you use on other
Raspbian is installed, it will only create desktop distros arent there. Fortunately,
a 2GB filesystem, so if you have a as Raspbian is linked to the Debian Armhf
larger card, any remaining space repositories, you have access to more
will remain unused. You can use this software than youre ever likely to need. If
option to expand the filesystem to take you like using a mouse, you may want to
advantage of any wasted space. install a graphical package manager. We
recommend Synaptic. To install it, type:
memory_split The Raspberry Pi uses
the same chunk of memory for both sudo apt-get install synaptic
the main processor and the graphics in a terminal. It can then be opened by
chip. Using this option, you can change going to the LXDE menu > Preferences
the amount allocated to each. > Synaptic Package Manager. You can
then install any software you want.

Like all good


distros, Raspbian
comes with a
selection of addictive
time-wasters. This
is Squirrels from the
Pygames selection.

Raspberry Pi User Guide.indd 8 08/07/2014 14:44


12 COOL RASPBERRY PI PROJECTS
The complete channel one temperature monitor and alarm project
The Raspberry Pi softball camera
The Raspberry Pi karaoke machine
The Drinkmotizer: a Raspberry Pi drink mixing robot
New Years Eve countdown timer with fireworks launching ability
Raspberry Pi remote fish tank controls: AKA Project Goldie
The scary door
RaspiWatt: discover power consumption using a Kill-A-Watt & Pi
Build your own Gertboard experimenter kit
Raspberry Pi enabled Christmas lights
Ultimate Raspberry Pi bundle security system
Pumpkin Pi project for Halloween and a second helping of pumpkin Pi

www.element14.com/raspberrypiprojects

Overclocking
The processor at the heart of the Raspberry Ifyou find that your Pi becomes unstable,
Pi is designed to run at 700MHz. That reboot with the Shift key held down to
is, perform 700,000,000 operations disable overclocking, then change the
per second. Of course, designed to option in raspi-config. The maximum
run doesnt mean has to run. You can setting should give you a whopping 50
increase this speed. However, doing this per cent extra speed, which we found
will increase the power consumption, makes a real difference to the desktop user
which in turn increases the amount of experience, especially for web browsing. Overclocking will
heat generated. If it gets too hot, youre increase the amount
If you want to keep an eye on your of power that your Pi
liable to have a smoking pile of silicon
core temperature, you can add the draws, and so may
rather than a functional processor.
Temperature widget to the LXDE panel. become less stable if
Fortunately, Raspbian includes a tool to However, your Pi will automatically turn running a number of
help you ramp up the speed while also off overclocking once it reaches85C. USB devices.
keeping a careful eye on the temperature.
And because this is an official tool,
using it wont void your warranty (unlike
earlier unofficial methods). Overclocking
your Raspberry Pi is simply a matter
of running sudo raspi-config and
then selecting Overclocking.
There are a few options to choose from,
depending on how brave youre feeling.

Raspberry Pi User Guide.indd 9 08/07/2014 14:44


Command line:
Learn the ropes
Get to grips with your Raspberry Pis
command line interface and unleash its
full power without using themouse.
As you have no doubt discovered, Raspbian has a graphical
interface similar to that of Windows or Mac OS X.

You can do most of your day-to-day This is an entirely text-based interface,


tasks in this interface. Theres a file where you type in commands and
manager, web browser, text editor and get a response. We wont lie to you:
many other useful applications. However, it will seem confusing at first. Dont
sometimes you need an interface thats a worry, though once youve had a bit
bit more powerful, and this is where the of practice, it will start to make sense,
command line interface (CLI) comes in. and spending a little time learning it
Its also known as the terminal or shell. now will pay dividends in the future.

LXTerminal running
on the Raspbian
desktop.

10

Raspberry Pi User Guide.indd 10 08/07/2014 14:44


The first thing you need to do is open up a terminal.
ClickonLXTerminal on the Raspbian desktop.

You should now see a line that looks like: .. and two dots always points to the
pi@raspberrypi ~ $ parent directory. To move back to your
home directory, you can enter cd pi.
This is the command prompt. Whenever There is also another way you can do
you see this, you know the system is it. The ~ (pronounced tilda) character
ready to receive input. Now type pwd, always points to your home directory, so
and press Enter. You should see: wherever you are in the filesystem, you
/home/pi can enter cd ~ and youll move home.
If youve changed your username, then Now type ls and hit Enter. This will list
youll see a different line. The rather all the files in the current directory. One of
cryptically named pwd command stands the big advantages of commands is that
for Print Working Directory, and the we can tell them exactly how we want
system simply outputs the directory youre them to behave. This is done using flags,
currently in. When you start a terminal, which come after the command and
it will go to your home directory. start with a -. For example, if we want
to list all the files in the current directory
Now we know where we are, the next
(including hidden ones, which start with a
logical thing to do is move about through
. on Unix-based systems), we use the
the directories. This is done using the cd
flag -a. So, in your terminal, type ls -a.
(change directory) command. Try entering:
cd .. This time, you should see more files
appear. Another flag for ls is -l. This
pwd
gives us more information about each file.
You should find that the system returns Try it out now by typing ls -l. You can
/home. This is because weve cded to even combine flags, such as in ls -al.

Interactive programs
Most of the commands were dealing with There are a few quite complicated ones that
here are non-interactive. That means you are great if you spend a lot of time working
set them running and then wait for them from the command line, but they can be
to finish. However, not all command line hard to learn. Theres also an easy-to-use
programs work like this. For example, when terminal-based text editor called nano.
you first booted Raspbian, it started a config Enter nano followed by a filename at the
tool that ran in the terminal. There are a few command prompt to start it. You can then
other programs that work in a similar way. navigate around the text file and make any
Traditionally, the most common has been changes you need. Press Ctrl+X to save
text editors that allow you to work on files your work and exit back to the prompt.
if you dont have a graphical connection.

11

Raspberry Pi User Guide.indd 11 08/07/2014 14:44


Knowing what commands to use
At this point, youre probably wondering how on earth
you are supposed to know what commands
and what flags you can use for a task.

Well, theres good news and bad news. the command given as an argument. Tosee
The good news is that its usually not too the man page for ls, type man ls. You can
difficult to find out the flags for a command. navigate through the page using the up
Most commands support the -h or --help and down arrows, or the page up and page
flags, which should give some information down keys to scroll faster. To search for a
about what flags a command can take word or phrase inside the man page, type
and how to use it. For example, if you /, then the phrase. For example, /-l will
run ls --help, youll see a long list of find all occurrences of -l. You can use the
flags and what they all do, including: N key and Shift+N to scroll forwards and
-a, --all do not ignore backwards through the occurrences of-l.
entries starting with . As we introduce more commands, its
good to take a look at the help and the
-l use a long listing format man page to familiarize yourself with
what they do. Of course, you can always
The second way of finding information on
Google a command if you find the text-
a command is using man. This is short for
based help a little off-putting, but staying
manual. It takes a single argument, that is, a
in the terminal will help you become more
word after the command that isnt preceded
familiar with the command line interface.
by a hyphen. It then displays information on

Tab completion
When youre dealing with
long filenames, it can be very
annoying to have to type them
out every time you want to run
a command on them. To make
life a bit easier, the terminal uses
tab completion. This means that
if you start typing a filename
and press the Tab key, the
system will try to fill in the rest
of the name. If theres only one
file that fits what youve typed
so far, it will fill in the rest of the
name for you (try typing cd /h
then pressing Tab). If there are
more than one, it will fill in as far
as the two are the same, If you
press Tab again, it will show
the options (try typing cd /m,
You can even watch movies in the command line. To stream the classic,
and then pressing Tab twice).
just enter telnet towel.blinkenlights.nl and put somepopcorn on.

12

Raspberry Pi User Guide.indd 12 08/07/2014 14:44


How will I know?
Remember we said theres good news and bad news?
Well, the bad news is that it can be quite tricky to find
commands if you dont know what theyre called.

One helpful feature is the man keyword Were now going to quickly introduce a few
search. This is done with the -k flag. useful commands. rm deletes (ReMoves)
To search for all the programs related a file. mkdir makes a new directory. cp
to browser on your system, run copies a file from one place to another.
man -k browser. Youll notice that This one takes two arguments, the original
this lists graphical programs as well as file and the new file. cat outputs the
command line ones. This is because theres contents of one or more text files. This
no real difference between the two. You takes as many arguments as you want,
can launch windows from the terminal, each one a text file, and simply spits their
and sometimes even control them. contents out on to the terminal. less is
a more friendly way of viewing text files.
If youve got Iceweasel (a rebranded
It lets you scroll up and down using the
version of Firefox) installed on your
arrow keys. To exit the program back to
Pi (its not on there by default), you
the command line, press Q. Well use all
can open TuxRadar.com in a new
these commands in examples below, so
tab in a currently running Iceweasel
we wont dwell on them for too long.
window with the command iceweasel
--new-tab www.tuxradar.com.

find
find is a useful
command for
finding files on your
computer. You use
it in the format find
location flags.
For example, to
find every file on
your computer
thats changed in
the last day, run
find / -mtime 1
There are more
details of what
this means, and
the different flags
that can be used
over the page.
Probably the most important command in any Unix-like system is man, since it is the key to
understanding every other command. Take time to become familiar with the structure and language
used and it will make life easier in the future.

13

Raspberry Pi User Guide.indd 13 08/07/2014 14:44


Power up
So far youre probably thinking to yourself, I could have done all this in the graphical
interface without having to remember obscure commands and flags.

Youd be right, but thats because we havent introduced How about one*? Again, run
the more powerful features yet. The first of them are ls one*
wildcards. These are characters that you can put in that
match different characters. This sounds a bit confusing, to see if you were correct. The wildcards can be
so were going to introduce it with some examples. used with any command line programs. Theyre
particularly useful for sorting files. To copy all the
First, well create a new directory, move into it and create .txt files into a new directory, you could run:
a few empty files (we use the command touch, which
mkdir text-files
creates an empty file with the name of each argument).
Hint you can use tab completion to avoid having cp *.txt text-files
to retype long names, such as in the second line. We can then check they made it there correctly with:
mkdir wildcards ls text-files/
cd wildcards The second wildcard well look at is ?. This matches
touch one two three four any single character. What do you think:
touch one.txt two.txt three.txt four.txt ls ???
Then run ls to see which files are in the will match? Have a guess, then
new directory. You should see eight. run it to see if youreright.
The first wildcard well use is *. This matches any string We can also create our own wildcards to
of zero or more characters. In its most basic usage, match just the characters we want. [abc] will
itll match every file in the directory. Try running: match just a lower-case A, B and C. What do
ls * you think ls [ot]* will match? Now try
This isnt particularly useful, but we can put it in ls [!ot]*
the middle of other characters. What do you think What difference did the exclamation mark
*.txt will match? Have a think, then run: make? It should have returned everything that
ls *.txt didnt start with a lower-case letter O or T.
to see if you are right.

sudo
When using the Raspberry Pi for normal use, your settings. However, there are times when
you can work with files in your home directory you need to do this. You can use sudo to run a
(for example, /home/pi). You will also be able command as the super user (sometimes called
to view most other files on the system, but you root), which can do pretty much anything on the
wont be able to change them. You also wont system. To use it, prefix the command with sudo.
be able to install software. This is because Linux For example:
has a permissions system that prevents ordinary sudo apt-get install synaptic
users from changing system-wide settings. This is
great for preventing you from accidentally breaking will install the package synaptic and make it
available to all users.

14

Raspberry Pi User Guide.indd 14 08/07/2014 14:44


Pipes and redirection
The commands that weve been looking at so far have all
sent their output to be displayed in the terminal.

Most of the time this is what we want, but command. There are a lot of commands
sometimes its useful to do other things with that work with text that are designed to
it. In Linux, you can do two other things with be used in this way. Theyre beyond the
a command: send it to a file, or send it to scope of this tutorial, but as you continue to
another program. To send it to a file, use the use the command line, youll come across
> character followed by the filename. Run: them and start to see how they can be
ls > files linked together. Well take a look at a simple
example. If you run find / (dont do it just
cat files
yet!) it will list every file on the system.
and you should see that it creates
This will produce a reel of filenames that
a new file called files, which
will quickly go off the screen. However,
contains the output of ls.
rather than direct it to the screen, we can
The second option, sending it to another send (or pipe) it to another command
program, is another of the really powerful that makes the output easier to read.
features of the Linux command line, We can use the less command that we
because it allows you to chain a series of looked at on page 13 for this. Run:
commands together to make one super find / | less

Take it further
Weve only been able to touch
on the basics of using the
command line, but you should
have enough knowledge
now to get started, and
hopefully youre beginning
to see just how powerful the
command line interface is
once you get to know it.
If you want to know more (and
you should!) there are loads of
resources in print and online.
LinuxCommand.org is a great
place to start. Its book (The
Linux Command Line) is available
from bookshops, or for free
online www.linuxcommand.org/
lc3_learning_the_shell.php.

Use the sudo command to switch between the normal user pi, and the superuser root.

15

Raspberry Pi User Guide.indd 15 08/07/2014 14:44


Packages:
How do they work?
Discover how Raspbians package manager,
apt-get, gets software from online repositories
andmanages it on your system.
If youre used to Windows, you may be used to each bit of
software having its own installer, which gets the appropriate
files and puts them in the appropriate places.

Linux doesnt work in the same way (at least, There are a few different package
it doesnt usually). Instead, there is a part of managers available for Linux, but the one
the operating system called the package used by Raspbian is apt-get. Arch uses
manager. This is responsible for getting a different one, so if you want to try this
and managing any software you need. It distribution on your Raspberry Pi, youll
links to a repository of software so it can need to familiarize yourself with the pacman
download all the files for you. Since Linux software, which we wont cover here.
is built on open source software, almost
Before we get started, we should mention
everything you will need is in the repositories
that since this grabs software from the online
and free. You dont need to worry about
repositories, you will need to connect your Pi
finding the install files, or anything like that
to the internet before following this section.
the package manager does it all for you.

16

Raspberry Pi User Guide.indd 16 08/07/2014 14:44


apt-get is a command line program, so to start with In order to install software with apt-get, you
youll need to open a terminal (see the command line need to know the package name. Usually this
interface section on page 10 for more information on is pretty obvious, but it needs to be exactly right
this). Since package management affects the whole for the system to get the right package. If youre
system, all the commands need to be run with sudo. unsure, you can use apt-cache to search through
The first thing you need to do is make sure you have the list of available packages. Tryrunning:
the latest list of software available to you. Run: apt-cache search iceweasel
sudo apt-get update
This will spit out a long list of packages that all
Since all the software is handled through the have something to do with the web browser
package manager, it can update all the software (Iceweasel is a rebranded version of Firefox).
for you so you dont need to bother doing it for
To install Iceweasel, run:
each program separately. To get the latest versions
of all the software on your system, run: sudo apt-get install iceweasel
sudo apt-get upgrade You will notice that apt-get then prompts you
to install a number of other packages. These are
This may take a little while, because open source
dependencies. That means that Iceweasel needs the
software tends to be updated quite regularly. In Linux
files in these packages in order to run properly. Usually
terms, you dont install particular applications, but
you dont need to worry about these just press Y
packages. These are bundles of files. Usually, each one
and the package manager will do everything for you.
represents an application, but not always. For example,
a package could be documentation, or a plug-in, or However, if your SD card is running low on space, you
some data for a game. In actual fact, a package is just may sometimes come across a program that has so
a collection of files that can contain anything at all. many dependencies that theyll overfill the device. In
these cases, youll either need to free up some space or
find another application that has fewer dependencies.

apt-cache in a terminal will give you a list of available packages.

17

Raspberry Pi User Guide.indd 17 08/07/2014 14:44


If you then want to remove This works with packages in the
Iceweasel, you can do it with: same way as apt-get, but with a
sudo apt-get purge iceweasel graphical interface. Once the package
is installed, you can start it with:
The package manager will try to
--where is synaptic
remove any dependencies that
arent used by other packages. See below for more information.
Youll often see packages with -dev at The second graphical tool is the Raspberry
the end of package names. These are Pi App store. Unlike apt-get and
only needed if youre compiling software. Synaptic, this deals with commercial
Usually you can just ignore these. software as well as free software, so
you have to pay to install some things.
apt-get is a great tool, but it isnt as
It comes by default on Raspbian, and
user-friendly as it could be. There are
you can get it by clicking on the icon on
a couple of graphical tools that make
desktop. See Raspberry PiStore on
package management a bit easier. The
the next page for more information.
first well look at is Synaptic. This isnt
installed by default on Raspbian, so youll
have to get it using apt-get with:
sudo apt-get synaptic

Synaptic
Synaptic lets you do everything
you can with the command
line apt-get, but the graphical
interface is easier to use. We
find it especially useful when
searching, because the window
is easier to look through
than text on the terminal.

Synaptic provides a user-friendly


front-end to the apt package
management system.

18

Raspberry Pi User Guide.indd 18 08/07/2014 14:44


Compiling software
Sometimes, youll find you need software that isnt in the repository, and
so you cant get it using apt-get. In this case, youll need to compile it.

Different projects package their source code how to continue with the installation.
in different ways, but usually, the following Usually (but not always), it will say:
will work. Get the source code from the ./configure
projects website, and unzip it. Usually,
make
the filename will end in .tar.gz or .tgz. If
this is the case, you can unzip itwith: sudo make install
tar zxvf <filename> The first line will check you have all the
necessary dependencies on your system.
If the filename ends in .tar.bzip2, you need
If it fails, you need to make sure you have
to replace zxvf with xjf. This should
the relevant -dev packages installed.
now create a new directory which you
need to cd into. Hopefully, therell be a If that all works, you should have the
file called INSTALL, which you can read software installed and ready to run.
with less INSTALL This should tell you

Raspberry Pi store
The Raspberry Pi store allows
users to rate the software, so you
can see how useful other people
have found it. It also includes
some non-free software. However,
it doesnt have anywhere near
the range that is available
through apt-get or Synaptic.

The Pi Store is an app store


foryour Raspberry Pi.

19

Raspberry Pi User Guide.indd 19 08/07/2014 14:44


RaspBMC
You can install a media player, such as VLC,
on to Raspbian, and use that to play videos.
This works fine if youre using your Raspberry Pi as a general
computer and giving it occasional multimedia functions.

However, the small size of the hardware, and you may have experienced on Raspbian.
the fact that it runs silently, makes it a good You can play media stored locally or, through
choice for building your own entertainment the use of add-ons, stream content from the
center. You could start from Raspbian and internet. Music and videos can be added
customize it to your needs, and this is a to your setup either by attaching a USB
good idea if you have any unusual functions device, or directly on to the SD card using
in mind. Fortunately for us (and you), a team FTP (username pi, password raspberry).
of hackers have done all the difficult bits of See below for how to find the IP address.
building a media center for the Raspberry
Perhaps the only piece of configuration
Pi, and packaged it for you to use. Follow
you will need is to make sure the sound is
the guide on page 6 to install the RaspBMC
sent to the right place. Under System >
operating system from the NOOBS image.
System > Audio Output, make sure that
This uses the popular XBMC media desktop, Output is set to Analog if youre using
which is quite different from LXDE, which the jack, or HDMI if youre using this.

The Model B+
boards have mounting
holes to help you keep
your entertainment
center tidied away.

20

Raspberry Pi User Guide.indd 20 08/07/2014 14:44


This is all good, but its a bit impractical to use a
mouse and keyboard to control your telly. The Taking it further
good folks at XBMC thought of this and added
support for remote controls. The simplest and It is possible to take complete control of your TV
most general-purpose way of doing this is via viewing using Linux, including watching live TV, and
recording shows for later. This can be done using
RaspBMCs web interface. Using this, any
MythTV (available from www.mythtv.org). Youll
device with a web browser thats on the same
need a separate computer with the appropriate
network as the Pi can control the playback.
cable connections to act as the server.
This is enabled by default, so all you need to do is You can play video files that you have stored on other
find out the IP address of the Pi in System > System computers on your network, for example those on
Info (you should be able to set this to be a static IP a Network Attached Storage (NAS) box. The exact
on your router). Then, on any other device attached method for doing this will vary depending on how you
to a network, open a browser and point it to that IP. share the files, but they are configured through the
Add Sources buttons. For more information about
If youre a modern sort, and using an Android or
this, you should check out the wiki at: bit.ly/OOvXb6.
iOS mobile device, you should find a selection of
apps in the various app stores that can do this
with a nicer interface than the HTML pages. A new
feature on the Model B+ allows a software switch
to be set in the config.txt which allows additional
power to be routed to the 4 USB ports (up to a
maximum of 1.2Amps). This provides enough power
to drive a 2.5 inch hard drive directly off the Pi. To
enable this feature the Pi must be powered using
a 1.8Amp or 2Amp micro USB power supply.

This is the default


remote, but other
more graphically
stimulating ones
are available in the
RaspBMC settings.

21

Raspberry Pi User Guide.indd 21 08/07/2014 14:44


Camera controller
Back up your photos using your Pi.
The size of the Raspberry Pi means we can use
it to take control of other embedded devices.

This may seem a little redundant the Firstly, theres support for most in Linux, and
embedded devices obviously have some secondly theres a range of useful projects
form of controller already but it means we you can do once youve grasped the basics.
can script and extend them in ways that
The best command-line tool for manipulating
arent possible (or are, at least, very difficult)
cameras in Linux is Gphoto2. Get it with:
without the extra device. Almost anything
that you can plug in to a normal desktop apt-get install gphoto2
can be scripted by a Pi, but were going to
look at cameras for a couple of reasons.

Gphoto2 has far more capabilities than we use here, including bindings for Java and Python.
For full details, check out the project website: www.gphoto.org.

22

Raspberry Pi User Guide.indd 22 08/07/2014 14:44


Before getting stuck in to the project, well take
alookat this useful tool to see what it can do.

The desktop environment can try to mount on higher-quality cameras. The latter
the camera, and this can cause Gphoto2 let you deal with photos stored on the
a few problems, so the easiest thing memory card, and are present on most
to do is run without it. Open a terminal supported cameras. In this project, well
and run sudo raspi-conf, and under deal only with the second set of abilities.
Boot Behaviour, select No to not start
The simplest command we can
the windowing system, then reboot.
send to the camera is to get all the
In the new text-only environment, photos stored on it. This is:
plug in your camera and run: gphoto2 --auto-detect
gphoto2 --auto-detect --get-all-files
This will try to find any cameras attached Running this will download all the files from
to the Pi. Hopefully, it will pick up yours. the camera into the current directory. This
While it does support an impressive would be fine on a normal computer, but
array, there are a few cameras that you may not want to do it on a Pi, as you
wont work. If yours is one of the unlucky run the risk of filling up your memory card
few, youll need to beg, steal or borrow pretty quickly. Instead, well copy them on
one from a friend before continuing. to a USB stick. To do this in an interactive
session, you could simply use a GUI tool
Not all supported cameras are equal, so to mount the stick then run df -h to see
the next step is to see what the camera where the USB stick is mounted, and cd
can do. To list the available actions, run: to the directory. However, since this will
gphoto2 --auto-detect --abilities run automatically, we need to know where
There are, broadly speaking, two main the device will be. There are a few ways
classes of abilities: capture, and upload/ of doing this, but well keep it simple.
download. The former let you take photos Well mount the first partition of the first
with your scripts, and are present mostly serial disk, and store the photos there.

Powering your Pi
The Raspberry Pi gets power from its other options. Four AA batteries, for
micro USB port. This supplies 5V, and the instance, should provide enough power,
Raspberry Pi foundation recommends provided you have the appropriate
an available current of at least 600mA. housing and cables to get the power
This can easily be delivered via a into the micro USB port. However,
mains adaptor, or a USB cable from a we found the best solution was to get
computer. If you want your Raspberry a backup power supply for a mobile
Pi to be portable, however, there are phone that plugs directly into the Pi.

23

Raspberry Pi User Guide.indd 23 08/07/2014 14:44


Here, were assuming that youre using the default user pi.
If youre not, youll need to adjust the script.
First, we need to create a mount point it will decline. The umount is essential,
for the drive. This is just a folder, and can because it ensures that the drive is
be put anywhere were going to spurn properly synced and can be removed.
convention and put it in our home folder.
Weve called the script get-pics.sh,
So before running the script, run:
andsaved it in Pis home directory.
mkdir /home/pi/pic_mount To make it executable, run:
With this done, were ready to go. The script chmod +x /home/pi/get-pics.sh
to mount the drive and get the photos is:
You should now be able to run it
#!/bin/bash manually. Youll need to use sudo
because it needs to mount the drive.
if mount /dev/sda1 The final piece of the puzzle is to get the
/home/pi/pic_mount ; then script to run automatically. To do this,
echo "Partition mounted" we add it to the file /etc/rc.local.
cd /home/pi/pic_mount This script runs when you boot up, and
yes 'n' | gphoto2 -- it executes as root, so theres no need to
auto-detect --get-all-files worry about permissions. Just open the
umount /dev/sda1 file with a text editor as root. For example,
with sudo nano /etc/rc.local,
else and add the line:
echo "/dev/sda1 could not
/home/pi/get-pics.sh
be mounted"
fi just before the line exit 0.
Now all you have to do is plug in your
yes 'n' is a command that simply camera (making sure its turned on,
emits a stream of n characters. This of course) and your USB stick, and
means that when Gphoto2 prompts to itll back up your photographs when
overwrite any previously downloaded files, you boot up your Raspberry Pi.

In this form, its not


very portable, but with
a little bit of judicious
DIY, you should be
able to package it
more conveniently.

24

Raspberry Pi User Guide.indd 24 08/07/2014 14:44


New directions
If you want to run the device headless, as will most likely be
the case, you could attach LEDs to the GPIO pins, as shown
over the page, and then use these to indicate statuses.

As well as saving them to the USB stick, upload those. Of course, you dont have
you could upload them to an online to stop there. If you have a wireless dongle
service, such as Flickr. See the box on in your Pi, you could use it to run an HTTP
networking below for information on server. With some PHP (or other web
how to connect your Pi to your phone. language) scripting, you should be able to
create an interface to GPhoto2 that will allow
You could include some sort of switch to tell
you to connect from your mobile phone.
your Pi which photos to upload, and which
to store on the USB stick for example, Taking it in a different direction,
upload low-resolution images, and store if your camera supports capture
high-res ones. Or you could create low- options, you could use your Pi to take
resolution versions of the images, and photos as well as copy them.

Networking
The Raspberry Pi comes with a wired on the Pi, if you type sudo ifconfig,
Ethernet connection, which is fine for you should then see the interface usb0
most occasions, but sometimes the listed, but it wont have an IP address.
cable just wont reach. You could use a
Networking interfaces are controlled
USB wireless dongle however, if youve
by the /etc/network/interfaces file.
got an Android phone, and your carrier
By default, there isnt an entry in here
hasnt disabled the feature, you can use
for USB networking, so we need to set
this as your networking device. This has
one up. Open the file with your favorite
an extra advantage of not drawing as
text editor as sudo. For example, with
much power from the Pi, and so makes
sudo nano /etc/network/interfaces
it easier when running from batteries.
and add the lines:
You should be able to share your iface usb0 inet dhcp
phones connection to Wi-Fi as well
as 3G, so it wont necessarily eat into nameserver 208.67.220.220
your data allowance. Of course, its nameserver 208.67.222.222
best to check the connection type
This used the OpenDNS nameservers,
before downloading large files.
but you could use others if you wish.
To do this, connect your phone to your
You can now either restart the interfaces
Pi, and enable tethering in Settings >
or restart your Raspberry Pi to pick
Wireless and Networks > Tethering and up the changes. You should have an
Portable Hotspots (on the phone). Back internet connection up and running.

25

Raspberry Pi User Guide.indd 25 08/07/2014 14:44


Sending output
Use the GPIO pins to light up some LEDs.
The Pis tiny size makes it ideal for making your own embedded
devices. This can be a great way of creating small computing devices
to solve specific problems, as we saw with the camera controller.

However, there is the slight problem that can be used to display information from
it can be hard to know whats going on any source, but here were going to use it
inside your Pi without a screen. Fortunately, to find the final byte of the IP address. This
the designers of the Pi thought of this is useful if you want to remotely access
problem and have added the facility to get your Pi, but cant configure it with a static
information on and off a Pi without the bulk IP because, for example, you have to
of usual PC peripherals. This is done via move it between networks. Typically, you
General Purpose Input and Output (GPIO). can find out the first three bytes from the
netmask, but the final one can be elusive
You may have wondered what the spiky
unless you have a monitor attached.
pins near the SD card reader are for well,
youre about to find out. This basic circuit

Figure 1. This shows


how half of the LEDs
are wired up. The
additional ones are
added in exactly the
same manner.

26

Raspberry Pi User Guide.indd 26 08/07/2014 14:44


Were going to use the gpio program, which The circuit for this is very simple you
is part of WiringPi. You can find out more just have to connect each output to
about this from the website: bit.ly/RP8UKJ. the positive leg of an LED, then the
negative leg of the LED (shorter) to a
The software comes as source code, so
1KOhm resistor, and finally the other leg
well have to unzip it and compile it with:
of the resistor to the common ground.
tar xvf wiringPi.tgz See figures 1, 2 and 3 for details.
cd wiringPi/wiringPi
Once you have your fully-set-up board
make connected to your Pi, you can make things
sudo make install happen. To start with, well just use the
cd ../gpio final pin. This is pin 7 (the layout of the pins
make doesnt follow a numbering pattern). Open
up a terminal, and set it to output with:
sudo make install
gpio g mode 7 out
Well also use bc, so install it with:
Then you can turn it on with:
sudo apt-get install bc
gpio g write 7 1
Now, thats enough about software on
with the hardware! Just a quick word of and off again with:
warning before we start: it is possible gpio g write 7 0
to break your Pi by connecting the If youre like us, youll do that repeatedly until
wrong wires together, so make sure you the novelty of it wears off. Once it has, youre
double-check before powering up. ready to run the script. It contains fourparts.

PIN PIN PIN PIN PIN PIN PIN PIN

Figure 2. Connect
the bread board to
these pins. Weused
commercially-
available single-pin
connectors, but you
could also solder
connectors on, or use
an oldIDE cable.

27

Raspberry Pi User Guide.indd 27 08/07/2014 14:44


The first just sets the pins to the right bit=1
mode and makes sure theyre turned off: for x in $pins
pins="7 8 25 24 23 18 15 14" do
out=`echo $paddedBinary | cut
for x in $pins -b$bit`
do gpio -g write $x $out
gpio -g mode $x out bit=$((bit+1))
gpio -g write $x 0 done
done And, finally, we tell the script to sleep for
The second grabs the IP address from five minutes, then turn the LEDs off.
ifconfig, converts it to binary, then pads sleep 5m
it out with leading zeros, if necessary. for x in $pins
ipaddress=`ifconfig eth0 | grep do
'inet ' | awk '{print $2}' | cut
gpio -g write $x 0
-f4 -d'.'`
done
binary=`echo
"ibase=10;obase=2;$ipaddress" | bc` Thats it! Save this into a file called
paddedBinary=`printf %08d $binary` showIP.sh, make it executable with:
The next part uses cut to extract the chmod a+x showIP.sh
part we want from this binary string and type sudo ./showIP.sh to display
and outputs it to the appropriate pin. your IP. To get this run automatically on
boot, you just need to add the line:
/home/pi/showIP.sh &
to rc.local. See the Camera controller
section for details on how to do this.

Gertboards and Arduinos


Connecting directly to your Pis GPIO pins can
provide you with basic input and output control,
but there are limitations. There are two additional
items that you can obtain to help you interact
more precisely with the world around you.
Figure 3. The simple circuit in all its glory.
The Gertboard is a fairly complete expansion
pack for connecting between your Pi and
the real world, including a micro controller,
and a range of input and output options.
Meanwhile, the Arduino is a micro controller that
can connect to your Pi (or any other computer)
via the USB port. Typically, it comes assembled,
but kit forms are also available. In its raw form,
it has fewer features than the Gertboard (which
includes an Arduino microcontroller), but it can
be expanded with a huge range of shields.

28

Raspberry Pi User Guide.indd 28 08/07/2014 14:44


Weve shown you how to send output via the GPIO,
butas the name suggests, they can also receive input.

With this, its even more important to own circuits, or use ones off the web, make
ensure that you dont send too much sure you use the right pins for your board.
power into the pins. To get input, just set
You dont have to limit yourself to
the mode to input with gpio g mode
just switching pins on and off. The Pi
<pin number> in and then read the
supports a few methods of passing
value with gpio g read <pin number>.
larger amounts of data through the
This hardware can display any eight bits GPIO. The two most common of these
of information, so you dont have to limit are Serial Peripheral Interface bus (SPI)
it to displaying just IP addresses. For and Inter-Intergrated Circuit (IC).
example, you could make a modified
There are a number of devices available
version of the camera controller script to
that use these, and plenty of information
use the LEDs to indicate its progress.
online to help get you started. So
You can find details on the full selection of whats stopping you? Get out your
GPIO pins at bit.ly/JTlFE3. If you design your soldering iron and build a robot army.

Ohms Law
There are two key ways of measuring As a rough rule of thumb, you can expect
electricity: voltage and current. Voltage to draw voltage out of a GPIO pin at 3.3V,
(measured in volts) is the amount of and you shouldnt draw more than 16mA,
energy a given quantity of electrons has, or push more than this into an input pin.
while current (measured in amps) is the
This is the maximum current; you should
amount of electrons flowing past a point.
aim to use less. So, with Ohms law we
The two are intimately connected by know V=IR, so R=V/I. If we put in the data
Ohms law which states: Voltage = from the Pi, and want to ensure we dont
Current x Resistance, or V=IR. You can damage it, we know that R must be greater
use this connection to make sure you than 3.3/0.016, which is 206.25 Ohms.
dont accidentally toast your Raspberry
Remember, this is the smallest amount
Pi by pushing too much current into
of resistance its safe to use with a
it. The exact setup of the Pi is a little
GPIO output. You should aim for a
complex. If you wish to delve into it,
margin of safety several times above
Gert van Loo (one of the designers)
this unless absolutely necessary. In our
has put together an explanation, which
circuits, weve used 1,000 Ohms, which
can be found at: bit.ly/Qp4PMl
gives us a safety factor of almost 5.

29

Raspberry Pi User Guide.indd 29 08/07/2014 14:44


Minecraft Pi
Minecraft on the Raspberry Pi
Minecraft: Pi Edition is a version of Minecraft thats
designed to work on the Raspberry Pi.

Based on the Pocket Edition, Minecraft Pi To decompress your freshly


is smaller and faster as well as containing downloaded package type:
support for multiple programming tar zxvf minecraft-pi-0.1.1.tar.gz
languages. Minecraft Pi runs on the
Raspbian Operating System for the PI. This To start it:
is the most common operating system Type cd mcpi
used on the Pi. To get started, head over to
Then:
s3.amazonaws.com.assets.minecraft.net/
pi/minecraft-pi-0.1.1.tar.gz to download ./minecraft-pi
the package. Once that is finished, At this point you can play Minecraft as
open a new terminal window or click on a single user or over a network. What
LX Terminal icon on the desktop. is really exciting is what comes next
which is programming Minecraft to
perform certain functions for you.

Minecraft Pi.

30

Raspberry Pi User Guide.indd 30 08/07/2014 14:44


Programming Minecraft Pi
Once you have launched the game then you can select Start Game
followed by Create New. This should take you into a randomly
generated world that you can start to modify with code.

You should still have your LX Terminal Congratulations, you have learned
windows open. If not then click on the LX to simply program Minecraft Pi.
Terminal window again to open a command
Now on to a more advanced project,
line prompt. To do this you will need to
that is Placing Block within your
press escape to pause the game and allow
game. To place a block lets type the
you to move the mouse out of the game
following at the command prompt:
window. You can then launch another
terminal from the desktop. One way is to import block
have the programming terminal window mc.setBlock(0, 10, 0, block.STONE)
and the Minecraft Window side by side
The first line which imports block simply
Once you have your terminal launched allows us to use the block names when
you need to go to the Python API we position them. The name block.
directory (programming tools) by typing STONE can be changed to block.
the following at the terminal window: LAVA, block.MELON or block.WATER.
cd mcpi/api/python/mcpi The Minecraft Wikipage gives you
many other types of blocks to use.
and then: minecraft.wikia.com/wiki/Category:Blocks
python
The second line calls setBlock and passes
and pressing return. in 3 numbers and the block type. These 3
numbers are the X, Y and Z coordinates in
Your terminal prompt should change to >>>.
the game world. Just like you would find
Now we are ready to start programming. in maths, this coordinate system, called
The first thing we need to do is to Cartesian Coordinates, allows you to map
import the Minecraft library. your blocks in a 3D world. From your player
start position X is left and right, with numbers
At the command prompt in the
going down as you head left and up if you
terminal windows type:
head right. The Y coordinates are up and
import minecraft down, with up increasing the number and
Now we need to initialize it which will down decreasing the number. This leaves
create a connection to your game the Z axis being forwards and backwards,
and allow you to start modifying with forward increasing the number and
the game world. So now type: backwards decreasing. Its worth noting that
decreasing numbers go to a negative value.
mc = minecraft.Minecraft.create()
Have a go at setting different coordinates for
You can now use the mc object you
blocks and see how they come out. If you
have created to control the world. Lets
dont see a block then it means you either
say hello to your Minecraft world:
put it very far away or its underground. To
So type at the terminal window: avoid blocks going too far away try and keep
mc.postToChat("Hello Minecraft the X, Y and Z values within 20 and -20.
World!") You can view the source code for this
You should then see your message tutorial here: github.com/piprogramming/
come up on the chat window in your Minecraft/blob/master/tutorial1.py
game. Feel free to change this message
If you have the git-core package
to what ever you want. You can use the
installed then you can download it
postToChat method to post all sorts of
using: git clone git://github.com/
information you want the player to see.
piprogramming/Minecraft.git

31

Raspberry Pi User Guide.indd 31 08/07/2014 14:44


Postscript
The making of Pi
The idea behind a tiny and affordable computer for kids came in 2006,
when EbenUpton, Rob Mullins, Jack Lang and Alan Mycroft, based
at the University of Cambridges Computer Laboratory, became
concerned about the year-on-year decline in the numbers and skills
levels of the A-Level students applying to read Computer Science.

From a situation in the 1990s where Pete Lomas, MD of hardware design


most of the kids applying were coming and manufacture company Norcott
to interview as experienced hobbyist Technologies, and David Braben, co-author
programmers, the landscape in the 2000s of the seminal BBC Micro game Elite,
was very different; a typical applicant to form the Raspberry Pi Foundation to
might only have done a little web design. make it a reality. Three years later, the
Raspberry Pi Model B entered mass
The project started to look very realizable.
production through licensed manufacture
Eben (now a chip architect at Broadcom),
deals with element14, and within two
Rob, Jack and Alan, teamed up with
years it had sold over three million units.

More information
For more information about your Pi, the
following links are the best places to start
www.element14/raspberrypi
www.raspberrypi.org
www.mcmelectronics.com
www.cpc.farnell.com/raspberrypi
www.element14.com/raspberrypiprojects

32

Raspberry Pi User Guide.indd 32 08/07/2014 14:44


Command Line reference

Navigation and files

cd Changes directory. For example, cd movies moves to the


movies folder. cd ~ moves to your home directory, cd /
moves to the root directory, cd .. moves back one directory.

ls Lists files. By itself, it lists the files in the current directory.


ls movies lists the files in the directory movies. ls -a
lists all files (includinghidden ones), and ls -l lists more
information about each file.

cp Copies files. cp orig-file new-file copies


orig-file to new-file.

wget Downloads a file from the internet. Todownload


the Google homepage to the current directory, use
wget www.google.com.

df -h Displays the amount of space left on the device.

pwd Displays the current directory.

| The pipe symbol is used to pass information from one


program to another.

Finding files

find <location> <tests> Useful flags include: -mtime <number> finds files modified
in the last <number> days. <number> could be, for example,
2 (exactly two days ago), -2 (less than two days ago)
or +2 (more than two days ago). -name <filename>
finds files called <filename>. -iname <filename>
matches files called <filename> but not case-sensitive.
-writable finds files that are writable. There are many
more options. See the man page for a detailed list. For
example find / -mtime -2 -writable finds all files on the
filesystem that were changed less than two days ago and are
writable by the current user.

33

Raspberry Pi User Guide.indd 33 08/07/2014 14:44


Command Line reference

Remote working

ssh Log in to a remote computer using Secure SHell (SSH


protocol). ssh pi@192.168.1.2 will log in as user pi on the
computer at the IP address 192.168.1.2. Note, this will only
work if the remote computer has an SSH server running.

scp Secure copy. scp file pi@192.168.1.2 :/home/pi will


copy a file to the directory home/pi on the machine with
192.168.1.2. scp pi@192.168.1.2:/home/pi/file. will
copy /home/pi/file from the machine 192.168.1.2 to
the current directory. Note, this will only work if the remote
machine has an SCP server running.

Wildcards

* Matches any string of characters, or no characters.

? Matches any single character.

[abc] Matches a, b or c.

[!abc] Matches any character except a, b or c.

[A-Z] Matches any character in the range AZ


(that is, any upper-case letter).

[A-z] Matches any character in the range Az


(that is, any upper- or lower-case letter).

[one, two] Matches the words one and two.

Information about the computer

top Displays the programs that are currently using the most CPU
time and memory.

uname Displays information about the kernel. uname -m outputs the


architecture its running on.

lscpu Lists information about the CPU.

dmesg Displays the kernel messages (can be useful for finding


problems with hardware).

34

Raspberry Pi User Guide.indd 34 08/07/2014 14:44


Text files

head Displays the first 10 lines of a text file. Change


10 to any number with the -n flag. Forexample,
dmesg | head -n 15 displays the first 15 lines of the kernel
message log.

less Allows you to scroll through a text file.

cat Dumps the contents of a text file to the terminal.

tail Displays the last 10 lines of a text file. Can use the -n flag like
head. Can also keep track of a file as it changes with the -f
(follow) flag. For example, tail -n15 -f /var/log/syslog
will display the final 15 lines of the system log file, and
continue to do so as it changes.

nano A user-friendly command line text editor (Ctrl+X exits and


gives you the option to save changes).

Special keys

[Ctrl]+[C] Kills whatever is running in the terminal.

[Ctrl]+[D] Sends the end-of-file character to whatever program is


running in the terminal.

[Ctrl]+[Shift]+[C] Copies selected text to the clipboard.

[Ctrl]+[Shift]+[V] Pastes text from the clipboard.

Installing software

tar zxvf file.tar.gz When you unzip a programs source code, it will usually
tar xjf file.tar.bz create a new directory with the program in it. cd into that
./configure directory and run ./configure. This will check that your
system has everything it needs to compile the software.

make This will compile the software.

make install This will move the newly compiled software into the
(needs sudo) appropriate place in your system so you can run it like a
normal command.

apt-get This can be used to install and remove software. For


example, sudo apt-get install iceweasel will install
the package iceweasel (a rebranded version of Firefox).
sudo apt-get purge iceweasel will remove the package.
apt-get update will grab an up-to-date list of packages
from the repository (a good idea before doing anything).
apt-get upgrade will upgrade all packages that have a
newer version in the repository.

apt-cache search Will search the repository for all packages relating
<keyword> to keyword.

35

Raspberry Pi User Guide.indd 35 08/07/2014 14:44


www.element14.com

Raspberry Pi User Guide.indd 36 08/07/2014 14:44

You might also like