0% found this document useful (0 votes)
116 views16 pages

Raspberry Pi Pages From Computer Shopper 2015-02

The document provides a complete guide to using a Raspberry Pi computer. It discusses the key components of the Pi including the ARM processor, RAM, SD card storage, HDMI and USB ports. It also covers setting up the Pi by installing the Raspbian operating system and connecting peripherals. Projects that can be built with the Pi include a media center, network attached storage, and playing games.

Uploaded by

Carlos Anichela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views16 pages

Raspberry Pi Pages From Computer Shopper 2015-02

The document provides a complete guide to using a Raspberry Pi computer. It discusses the key components of the Pi including the ARM processor, RAM, SD card storage, HDMI and USB ports. It also covers setting up the Pi by installing the Raspbian operating system and connecting peripherals. Projects that can be built with the Pi include a media center, network attached storage, and playing games.

Uploaded by

Carlos Anichela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Worldmags.

net
Raspberry Pi
Recipe
Take one very small computer Take a dollop of code
Garnish with inexpensive peripherals Add a dash of ingenuity
Stuff with a light, zingy Baste it on liberally, and make
operating system something truly unique
Set aside to rise overnight

Select two or three rm projects


Slice into easily digestible steps
Arrange within Pi
Enjoy results with family
and friends
Now for the tricky bit

Ultimate guide to
Raspberry Pi
It can be used as a media centre, a NAS device and
even for playing games yet costs less than 30.
Shopper presents its complete guide to a life of Pi
aspberry Pi computers were originally conceived diminutive size, low price and unglamorous appearance,
to inspire young programmers to hone their however, the Pi is a fully functional computer. Lets take a
coding talents and earn themselves a place on closer look at the Pis component parts and nd out what
the computing degree course at Cambridge kinds of task its capable of.
University. But when word got out about a tiny
sub-30 computer anyone could buy and write The brains
programs for, suddenly everyone wanted to get their hands A single chip contains the Pis memory, central processing unit
on a slice of Pi. and graphics chip. The Raspberry Pi uses a chip designed by
When your Raspberry Pi arrives, the rst thing youll notice ARM, the same Cambridge-based company that designs
is that its very different to the type of computer you might be processors used in many smartphones and tablets. The version
used to. For starters, its tiny the size of a pack of cards. It used in the Pi is slower than youll nd in devices such as the
also has no case; its simply a printed circuit board. Despite its iPad, but its fast enough to do the job.
Worldmags.net

The newest Model


B+ has four USB ports for
adding multiple peripherals

Unlike the relatively pedestrian CPU, the Graphics


Processing Unit on the Pi is equivalent to that in a high-
specication mobile device. It can run 3D games and play
high-denition video (indeed, one of the most common uses for
the Pi is as a very cheap media centre). With the right software,
a TV and a broadband link you can have iPlayer, YouTube and
other internet video services at your ngertips.
The Pi comes with 512MB of RAM, which is plenty for the
projects in this guide. It also comes with an SD or microSD card Just like a PC, the Pis OS has a user-friendly, graphical interface
slot the same as that used by many digital cameras which
takes the place of the hard disk found in most laptops. Programs computer monitor. HDMI carries both pictures and sound, so if
are stored on the SD card and, once the Pi is powered on, these you use a monitor without built-in speakers, you may need to
are copied into the much faster RAM until the computer is plug a set of speakers into the stereo audio jack. If your monitor
turned off, at which point the RAM is cleared. One of the most doesnt have an HDMI socket, you can buy a cheap adaptor to
convenient aspects of the Pi is that you can transform it from a convert HDMI to DVI. Its even possible to connect a VGA-only
media player to a desktop computer simply by swapping out the monitor with an adaptor and a bit of wrangling.
SD card, which is easier than removing a laptops hard disk! On the older Model B, you can use an RCA video jack to
connect to the composite video input on an old-fashioned
Sound and vision CRT TV. However, this was added mainly to allow the Pi to be
One of the design requirements for the Raspberry Pi was that it used in the developing world, where TVs are more common
should be easy to hook up to existing equipment, so the latest than monitors, and the picture quality over composite is poor.
model includes an HDMI port for connecting to a TV or
Connections
The current Raspberry Pi Model B+ has four USB ports that you
You can transform the Pi from can use to connect a keyboard, mouse, Wi-Fi dongle or any
compatible peripheral. The slightly older but still very common
a media player to a desktop Model B has only two USB ports, so you may want to use a
powered USB hub to attach more devices.
computer simply by swapping You can connect either the B or B+ directly to your router or
a wired network via the standard Ethernet port this gives the
out the SD card fastest and most reliable connection to the internet. Note that

Where can I get a Pi?


