Raspberry Pi User Guide
Raspberry Pi User Guide
Operating Systems
Installation
Raspbian
10
16
OpenElec
20
Camera controller
22
Sending output
26
Minecraft Pi
30
Postscript
32
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.
3
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.
Its hardly surprising the hardware
alone is developed perfectly for the goals
of the Raspberry Pi Foundation, the
pricing is pitched perfectly, and having
the unique versatility of Linux as the
operating system seals the deal nicely.
Most buyers, once they get their hands
on their new RPi, make a move towards
the official Raspberry Pi site and follow the
getting started instructions therein; the
end result is the user running Raspbian
Wheezy, the Foundations recommended
OUR SELECTION
Raspbian
Risc OS
Arch
OpenELEC
Pidora
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-thebox), 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.
Raspbian
OpenElec
Arch Linux
Risc OS
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.
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
idea to grab the latest versions of all the
software by connecting your Pi to the
internet, opening a terminal and running:
sudo apt-get update
sudo apt-get upgrade
The killer feature of Raspbian is the
raspi-config program. This will start
automatically the first time you boot,
or can be run at any time by typing
sudo raspi-config in a terminal.
It has got quite a few options,
but the most important are:
www.element14.com/raspberrypiprojects
Overclocking
The processor at the heart of the
Raspberry Pi is designed to run at 900MHz.
That is, perform 900,000,000 operations
per second. Of course, designed to
run doesnt mean has to run. You can
increase this speed. However, doing this
will increase the power consumption,
which in turn increases the amount of heat
generated. If it gets too hot, youre liable to
have a smoking pile of silicon rather than a
functional processor.
Fortunately, Raspbian includes a tool to
help you ramp up the speed while also
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.
Overclocking will
increase the amount
of power that your Pi
draws, and so may
become less stable if
running a number of
USB devices.
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
tasks in this interface. Theres a file
manager, web browser, text editor and
many other useful applications. However,
sometimes you need an interface thats a
bit more powerful, and this is where the
command line interface (CLI) comes in.
Its also known as the terminal or shell.
LXTerminal running
on the Raspbian
desktop.
10
Interactive programs
Most of the commands were dealing with
here are non-interactive. That means you
set them running and then wait for them
to finish. However, not all command line
programs work like this. For example, when
you first booted Raspbian, it started a config
tool that ran in the terminal. There are a few
other programs that work in a similar way.
Traditionally, the most common has been
text editors that allow you to work on files
if you dont have a graphical connection.
11
-l
use a long listing format
The second way of finding information on
a command is using man. This is short for
manual. It takes a single argument, that is, a
word after the command that isnt preceded
by a hyphen. It then displays information on
Tab completion
You can even watch movies in the command line. To stream the classic,
just enter telnet towel.blinkenlights.nl and put somepopcorn on.
12
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
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
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
the more powerful features yet. The first of them are
wildcards. These are characters that you can put in that
match different characters. This sounds a bit confusing,
so were going to introduce it with some examples.
First, well create a new directory, move into it and create
a few empty files (we use the command touch, which
creates an empty file with the name of each argument).
Hint you can use tab completion to avoid having
to retype long names, such as in the second line.
mkdir wildcards
cd wildcards
touch one two three four
touch one.txt two.txt three.txt four.txt
ls *
This isnt particularly useful, but we can put it in
the middle of other characters. What do you think
*.txt will match? Have a think, then run:
ls *.txt
ls [!ot]*
What difference did the exclamation mark
make? It should have returned everything that
didnt start with a lower-case letter O or T.
sudo
When using the Raspberry Pi for normal use,
you can work with files in your home directory
(for example, /home/pi). You will also be able
to view most other files on the system, but you
wont be able to change them. You also wont
be able to install software. This is because Linux
has a permissions system that prevents ordinary
users from changing system-wide settings. This is
great for preventing you from accidentally breaking
14
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
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,
it doesnt usually). Instead, there is a part of
the operating system called the package
manager. This is responsible for getting
and managing any software you need. It
links to a repository of software so it can
download all the files for you. Since Linux
is built on open source software, almost
everything you will need is in the repositories
and free. You dont need to worry about
finding the install files, or anything like that
the package manager does it all for you.
16
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.
18
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
in different ways, but usually, the following
will work. Get the source code from the
projects website, and unzip it. Usually,
the filename will end in .tar.gz or .tgz. If
this is the case, you can unzip itwith:
tar zxvf <filename>
If the filename ends in .tar.bzip2, you need
to replace zxvf with xjf. This should
now create a new directory which you
need to cd into. Hopefully, therell be a
file called INSTALL, which you can read
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.
19
OpenElec
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
the fact that it runs silently, makes it a good
choice for building your own entertainment
center. You could start from Raspbian and
customize it to your needs, and this is a
good idea if you have any unusual functions
in mind. Fortunately for us (and you), a team
of hackers have done all the difficult bits of
building a media center for the Raspberry
Pi, and packaged it for you to use. Follow
the guide on page 6 to install the OpenElec
operating system from the NOOBS image.
This uses the popular XBMC media desktop,
which is quite different from LXDE, which
The Pi 2 Model B
boards have mounting
holes to help you keep
your entertainment
center tidied away.
20
Taking it further
It is possible to take complete control of your TV
viewing using Linux, including watching live TV, and
recording shows for later. This can be done using
MythTV (available from www.mythtv.org). Youll
need a separate computer with the appropriate
cable connections to act as the server.
You can play video files that you have stored on other
computers on your network, for example those on
a Network Attached Storage (NAS) box. The exact
method for doing this will vary depending on how you
share the files, but they are configured through the
Add Sources buttons. For more information about
this, you should check out the wiki at: bit.ly/OOvXb6.
21
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
embedded devices obviously have some
form of controller already but it means we
can script and extend them in ways that
arent possible (or are, at least, very difficult)
without the extra device. Almost anything
that you can plug in to a normal desktop
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
Powering your Pi
The Raspberry Pi gets power from its
micro USB port. This supplies 5V, and the
Raspberry Pi foundation recommends an
available current of at least 1A.
This can easily be delivered via a
mains adaptor, or a USB cable from a
computer. If you want your Raspberry Pi
to be portable, however, there are
23
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
for the drive. This is just a folder, and can
be put anywhere were going to spurn
convention and put it in our home folder.
So before running the script, run:
mkdir /home/pi/pic_mount
With this done, were ready to go. The script
to mount the drive and get the photos is:
#!/bin/bash
if mount /dev/sda1
/home/pi/pic_mount ; then
echo "Partition mounted"
cd /home/pi/pic_mount
yes 'n' | gphoto2 -auto-detect --get-all-files
umount /dev/sda1
else
echo "/dev/sda1 could not
be mounted"
fi
24
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,
you could upload them to an online
service, such as Flickr. See the box on
networking below for information on
how to connect your Pi to your phone.
You could include some sort of switch to tell
your Pi which photos to upload, and which
to store on the USB stick for example,
upload low-resolution images, and store
high-res ones. Or you could create lowresolution versions of the images, and
Networking
The Raspberry Pi comes with a wired
Ethernet connection, which is fine for
most occasions, but sometimes the
cable just wont reach. You could use a
USB wireless dongle however, if youve
got an Android phone, and your carrier
hasnt disabled the feature, you can use
this as your networking device. This has
an extra advantage of not drawing as
much power from the Pi, and so makes
it easier when running from batteries.
You should be able to share your
phones connection to Wi-Fi as well
as 3G, so it wont necessarily eat into
your data allowance. Of course, its
best to check the connection type
before downloading large files.
To do this, connect your phone to your
Pi, and enable tethering in Settings >
Wireless and Networks > Tethering and
Portable Hotspots (on the phone). Back
25
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
it can be hard to know whats going on
inside your Pi without a screen. Fortunately,
the designers of the Pi thought of this
problem and have added the facility to get
information on and off a Pi without the bulk
of usual PC peripherals. This is done via
General Purpose Input and Output (GPIO).
You may have wondered what the spiky
pins near the SD card reader are for well,
youre about to find out. This basic circuit
26
PIN PIN
Figure 2. Connect
the bread board to
these pins. Weused
commerciallyavailable single-pin
connectors, but you
could also solder
connectors on, or use
an oldIDE cable.
27
bit=1
for x in $pins
do
out=`echo $paddedBinary | cut
-b$bit`
gpio -g write $x $out
bit=$((bit+1))
done
And, finally, we tell the script to sleep for
five minutes, then turn the LEDs off.
sleep 5m
for x in $pins
do
gpio -g write $x 0
done
Thats it! Save this into a file called
showIP.sh, make it executable with:
chmod a+x showIP.sh
and type sudo ./showIP.sh to display
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.
28
Ohms Law
There are two key ways of measuring
electricity: voltage and current. Voltage
(measured in volts) is the amount of
energy a given quantity of electrons has,
while current (measured in amps) is the
amount of electrons flowing past a point.
The two are intimately connected by
Ohms law which states: Voltage =
Current x Resistance, or V=IR. You can
use this connection to make sure you
dont accidentally toast your Raspberry
Pi by pushing too much current into
it. The exact setup of the Pi is a little
complex. If you wish to delve into it,
Gert van Loo (one of the designers)
has put together an explanation, which
can be found at: bit.ly/Qp4PMl
29
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
is smaller and faster as well as containing
support for multiple programming
languages. Minecraft Pi runs on the
Raspbian Operating System for the PI. This
is the most common operating system
used on the Pi.
Minecraft Pi is now loaded directly with the
LX desktop, no messing around with
downloads or installation files. Click on the
Menu icon and then head down to
Games and over to Minecraft Pi. At this
point you can play Minecraft as a single
user or over a local network.
30
Minecraft Pi.
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
windows open. If not then click on the LX
Terminal window again to open a command
line prompt. To do this you will need to
press escape to pause the game and allow
you to move the mouse out of the game
window. You can then launch another
terminal from the desktop. One way is to
have the programming terminal window
and the Minecraft Window side by side
Once you have your terminal launched
you need to go to the Python API
directory (programming tools) by typing
the following at the terminal window:
cd mcpi/api/python/mcpi
and then:
python
and pressing return.
Your terminal prompt should change to >>>.
Now we are ready to start programming.
The first thing we need to do is to
import the Minecraft library.
At the command prompt in the
terminal windows type:
import minecraft
Now we need to initialize it which will
create a connection to your game
and allow you to start modifying
the game world. So now type:
mc = minecraft.Minecraft.create()
You can now use the mc object you
have created to control the world. Lets
say hello to your Minecraft world:
So type at the terminal window:
mc.postToChat("Hello Minecraft
World!")
You should then see your message
come up on the chat window in your
game. Feel free to change this message
to what ever you want. You can use the
postToChat method to post all sorts of
information you want the player to see.
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
most of the kids applying were coming
to interview as experienced hobbyist
programmers, the landscape in the 2000s
was very different; a typical applicant
might only have done a little web design.
The project started to look very realizable.
Eben (now a chip architect at Broadcom),
Rob, Jack and Alan, teamed up with
More information
For more information about your Pi, the
following links are the best places to start
32
www.element14/raspberrypi
www.raspberrypi.org
www.mcmelectronics.com
www.cpc.farnell.com/raspberrypi
www.element14.com/raspberrypiprojects
cd
ls
cp
wget
df -h
pwd
Finding files
33
Remote working
ssh
scp
Wildcards
[abc]
Matches a, b or c.
[!abc]
[A-Z]
[A-z]
[one, two]
top
Displays the programs that are currently using the most CPU
time and memory.
uname
lscpu
dmesg
34
Text files
head
less
cat
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
Special keys
[Ctrl]+[C]
[Ctrl]+[D]
[Ctrl]+[Shift]+[C]
[Ctrl]+[Shift]+[V]
Installing software
make
make install
(needs sudo)
apt-get
apt-cache search
<keyword>
35
www.element14.com