If you havent yet got a Raspberry Pi computer, head to CPC
(http://cpc.farnell.com) or RS (http://uk.rs-online.com) to buy one.
You can also buy a Pi through Amazon. Prices uctuate, but you
should be able to pick up the latest Raspberry Pi Model B+ for
around 25 including delivery.
Youll also notice thats theres a 17 Raspberry Pi Model A+
available. This cheaper model has just 256MB RAM, compared to
512MB on the Model B+. Both use the same 700MHz Broadcom
SoC (system on a chip). However, the Model A+ has a single USB
port and doesnt have an Ethernet port, so youll need to plug in a
USB Wi-Fi dongle to get online. If at all possible we highly
recommend nding the extra cash to buy the Model B+ or shop
around to pick up a second-hand Model B, which only has two USB
ports but still has the network port.
In addition to the Pi itself, youll need a few other accessories
before you can get started. Head to page 107 to nd out what
youll need, together with some important tips. CPC is one of the ocial suppliers of the Raspberry Pi in the UK

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 105


Worldmags.net
the cheaper Model A and A+ variants lack the all-important The
h software
Th
network port. Theyre great for educational purposes, but There wouldnt be much point in a cheap computer if you
The
wed avoid these models for home projects. had to install an expensive OS on it (such as Windows
or Mac OS X) to get it to work. This, and the fact that
Pins and needles no version of Windows or OS X will work on the ARM
So far, everything weve described (apart from the SD chip in the Pi, means that the various OSes created for
card slot) is pretty standard to all computers. However, it are all based on the free and open-source Linux OS.
the Pi has some extra capabilities not found on your The Raspberry Pi Foundation recommends Raspbian,
common or garden laptop. The most important of these are avversion of the popular Debian Linux distribution. If this
the General Purpose Input Output (GPIO) pins, which offer sounds like gobbledygook, dont worry if youve used
various ways to control devices and receive input from sensors Windows, youll nd Raspbian pretty familiar.
and suchlike. However, misusing these pins can bake your Pi, so You can even install Linux versions of many of the programs
its best to use one of the many add-on boards that allow you youre familiar with, including LibreOce for Microsoft-
to experiment safely. We cover some of these options later on. compatible word processing and spreadsheet work, and even
The Pi also includes a connector for a camera module and the Chrome browser. Well explain how to add software of all
a DSI connector for connecting the Pi to certain specialist kinds from page 111. But before you do that youll need to install
displays such as mobile phone screens. Raspbian on your Pi rst. Head to page 108 to nd out how.

Pi ingredients
2x or 4x USB

Ethernet

Stereo audio jack

Camera
connector

RCA video
(A and B models) HDMI

512MB RAM,
CPU & GPU

GPIO pins

DSI connector

SD or microSD Micro USB power connector


card (model B+)
Worldmags.net
What do I need?
A
lthough the Raspberry Pi is cheap, the barebones circuit
board comes without many of the basic bits and pieces
needed to turn it into a usable computer. While adding
these can cost money, in many cases you can use spare kit that
you have lying around, or pick things up second-hand.
Here well explain the must-have items, and some optional
accessories that can make the Raspberry Pi experience even
more fun. Most accessories mentioned here are widely available
and http://cpc.farnell.com, one the ocial UK sellers, even sells
kits with bundled peripherals under the U:Create brand.

Storage
As the Raspberry Pi has no built-in storage, the most important
extra you will need is an SD card or, if you have a model B+, a The older A can be solved by using a powered USB hub instead (see below).
microSD card. This stores the operating system along with your and B models CPC sells a basic wireless desktop set for 18 including VAT.
own les and projects. It must be at least 4GB in size and have composite
preferably a Class 4 speed grade or higher. The bigger the video outputs Display
capacity, the more room youll have for your own stuff. Cards for connecting The Pi has two display connectors: HDMI and, on the old Model
to old CRT TVs
up to 32GB are supported; anything larger than that needs A and B, composite video. For best results, use an HDMI cable
some advanced tinkering to make it work. Cards are often (just over 1 on Amazon). Most HD TVs and some newer PC
bundled with the Pi itself for a couple of pounds extra, but a monitors have HDMI, but some older monitors have only DVI or
new 4GB SD or microSD card normally costs under 7. Always VGA connectors. An HDMI-to-DVI cable costs around 5. If you
buy branded cards from a reputable store to avoid fakes. already have an HDMI cable, a DVI adaptor is a little cheaper.
As the operating system is entirely contained on the SD HDMI-to-VGA converters are more expensive at around 18, but
card, theres nothing to stop you putting it on several cards and still cheaper than a new monitor. Composite video cables
swapping them as needed; for example, you could have one costing less than 1 can be used with older CRT TVs.
card for programming projects and another congured to use
your Raspberry Pi as a media player (see page 114).
Experienced users can connect USB hard disks or USB ash You can put the operating
drives to add more storage later if needed, but these storage
devices cant easily be used for the OS, as the Pi can only start
system on several SD cards
from an SD card. Well be considering USB storage on page 113.
and swap them as needed
Power supply
The Pi gets its power from a separate Micro USB power Audio
adaptor, which can be bought very cheaply (CPC sells one for The stereo minijack audio output on the Pi can be connected to
3.54). However, if you have a mobile phone charger with a headphones, powered speakers or a standard hi- system. A
Micro USB connector you might be able to use that instead. 3.5mm minijack to dual-phono cable costing about 1 might be
The only requirement is that the power supply can supply needed if the hi- has phono (also called RCA) connectors. If
ve volts and least 700 milliamps (mA) of current. Check the you use HDMI to connect to a TV (or a monitor with built-in
label on the power supply and look for the Output gures. It speakers), a separate audio cable isnt needed.
should say 5V and the milliamp rating; it doesnt matter how
large the milliamp number is, as long as its over 700mA. The Networking
more power your supply has, the less likely you are to have To connect the Pi to the internet, a wired or Wi-Fi network
problems with USB devices. connection to your home router is needed. The Model B/B+ Pi
has a wired network port that takes a standard Ethernet
Keyboard and mouse network cable costing a couple of pounds. A USB Wi-Fi dongle
To get up and running, a USB keyboard and mouse are can also be used, and CPC sells a compatible Dynamode 11n
essential. Any model is suitable, and no software or drivers are The Pi can model for 7. If you already have a spare dongle its worth
needed. Wireless sets are a good choice, as they use only one be powered trying, but not all work. No software is needed as the drivers are
USB port. However, if the wireless adaptor takes too much by Micro USB included in the operating system. For the Model A/A+, youll
power, it can prevent the Pi from starting up. If this happens, it phone chargers need a USB hub to connect dongle, keyboard and mouse at the
same time. Head to page 112 to read more about using Wi-Fi.

Optional extras
One of the most useful accessories for your Pi is a powered
USB hub. This connects to one of the Pis USB ports and allows
several devices to be connected at once without draining power
from the Pi. Hubs typically have four or seven ports, and a
seven-port model from CPC costs just 10. Dont use
unpowered hubs, as they could overload the Pis power supply.
A great addition to any Pi is a case to protect the
components. A basic plastic case costs 5.39 from CPC and
is available in several colours. There are loads of other
exciting new accessories appearing all the time, including a
very cool Raspberry Pi camera board.

107
Worldmags.net
Install an operating system on your Pi
O
nce your tiny new computer arrives, you have a little work to use a special Windows program to burn an OS image to your SD card;
do before you can connect it to a display and boot it up, that option is still available should you wish to use it (see Steps 5 and
including installing an operating system the software that 6). However, the process of installing an operating system has been
provides an interface for the Pi and allows you to run other programs. now been made a whole lot simpler thanks to something called NOOBS.
The Raspberry Pi uses a standard SD card instead of the hard disk It stands for New Out Of Box Software and makes setting up your
youll nd in most laptops, and your rst job is to prepare the SD card Pi much simpler than before. Follow these steps to install the
and transfer a suitable operating system to it. Until recently, you had to recommended operating system Raspbian on your Pi.

01 The Pis Raspbian OS


runs from an SD card.
Programs you install will also be
02 Youll need to format the SD card rst. This will wipe the
cards contents, so make sure nothing you need is stored on it.
Windows has a built-in formatting tool, but the Raspberry Pi Foundation
stored and run from this card. recommends using the ocial SD Card Association Formatting Tool, as
You can use SD cards of up to this is capable of formatting the entire card. PC users can download this
32GB, but 4GB or 8GB is plenty. tool free of charge from www.snipca.com/9721. If youre on a Mac, an OS
You can buy an SD card with X version (also free) is at www.snipca.com/9722. Well assume youre
the Raspbian operating system using Windows. Download the SDFormatter4 Zip le to your desktop,
installed on it, such as the one at right-click it and select
www.snipca.com/9314. However, Extract All, then Extract.
this Kingston-branded card is only Double-click the Setup.exe
a Class 4 SD card and wont work with a Pi B+, which needs microSD. le in the extracted folder
We recommend buying a faster SD card (one with a higher class and follow the onscreen
number), such as a Class 10 model, and installing the free Raspbian instructions to install the
OS yourself. Youll need a Windows or Mac computer for this. If your SD Formatter tool.
computer doesnt have a built-in SD card slot, you may need to attach a
USB SD card reader. Many photo printers have built-in SD card readers.

04 Right-click the Zip le and select Extract All. In the dialog box,
click Browse, navigate to the SD card and click OK, Extract.

03 Insert your
SD card into
your PC, printer or
Use the Safely Remove Hardware tool (in the Windows Notication
Area) to eject the SD card and insert it into the Raspberry Pi. Set up the
Pi (see opposite) and switch it on. Your Pi will now boot into NOOBS
card reader and launch and should automatically display a list of operating systems you can
SD Formatter. Under install. If your screen is blank, you
Drive, make sure the can try manually selecting the
drive letter selected is correct display mode using the
the one for your SD number keys on your
card; pick the wrong keyboard. Tap 1 for
one and you could end HDMI mode, 2 for
up wiping another HDMI safe mode, 3
drive. Unplug any other external drives to be safe and double-check you for Composite PAL
have the correct drive selected by clicking Start, Computer. In SD (UK) mode and 4 for
Formatter, click Option and set Format Size Adjustment to On. Click OK Composite NTSC
then click Format and OK again twice. A summary will be displayed. (US) mode. Once
Click OK and close the formatting tool. Now go to www.snipca.com/9319 you see the NOOBS
and download the NOOBS Zip le, using the Direct Download option. dialog box, select
Its quite big (about 1GB) so it might take a while to transfer to your PC. Raspbian and click
Install OS.

05 We recommend that new users employ the NOOBS method,


as described above, but there is an alternative way of writing
the Raspbian OS image to an SD card using a utility called Win32 Disk 06 Go to www.raspberrypi.org/downloads and, under Operating
System Images, youll see a link for Raspian (the Debian
Imager. Format the SD card as described in steps 1 to 3. Then, on a Wheezy version is recommended for newcomers). Click the Download
Windows PC, go to www.snipca.com/9723 and download the most Zip link. Go to your Downloads folder, right-click and extract the Zip.
recent version of Win32 Disk Imager. Make sure you get the Binary There will be one le, with the extension IMG. Double-click the
(win32diskimager- Win32DiskImage.exe le
binary.zip), not the you extracted in Step 5.
source version. Go to Click the blue folder icon
your Downloads and use File open to nd
folder, right-click on the IMG le you extracted.
the Zip le and select Under Device, select your
Extract All. Youll SD card from the list, being
then be asked to pick careful to choose the correct
a folder into which drive letter for the SD card.
to copy the les the Once youve checked this,
Zip contains; do so, click Write to transfer the
then click Extract. image to the card.
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
Set up your Raspberry Pi and switch it on
I
f you followed the workshop opposite, you should have an SD card As the Pi is supplied as a bare circuit board, you should discharge
ready with your Raspberry Pis operating system installed. Now its static electricity before handling it, by touching an earthed metal object
time to look at the hardware side. Thankfully, this is straightforward. (such as a radiator) or wearing an anti-static wrist-strap.
In most cases, there is only a single place for each cable to go and little Were using a Model B, but well explain any differences for Model A.
chance of confusion with regards to what goes where. For more information on the cables required, refer back to page 107.

01 The SD card you prepared earlier slides


into a wide, black slot that
lies ush with the underside of the
02 The Raspberry Pi is designed to be connected to a television or
a computer monitor. There are two ways of connecting a Pi to
a TV: a digital connection via an HDMI cable (the same type of cable
Raspberry Pi. The card should be that the latest games consoles use) or analogue through a composite
inserted with the label facing away video cable (see Step 3). For the best image quality, use the HDMI
from the circuit board. The easiest connection by connecting an HDMI lead from the port on the bottom
way to insert the SD card is to ip of the Pi to your TV. You can connect to computer monitors that
the Pi on to its front, revealing the support HDMI in this
SD card slot. Push the SD card into way, too. In both cases,
the Pi with rm nger pressure. HDMI will also carry sound
When fully inserted, the top of the to the TV or monitors
card will be ush with the back of built-in speakers. If your
the slot, and the card itself will protrude from the edge of the Pi it monitor has a DVI input,
may look a little odd but this is how it should be. On the Pi B+, the youll need an HDMI-to-DVI
microSD card will spring into place against a spring. cable. Plug the DVI end
into the monitor, and the
HDMI end into the port on

03 If youre using an
older TV that lacks
HDMI, connect a composite
the bottom of the Pi.

video cable from the yellow


port on the top of the Pi to the
TVs yellow composite socket.
04 The Pi requires a keyboard and mouse that use USB
connections; most modern devices do. The Model B Pi
has two USB ports on its right-hand
If the TV lacks a composite side, and the B+ has four. Attach the
input but does have a Scart keyboard and mouse, checking that the
socket the wide, at USB connectors are the right way up
connector type used by older before pushing them in. Both the Pis
video recorders then full-size USB ports will now be occupied.
composite-to-Scart adaptors This doesnt matter in the short term,
can be purchased at most but connecting additional USB devices
electrical shops. If youre not later will require the purchase of a
connecting from HDMI to HDMI directly and you want to hear sound powered USB hub. Owners of Model A
through your TV speakers, you will also need an audio cable with a Raspberry Pi units will denitely need a
3.5mm jack and a pair of phono plugs. This should be connected to the hub, as this edition of the device only
black or light blue audio port on the top of the Pi, with the two plugs on has a single USB port. See page 107 for
the other end going into the TVs audio inputs or the Scart adaptor. more advice on USB hubs.

05 The PC will need a network connection in order to


provide access to the internet. The Pi doesnt have
built-in Wi-Fi connectivity, so this needs to be done using a
06 Finally, the Pi needs power from a mains adaptor using a Micro USB
cable. With all the cables connected, your Pi should look as shown
below. As soon as the Pi is connected to the power, it will switch on. Lots of
traditional Ethernet network cable strung between the Pi and a text will scroll up the screen. The Raspi-cong menu will appear; for now, these
router or modem. Push one end of the cable into the network settings can be safely ignored, so just press the Tab key on the keyboard until
port on the right-hand side of the Pi, making sure the small the Finish option is selected, then press Enter to leave the menu. A text screen
plastic lug is facing downwards. Once inserted far enough, the will appear asking for a username. For the Raspbian operating system we
plug should make an audible click and resist being pulled out installed opposite, this is simply pi so type in pi, press the Enter key, then
again. The other end of type raspberry as the password and press Enter again.
the cable should be
connected to a router,
ADSL modem or cable
modem. Its also possible
to add wireless network
facilities; this is
particularly useful for
owners of the Model A/
A+ Raspberry Pi, which
doesnt have an Ethernet
socket. See page 112 for
detailed instructions.

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 109


Worldmags.net
Configuring your Raspberry Pi
O
nce the Raspbian operating system is installed on the Pi (see the Pi run faster. Its a very easy program to use, and is essential for
page 108) and it boots up for the rst time, the rst thing it getting the best out of the Pi. Raspi-cong can also be run at any time
does is run a special program called raspi-cong. This lets you from the desktop or the command line. In this workshop well not only
congure many aspects of the Raspberry Pis software and hardware. explain how to do this, but well also walk you through each of the main
You can set the time zone, choose the correct keyboard and even make settings, explaining what they do and how to make the right choices.

01 After installing the Raspbian operating system, the Pi will


restart and after a few moments of text scrolling down the
screen, the raspi-cong program screen will appear. It only does this
02 The second
option allows
you to change the
automatically the rst time Raspbian starts, but raspi-cong can be default password
started at any time: from the command line, just type sudo raspi-cong; (raspberry), which is a
from the desktop, open the LXTerminal program and type the same good idea to help keep
command. Raspi-cong is a simple text menu with nine options. Use the the Pi secure. Select this option, press Enter, then press Enter again.
up and down arrow keys and the Tab key to navigate around the screen A command line appears asking for the new password. Type it, press
(the mouse doesnt work in this program). The rst option on the Enter, type it again and press Enter again. When successful you will be
screen, Expand Filesystem, isnt needed if you used the ocial NOOBS returned to the main menu. The third option down is Enable Boot to
package to install Raspbian. Desktop, which saves you having to start the graphical desktop
manually every time. Select this, press Enter, then choose Yes to go
straight to the Desktop, or No if you prefer to start from the command
line. Starting the Desktop from the command line is simply a matter of
typing startx and pressing Enter.

04 Option 5 on the main menu, Enable Camera, is only needed if


you have the Raspberry Pi camera module. We dont
recommend using Option 6, Add to Rastrack, as it just adds the Pis
location to an online database. The Overclock option is of interest to
those wanting to improve the Pis performance. Open this, press Enter
then choose an overclocking option. We recommend trying Modest
rst to see if it causes any problems. Trying the faster options will
make the Pi become hotter and may reduce its lifespan and cause
crashes, so dont use them if you leave the Pi turned on all the time.

03 If a key on your keyboard produces the wrong letter, x it with


Internationalisation Options. Select the option, press Enter,
select Change Locale and press Enter. Choose All locales from the list,
The fastest options will give you a noticeable boost in the Pis speed,
though. The Pi needs to be restarted before the changes take effect.

press OK, then Enter. Select OK on the next screen, press Enter and wait
until the main menu returns, and choose Time Zone. Select Europe
from the list, press Enter, select your nearest city and press Enter again.
Finally, to set the keyboard layout, open Internationalisation Options
again, choose Change Keyboard Layout then press Enter. Choose
Generic 105-key (Intl) PC, press Enter, then English (UK) and press
Enter again. On the next three screens, we recommend keeping the
default settings; press Enter until you return to the main menu.

06 The next option in the Advanced Options menu is SSH. This


stands for secure shell and is a way of accessing the Pis
command line remotely from another computer. Its enabled by default,
but can be disabled if you dont want to use it. The nal option is
Update, which updates the raspi-cong tool to the latest version. If your
version is out of date, simply select Update and press Enter. The tool

05 Advanced Options has several useful settings. Overscan is


needed only if you are connecting to a TV via the composite
video connector; it removes the black bars at the edges of the screen.
will automatically update itself and restart. An internet connection is
needed for this. When youre happy with all the changes youve made,
from the main raspi-cong menu select Finish then press Enter. The Pi
Hostname lets you change the Pis network name from the default of will reboot if any of the changes youve made require it.
raspberrypi. Open this, press Enter, then type the new name in the box.
Only standard letters and numbers can be used. Memory Split lets you
change the amount of memory used for graphics. In most cases you wont
need to change this, but if youre using the Pi as a media player or for
games you can boost performance by increasing this to 256MB. If youre
using your Pi without a display, you could reduce the gure to 16MB.
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
Find and install software
O
ne of the benets of any Linux-based system is the huge Rather than running a setup program, with Linux you use a package
library of free programs that are available. The process for manager, and in many cases this is done by typing in commands. Dont
nding and installing software for the Raspberry Pi is different panic, though its easier than it sounds. Here well show you how to
to its Windows equivalent, though. While the Raspberry Pi desktop looks use a package manager as well as how to install programs via the
supercially similar to Windows, underneath are many differences. terminal, because most online examples use this approach.

01 The Raspberry Pi
comes with a
basic range of software
02 Lets begin by installing Chromium. Double-click LXTerminal
and type sudo apt-get update followed by the Enter key.
This probably looks incomprehensible, so lets take it step by step.
built in. Similarly to The rst command, sudo, tells Linux you want to run the rest of the
Windows, theres a button command as a super-user. This is similar to the Administrator user in
in the bottom left-hand Windows; it gives permission to change the system, which can be
corner of the screen that dangerous if not used properly. Next, apt is short for Advanced
you can click in order to Packaging Tool and this is the program that installs our software.
see a launch menu of Get is the utility within apt that does this it gets packages.
programs and tools that Finally, update tells apt-get to download the latest list of packages:
are installed. In addition, you should always update apt-get before trying to install software.
each distribution of Linux comes with a library of optional software,
called Package Repositories. You can think of the initial setup as a
starting point, to which you can then add software from the
repositories to suit your purpose. For a general-purpose computer,
youd probably want to install an oce suite such as LibreOce (a
version of OpenOce), and the Chromium browser (the open-source
version of Google Chrome). In this case, were going to install Chromium
and then focus mainly on installing a programming editor.

03 Wait for the update to complete; the pi@raspberrypi prompt


will appear once its done. To install Chromium, type sudo
04 This is all very well, but how do you know what to install and
what the package name is? One way is to Google oce
software for Raspberry Pi, but another is to install a graphical package
apt-get install chromium and press Enter. This time weve told apt-get manager. In an LXTerminal window, type sudo apt-get install synaptic.
to install a named package. Your terminal window will ll with lines of This will download and install the Synaptic Package Manager. Once this
text explaining whats happening. You may be told how much disk space is done, nd it by clicking the Start button
the program will use up and be asked to conrm the installation. Type Y and choose Other. Click Synaptic and
and Enter to do so. youll be asked to type your password.
When its done, close Youll now see a window containing all
the LXTerminal the packages available for the Pi.
window. Chromium
will be available in the
Internet submenu of
the Start button. To
place an icon on the
desktop, right-click
on it in the submenu
and select Add to desktop.
The flip side
05 Were going to use Synaptic to install a code editor called
Geany. On the left side of the Synaptic window, scroll down to
the Development category. Now scroll through the right-hand window
If youre used to a snappy modern computer, using software such
as LibreOce on your Pi will feel like wading through treacle. Youll
notice a delay of a couple of seconds after you double-click an icon
until you nd Geany. In fact, you need to click the package geany- before the program launches, for example. This is partly because an
common rst, then select Mark for Installation, before doing the same SD card isnt as fast as a modern hard disk at reading les, and also
with the geany package. Once youve done this, click the Apply button reects the speed of the processor. Once your word processor has
to install it. This is straightforward, but remember the equivalent fully loaded, you should nd performance acceptable. Some games
command in the terminal would be sudo apt-get install geany, which is will work well on the Pi, too: 3D shoot-em-up Quake 3 (below) was
clearly much quicker. famously ported across very early on. But the Pi is not designed for
So, if you know the playing the latest high-end games, so it wont replace your Xbox.
package name, you
should use the
command line
approach; if you
want to browse,
choose Synaptic.
Why not give it a
go and install
LibreOce?

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 111


Worldmags.net
Set up Wi-Fi and print from your Pi
A
lthough the Model B Pi can connect to a network using a Edimax EW-7811UN is a good choice), and you can nd a complete list
standard Ethernet cable, upgrading to Wi-Fi makes it easier to at www.snipca.com/9740. In this guide well be explaining not only how
position your Pi wherever you like. And if you own a Model A, to set up Wi-Fi, but also how to connect your Pi to a printer. Were
Wi-Fi is your only choice, as theres no network socket. Fortunately, the connecting our printer via USB (you may need a USB hub for this) but
Pi supports a good selection of USB Wi-Fi adaptors out of the box (the these instructions will also work for printers on a home network.

01 To get started, turn off


your Raspberry Pi and
plug your Wi-Fi dongle into a
02 To print from your Pi
youll need to install
CUPS (Common Unix Printing
spare USB socket for the System). This software allows a
Model B this can be either computer running a version of
one of the two built-in ports. Linux, such as Raspbian, to
The Model A has only one USB support printers and act as a
socket, so youll need to print server for other
connect the dongle to a hub. computers. Before
Connect your HDMI cable, you install CUPS,
keyboard and mouse, insert check your printer is supported
your Raspbian SD card and boot up. Once the desktop has loaded, by going to www.openprinting.
double-click the Wi-Fi Cong icon and choose Manage Networks. org/printers and selecting your printers make and model, then clicking
Click Scan to see a list of wireless networks. Double-click your network the show this printer button. If your model is on the list, this page will
name to select it, then add your Wi-Fi password in the eld called provide some information that might be useful later, so bookmark it.
PSK and click Add to complete the setup. Your Raspberry Pi will now Connect your printer to your Pi and switch them both on. Double-click
automatically use that network each time you boot up. LXTerminal on the desktop; LXTerminal is similar to the command
prompt in Windows. Type sudo apt-get update, press Enter, then type
sudo apt-get install cups. The installation may take up to 30 minutes.

03 Once CUPS is
installed, add
the user pi (thats you)
to the group allowed
to access the printer.
04 Assuming your
printer is
connected via USB, you
To do this, type sudo should see your printer
usermod -a -G lpadmin listed on the Add Printer
pi and press Enter. page; you should also see
With CUPS all printer any other printers CUPS
management is done has discovered on your
via web pages, but none of the built-in home network. You might
browsers works well with CUPS, so were nd that the name CUPS suggests
going to install Iceweasel, the Raspbian version of Firefox. Do this by for your printer isnt exactly the
typing sudo apt-get install iceweasel into LXTerminal and pressing same as its model name; just check that it matches with the model
Enter. After installation, start Iceweasel by clicking the start button at name you came up with in step 2. Click the Continue button and, on the
the bottom left and selecting Internet. Bring up the CUPS pages by next page, you can add a location (for example spare bedroom). If you
typing 127.0.0.1:631 into the address bar that address is pointing at want other people on your home network to be able to access the
your Raspberry Pi. Now, click the Adding Printers and Classes link, type printer, click the Share This Printer tick box and click Continue.
the username pi and password raspberry into the pop-up box and
click the Login button. On the next screen, click Add Printer.

06 To check your printer is fully working, select the Maintenance


dropdown on the left and choose Print Test Page. A message

05 The correct model name should now show next to model on


the Add Printer page. If it doesnt, as in our case, then you may
have to do a little searching on Google to nd the nearest equivalent;
will appear to conrm the page has been sent to the printer, and youll
then see the list of print jobs with the current status. All being well,
youll also hear your printer re up be patient, however, as it can take
the older your printer, 30 seconds for the test page to start printing. Dont despair if you get
the more likely it is to an error message: sometimes this is an issue with the browser rather
be on this list already. than the printer itself. Check this by selecting File/Print from another
Click Add Printer and, application such as LeafPad. If this doesnt work, your best bet is to
on the next page, click try another printer driver. To do this, select the Administration menu
Set Default Options and choose Modify
and Continue. After Printer. You can
a brief message then walk through
conrming that the the steps you took
default options have to set the printer
been set, the printer up, looking for an
summary screen will alternative driver. If in
appear, conrming doubt, pick one that
that the printer mentions CUPS in its
is ready. driver name.
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
Add USB storage to your Pi
A
lthough the Raspberry Pi boots from an SD memory card, its same. However, although you can power ash drives from the
not a good idea to store documents, photos, videos and music Raspberry Pi, if you want to add an external hard disk, youll need
on such a card, as its relatively slow and has only limited space. to use a powered hub, or a hard disk with a separate power supply.
Fortunately, its easy to add USB storage, whether by using a ash drive You can also attach USB DVD drives to your Pi, although this is a
or an external USB hard disk. Either way, the process is exactly the slightly different process.

01 Were using a USB


ash drive like the one
shown, but the principles are
02 Double-click
LXTerminal,
type sudo blkid and
the same for adding an external press Enter. You should
USB hard disk too. Most USB ash now see a list of all
drives come preformatted with the attached drives. The
Windows FAT32 le system. This will work path name for your drive will start with /dev/sd so look for a line that
with the Raspberry Pi but its inecient and begins with those letters. Youll also get a clue from the label and the
easily corrupted, so the rst step is to reformat type; usually this will be vfat. Note the path name for your drive in
the drive using the Pis native EXT4 system. the screenshot above, the path is /dev/sdb1. Before you can format the
Begin by turning on your Raspberry Pi, then wait for the USB drive you need to unmount it so that the system cant access it
Raspbian desktop to load and plug in the USB drive. On a PC, during formatting. Type sudo umount followed by the path you noted
Windows assigns the drive a letter such as E: or F: but a Linux system, earlier. In our case, well use sudo umount /dev/sdb1.
such as the Raspberry Pi, uses mount points. These are full paths such
as /dev/sda1 rather than letters to indicate where a le is stored.

04 To give permission to all users to save to the disk, type sudo


chmod 777 /media/usbash followed by Enter. Open File

03 Were now ready


to format the
card. To do this, type sudo
Manager and select Places from the dropdown box in the left-hand
pane of File Manager. You should see your ash drive appear beneath
Applications. From now on, it will always be visible whenever its
mkfs.ext4 /dev/sdb1 L plugged into your Pi. You can now create new folders on the USB drive,
usbash (substituting the which you do in File Manager by selecting it from the list of places.
path if yours is different). Youll probably see a lost+found folder there; this is a system folder,
This creates a new le so dont interfere with it. Move your mouse over the white area and
system that will appear as right-click to launch the contextual menu. Hover over Create New item,
usbash in the select Folder and give it a name before clicking OK.
le explorer. We
now need to create a folder to link with the ash drive; its a good idea
to use the same name as the label youve given the drive. Create a
location for it by typing sudo mkdir /media/usbash. Press Enter and
then type sudo mount /dev/sdb1 /media/usbash to mount the drive,
again substituting the path to your ash drive.

05 Now we have a working external disk, we can use it to back up


les from the Pis SD card. This may be something you want
to do so that you can restore the les on your Pi in case something
goes wrong, or you might only back up when youre about to change
les or install new software. Either way, were going to use the simple
command-line program called rsync thats built into Raspbian, so you
dont need to install any new software. For a simple directory backup,
use the form at sudo rsync av [source folder] [destination folder].
Begin by checking the exact name of the USB disk to which youre
06 In our example, were copying a folder called python_games
to a directory called Backups on the ash drive. To do this,
we type sudo rsync av python_games /media/usbash_/Backups.
backing up by looking again in the le manager under Places. Click your The a (archive) parameter tells rsync to preserve all le information
ash drive and youll see the path appear at the top; this is the path you (such as which user it belongs to), and the v (verbose) parameter
must use. Note that in the screenshot, the Raspberry Pi has added an causes rsync to tell us exactly whats going on (you can leave this one
underscore to the end of the path, which must be included. out once youve got used to the process). Once youve pressed Enter,
rsync will copy over the les. Whats really clever is that rsync supports
differential copying, so it only copies les that have changed. If you
ran the exact same command again, it would check to see if any new
les have been added to the source folder and only proceed if it detects
any changes. So, if
you use your Pi for
writing documents or
editing photos, for
example, you can run
rsync periodically to
back up new les as
you add them.

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 113


Worldmags.net
Turn your Pi into a media centre
and watch BBC iPlayer
O
ne of the Raspberry Pis best features is the fact that the pre-congured version of XBMC called OpenELEC. This lets you play
hardware is capable of playing high-quality music and videos. media les in a TV-friendly interface, and you can even add the BBC
However, Raspbian doesnt have all the necessary software, so iPlayer app to stream your favourite shows. Here we explain the basics
a media centre application like XBMC is needed. You can install this of getting up and running with XBMC, how to connect to a network,
manually, but NOOBS makes it much easier, as it comes with a great install iPlayer and play les from a USB drive or via a Windows network.

01 To install XBMC, you need an SD card containing the latest


NOOBS installation package (see page 108). If Raspbian is
already installed on a card, you can either reinstall over the top of this
(all your les on the SD card will be deleted), or use a different card
with a fresh copy of NOOBS. In the latter case, just insert the card and
power on the Pi. To use an existing installation, power on the Pi while
pressing the Shift key. This launches the same menu you see when rst
installing, where you can choose which operating system to install.
Select OpenELEC, press Enter and wait for the install to complete.
Once its nished, press Enter to restart the Pi.

02 The OpenELEC interface works well with keyboard and


mouse, but sometimes the edges of the screen may be cut
off. To x this, use the right and left arrow keys (or push the mouse
pointer to the right or left edge of the screen) until the System
category is highlighted, then press Enter. Click System, click Video
Output, then click Video Calibration. Move the mouse into the top
If you have problems left corner of the screen, and click and drag the corner inwards until the
two blue lines t perfectly in the corner. Repeat for the bottom right
when using a Wi-Fi corner. Put the mouse in the centre of the screen, and if the blue
square looks rectangular, click and drag it until it is square (use a
connection, switching ruler to check). Press Esc three times to return to the main desktop.

to a wired connection
should fix them

03 To use the internet, the Pi needs to be connected to a


router. If using a wired (Ethernet) connection no
conguration is normally needed, and OpenELEC should
connect automatically. Wireless dongles need setting up, though.
Hover the mouse over the System category on the menu bar
(see Step 2), then click OpenElec. Click Network, then in the
section Network Technology, click the small up or down arrows
to choose WLAN. In the Network Interface section, choose
wlan0. Next click WLAN SSID, then type in the wireless network
name. Click Done. In WLAN Security, choose the correct security
type for your router (usually WPA/WPA2), then click WLAN
Passphrase to enter the wireless password. Click Done, then click
OK. After a few moments the connection should be made and a
small Wi-Fi icon will appear at the right end of the taskbar.
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
04 Now OpenELEC looks good
and is connected to a
network, its time to install the
BBCs iPlayer. Download the Zip
le from http://tinyurl.com/
openeleciplayer and copy it to a USB
ash drive (but dont unzip it). Plug
the USB key into the Pi. Click
Programs on the OpenELEC menu
bar. Click Get More, then click the
two dots (..) at the top of the left
panel, then click them again when
the second list appears on your
screen. Click Install from zip le,
then look for the USB drive in the
folder list in the right panel (ours is
called USB_KEY). Click this, then
navigate to the Zip le and click it to
automatically install the plug-in; it
should take only a few seconds.

05 To use iPlayer, click Videos on the


main desktop menu, then click
Video Add-Ons. Click iPlayer then choose
the content to watch from the list.
Watching live TV is supported, via the
Watch Live link, but remember that you
need a valid TV licence to do this. A good
reliable internet connection is needed for
an enjoyable experience, and if you have
problems when using a Wi-Fi connection,
switching to a wired connection should x
them. Moving the mouse while a video is
playing will bring up a menu at the bottom
of the screen with programme information
and all the standard playback controls. To
listen to live or catchup radio programmes,
from the desktop click Music, then Music
Add-Ons, then iPlayer. Not all radio
channels support the live streaming feature.

06 Media les can be stored on


the Pis SD card, on a USB
drive, or on shared network folders.
Head to page 113 for more about
adding USB storage to your
Raspberry Pi. Most popular audio and
video formats are supported, apart
from WMV and MPEG2 videos.
When playing music, the current
track is shown as a thumbnail above
the menu bar with play controls at
the right of the screen. To play les
from a USB drive or network location,
click the relevant category and choose
Files. USB drives should automatically
appear in this list. For networks, click
Add Source. Click Browse then
choose Windows Network (SMB)
to browse PCs on the network.
To connect to a PC via UPnP
streaming, choose UPnP Devices in
the Browse window, select the PC,
then click OK.

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 115


Worldmags.net
Play Minecraft on the Raspberry Pi
M
inecraft is more than just another game: it has become a The Pi version is free and doesnt include all the gameplay of the online
worldwide phenomenon, thanks to its winning combination of and desktop versions, but it does have something unique: you can
attractive graphics and open-ended, creative-led gameplay. At control what happens in the game using the Python programming
the beginning of 2014 the company behind Minecraft, Mojang, language. If you want a great way to get youngsters interested in
announced that it was making Minecraft available for the Raspberry Pi. programming, Minecraft will be the key.

01 Start LXTerminal
by clicking the
bottom left button,
02 You can do
more than
simply build structures
Accessories, then in Minecraft by
LXTerminal. Type cd ~, interacting with it
press Enter, then type using the Python
wget https://s3. programming language
amazonaws.com/assets. and whats called the
minecraft.net/pi/minecraft- Minecraft API. An API
pi-0.1.1.tar.gz, press Enter, is a set of programming tools; in this case these tools let you nd out
then type tar -zxvf whats happening in Minecraft and change it while the game is running.
minecraft-pi-0.1.1.tar.gz Press Esc in Minecraft so that the normal mouse cursor appears and
and Enter. This creates a move the Minecraft window off to the right. Now rearrange the
folder called mcpi containing Minecraft. To start it, type cd mcpi, press LXTerminal window so that it lls the left-hand space left by Minecraft.
Enter, then minecraft-pi and Enter. Now select Create new. Youll nd It will be a narrow window, but everything were going to do can either
yourself in a new Minecraft world. Press E to see a full list of items in wrap text or scroll backwards and forwards.
your inventory; click one to select it. Press the right mouse button to
place an item and left-click to destroy a block. Press Space once to
jump or twice quickly to enter the ying mode.
04 The next section of the program is where it actually starts.
Type if __name__ == "__main__": and press Enter twice.
Note that there are two

03 Create a folder to store your Minecraft programs and copy the


special API les from Minecraft. Return to the LXTerminal
window, type mkdir ~/minecraft-api and press Enter. Type cp r
underscores in each part of
the command. Python uses
tabs to understand how a
~/mcpi/api/python/mcpi ~/minecraft-api/minecraft, press Enter, then program is divided, so every
cd ~/minecraft-api and press Enter. Type nano minecraft-api-demo.py line following this must be
and press Enter to start the nano text editor and create a new le. preceded by at least one tab.
The rst part of the program is used to import the Minecraft The next command connects
commands and the ones used by Python to understand time, so we can our program to Minecraft.
use delays in between commands. Type import minecraft.minecraft as Press Tab once, then type
minecraft, press Enter, type import minecraft.block as block, press mc = minecraft.Minecraft.
Enter, type import time and press Enter twice more. create() and Enter. Save your
program by pressing Ctrl-O and Enter.
Create a message that will appear in
Minecraft by typing a tab then mc.postToChat("Hello World"). Press
Ctrl-O, Enter, then Ctrl-X to quit the text editor. Type python minecraft-
api-demo.py and press Enter. The message will appear in the Minecraft
window above the inventory list and then disappear after ten seconds.

05 Return to the LXTerminal window and type nano minecraft-


api-demo.py to load the program in nano. Use the cursor keys
to move down to the bottom of the le. In order to build a tower of 06 To create the tower as simply as possible, create a loop so you
will only need to enter the setBlock command once. All the
blocks near the player, we need to nd out where they are. Enter the commands inside the loop must be preceded with two tabs for Python
command playerPos = mc.player.getPos() below and in line with the to interpret it correctly. Press Tab once, then type for towerBlocks in
messages and press Enter. Press Tab again and then enter playerPos = [1, 2, 3, 4, 5]: and press Enter. Press Tab twice and then type mc.
minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z)) and setBlock(playerPos.x, playerPos.y + towerBlocks, playerPos.z +5, block.
press Enter. The second command converts the players position into DIAMOND_BLOCK). Press Ctrl-O and then Enter to save the program.
the correct type of data that Python can use. Press Ctrl-X to quit. Type python minecraft-api-demo.py and press
Enter to run the
program. It
doesnt know
which direction
youre facing so
you might need
to turn around
to see the tower
after the Hello
World message
appears.
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
Turn your Pi into a network storage drive
O
nce youve attached a USB drive or USB hard disk to your Pi If possible, connect your Raspberry Pi and its USB storage to the
(see page 113) you can use it as a network-attached storage network using Ethernet rather than Wi-Fi; this makes transferring les
(NAS) drive. The Pi can then be used to store digital photo faster and more reliable. Its also worth housing the Pi in a case or
albums, videos and music that everyone on the network can share, nding a case for it and its disk: just bear in mind that a hard disk needs
whether theyre using a Windows computer, Mac, tablet, phone or good ventilation. Site your new NAS as near to the router as possible
another Pi. Its a great way to keep important things easily accessible. and set it up so it wont need to be turned off once its up and running.

01 Samba is the
software
used to allow
02 We now
need to set
up Samba by editing
Windows machines its conguration les.
to communicate with In common with many
Linux computers Linux programs,
(including the Pi), theres no graphical
which use different user interface but you
le formats only have to set it up
including EXT4 which once. Were going to
we used for our USB use nano, one of the
drive on page 113. Raspberry Pis built-in text editors.
To install Samba, In LXTerminal, open the conguration le in nano by typing sudo
make sure your Pi nano /etc/samba/smb.conf. You use the keyboard rather than your
is connected to the internet and open LXTerminal. Type sudo apt-get mouse to edit les in nano, but its straightforward. Navigate through
update to make sure your system is up to date followed by sudo the le using the arrow keys until you reach a section called
apt-get install samba samba-common-bin. This process will take up to Authentication. We want to add some security to our network, so nd
30 minutes, depending on the speed of your broadband connection. the line # security = user and remove the hash symbol at the beginning
of the line. Hash is often used to tell computers not to pay attention; by
removing it were turning on user-level security and preventing people

03 Use the arrow keys to move down to the very bottom of


smb.conf and press the Enter key at the end to insert a new
line. Add these lines to the le, pressing Enter at the end of each:
who connect to your network as guests from having access.

[Share]
comment = Raspberry Pi Share
04 We need
to restart
Samba so that it reads
path = /media/usbash_/Share the conguration le
valid users = @users back in. To do this,
force group = users type sudo /etc/init.d/
create mask = 0660 samba restart.
directory mask = 0771 We now create a
read only = no Raspberry Pi user who
can access the share; were choosing the username networkuser and
Once youve done this, press password raspberry. It will be these details that people using other
Ctrl-O to save the le, then Enter computers to connect to your USB drive will be asked for. To do this,
to conrm. Press Ctrl-X to exit type sudo useradd networkuser m G users and Enter followed by
nano and youll return to the sudo passwd networkuser. After pressing Enter, the Pi will ask you to
command prompt in LXTerminal. set a password. Make sure you write this down as you and all your
NAS drives other users will need it.

05 We need to add this new user to Sambas list of authorised


people. Type sudo smbpasswd a networkuser and enter the
password when prompted. Finally, were going to set the permissions on 06 To make
the shared
the share folder so that anyone on the network can add, edit or delete folder easy to use, we
les. To do this, use the chmod command followed by the permission assign it a drive letter
and the name of the folder. Type chmod 777 /media/usbash_/Share in Windows so that it
followed by Enter. Now appears like a disk
start Windows Explorer drive. In Windows
on a PC and you should Explorer, right-click
see Raspberry Pi on the the Raspberry Pis
list of devices. Double- Share folder and
click it to see the Share select Map Network
folder. Try to open it and Drive from the menu.
you should be prompted Choose a drive letter from the dropdown menu; its probably a good
for a username and idea to pick a high letter so its clear which are true disk drives and
password. Once youve which are network storage. Leave the Reconnect at logon tick box
entered these, you can selected and click Finish. After a few seconds, the NAS will appear in
drag and drop les. alphabetical position under Computer on your Windows PC.

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 117


Worldmags.net
Use Scratch to program a game
T
he little Raspberry Pi computer has led to a resurgence
of interest in the more technical aspects of computing,
including programming. However, the challenge with
many programming languages is that they dont always offer
the quick gratication needed to keep novices interested.
However, a free tool called Scratch takes a different
approach by offering an engaging experience from the start.
Programs are created simply by dragging and dropping
elements around onscreen. A complete novice can create a
working program quickly, and projects can be shared with other
users on the Scratch website. So, to learn how to program a
game in just 15 minutes, read on.

Understanding the interface


Scratch comes built into the Raspberry Pis Raspbian operating
system. Youll nd a shortcut for it on your Pis desktop. A
Windows version is also available to download for free from
http://scratch.mit.edu/scratch_1.4. Wed also suggest signing up
for a Scratch account. This is free, and will allow you to share
your work with other people. Visit http://scratch.mit.edu and
click the Signup link at the top of the web page. Fill in the
registration form and the blue sign up button at the bottom.
Your Scratch prole page will appear; well return here later.
Flip back to the Scratch program window. There are several
panes; the window in the top-right corner, with the picture of a
cat, is the stage, and this is where the results of the program
will appear. It also controls the starting and stopping of
programs, with the green ag and red dot respectively.
Objects on the stage, such as the cat, are known as sprites
and are listed in the pane below the stage; the cat is named Scratch is a command into the scripts pane. Place it near the top-left corner
Sprite1. Here you add new sprites and change their properties. great way to but dont worry too much about its precise position.
start learning
The tall pane to the left-hand side of the stage is known Now click the Looks category button and nd the say
about computer
as the scripts area; this is where the programming code is Hello! For 2 secs command drag the rst (orange) command
programming,
developed and shaped. Programming essentially involves on Raspberry Pi
into the scripts pane. As you do, notice how a white line
creating a series of commands in order to control something: or Windows appears below the orange command; this indicates that the
sprites on the stage, in this case. A complete series of command being dragged can naturally follow the existing
commands is known as a script. command. Now drop the new command below the existing one
Scratchs commands are arranged into eight different and the two will snap together. Indeed, examine the command
categories, which can be selected by clicking one of the eight icons and youll see they are shaped a bit like puzzle pieces;
labelled buttons in the top left-hand corner of the Scratch commands that t together can work together.
program window. Scripts are created by dragging items from Remarkably, you have already created some working
the commands pane into the scripts area. computer code. To try it, click the green ag icon above the
stage to start the program. A Hello! speech bubble will appear
Programming primer above the cat for a couple of seconds, and then disappear.
First, click the Control button in the top left corner and the Now examine the edging script to consider what is going on.
commands pane will ll with command icons, coloured orange. The two commands read when [green ag icon] clicked and
To start, drag and drop the when [green ag icon] clicked say Hello! For 2 secs, and thats precisely what has happened.

Creating a game
Beyond Scratch
Lets make a simple game of chase in Scratch. The player will
control the cat sprite in an effort to try to reach a snowman,
while avoiding a ball that moves across the stage. Well create
Scratch has the potential for creating some fairly sophisticated programs. the program so that the two characters appear in opposing
For example, it makes it easy to perform several tasks simultaneously, which corners at the beginning of the game, and apply random
can be quite tricky with traditional coding methods. movement to the ball.
However, if you want to develop your skills then at some point it will Create a new script by selecting New from the File menu
become necessary to move to a more traditional programming language. and click No when asked if you want to save your work.
Small Basic (http://smallbasic.com) is a good one to try. The next step up is Drag and drop the when [green ag icon] clicked command
Visual Studio. Microsoft produces a free version called Visual Studio Express into the scripts pane. Now select the Motion category and
(www.snipca.com/9818). Although some handwritten code is required, its drag the go to x:[X] y:[X] and the point in direction [X] icons
also possible to design programs by dragging and dropping commands in a to join them to the rst command. Click in the x: box and type
similar way to Scratch. Another good choice is Game Maker Studio (www. -182 as the new value, and set y: to -112.
yoyogames.com/studio). The best way, however, would be to try Python To make the cat react to the cursor (arrow) keys, return to
(www.python.org), which is a simple, free programming language thats the Control category and drag when [X] key pressed to the
ideally suited to your Raspberry Pi. scripts pane; this wont join up with the previous three
commands. Click this commands down-pointing arrow and
ULTIMATE GUIDE TO RASPBERRY PI
Worldmags.net
command into the scripts area, followed by a go to x:[X] y:[X]
Motion command. Change x: to 178 and y: to 106.
To make the snowman move, add a forever loop and then a
repeat loop within that. From the Operators category, drag a
pick random [X] to [X] command into the number eld in the
repeat command, and change the [X] values to 1 and 5. Below
this, attach a move [X] steps] command (from the Motion
category) and another pick random [X] to [X] command to the
move command, setting the [X] values to 5 and 15.
Drag a point towards [X] Motion command so that it
appears underneath the repeat loop but still inside the
forever loop. Click on the down-pointing arrow and
choose Sprite1. Now insert a turn [X] degrees command
underneath this. Drag a pick random [X] to [X] Operator
command into the turn [X] degree commands number eld
and set the values to -90 and 90. This is to make the ball
travel in the general direction of the cat but with some
randomness, so the game isnt impossible.
Finally, the ball needs to know whether or not it has
touched the cat. Insert an if command after the turn [X]
degrees command, but still within the forever loop. From the
Sensing category, drag a touching [X] ? command into the if
In Scratch,
choose up arrow for the [X] value. Return to the Motion commands gap, choosing Sprite1 as the [X] value. Add a say
you can build up
category. Drag both the point in direction [X] and the move command from the Looks category and change the text to
a program just
[X] steps commands to join up with the second orange by dragging and
read Got You!. Add a stop all [red circle icon] after this say
command. Click the down-pointing arrow to ensure that the dropping command to end the game.
point in direction [X] value is set to 0 (up). For move [X] If you ran the program now (by clicking the green ag icon)
steps, the [X] value should be 10. youd discover the ball moves too fast. This can be xed by
Click Control and drag another when [X] key pressed adding a wait command (from the Control category) to the
command to the scripts pane, choosing down arrow for [X]. very end, but still within the forever loop. Set it to 0.2 seconds.
Add point in direction [X] and the move [X] steps commands
as before, changing the rst [X] value to 180. Repeat twice
more, for the left and right arrows, using -90 for the left arrow Scripts are created by dragging
items from the commands pane
[X] value and 90 for the right arrow.
Click the green ag icon to check your work. Tapping the
arrow keys should now allow you to control the cat.
into the scripts area
Adding the snowman
To add a new sprite, click the middle star-shaped icon under Now run the program. The ball will move and the cat will
the stage. In the New Sprite dialog box, click the Costumes respond to direction commands from the cursor (arrow) keys.
button on the left and then double-click the Fantasy folder. Try to get to the snowman without being touched by the ball.
Scroll down to nd and double-click on snowman2 and he will If somethings wrong, check the code carefully or download
appear in the stage. Double-click on the snowman to make him the completed program from www.snipca.com/7950.
the subject of scripts pane. As before, add a when [green ag
icon] clicked command. Then join a forever command beneath Save and share
it, followed by an if command inside that. The forever Save your work often. Type a name at the bottom of the
command grows to allow if to t inside. window. If youre planning to share your creation, add your
We have now created a loop. Loops are used to repeat It wont be
name in the Project author box and a description in the About
actions either endlessly, or based on a particular condition that long before this project box, then click OK.
will be checked by the if command. youve created To share the program with other people using your Scratch
We need the if command to check whether or not the cat a simple script account, click the orange icon. Enter your Scratch login details
has touched the snowman. Click to select the Sensing category using Scratch and some information about the program, then click OK.
and drag the diamond-shaped touching [X] ? command into
the diamond-shaped depression inside the if command.
Click the down-pointing arrow to change the touching [X] ?
commands [X] value to Sprite1 this is the cats sprite.
Select the Looks category and drag and drop the say Hello!
command inside the if loop. Double-click the Hello! text,
delete it and replace it by typing You Win!. Return to the
Control category and drag and drop a stop all [red circle icon]
command (you may need to scroll down the commands list to
nd it) below the say command. This will end the game when
the cat sprite touches the snowman.

Adding the ball


Click the middle star-shaped icon under the stage. Click
Costumes then double-click Things followed by beachball1.
Double-click the ball in the stage to make it the focus of the
script area. Drag a when [green ag icon] clicked Control

ISSUE 324 | COMPUTER SHOPPER | FEBRUARY 2015 119

You might also like