background image

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

Summary of Contents for Raspberry Pi

Page 1: ...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 ...

Page 2: ...stems 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 ...

Page 3: ...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 reserv...

Page 4: ...osphere What many RPi users don t realize though is that there s a wealth of other operating systems available for their beloved Pi We thought therefore that those users who aren t aware of these other sweet toppings for the Raspberry Pi need to be informed and what s more they need to have a chocolate box selection presented to them OUR SELECTION Raspbian Risc OS Arch RaspBMC OpenELEC Pidora How ...

Page 5: ...her or not this is worth all the work does of course depend on you RaspBMC The Raspberry Pi may have been designed as an educational tool but hobbyists have been pretty quick to make it a toy This distro is designed to turn your Pi into a media center that can be used to control your TV It s based on XBMC which allows you to play music and videos that you have as files or stream them from the inte...

Page 6: ... we are rapidly launched into a colorful and friendly GUI with relatively detailed messages informing us of any issues during the initial boot and setup From here we can simply click on the Configure icon and begin to alter any settings we see fit Arch Linux for the RPi is a different beast booting the user into a terminal environment and leaving them to download install and configure their OS Arc...

Page 7: ...as normal However NOOBS stays resident on your card by holding Shift down during boot you can return to the recovery interface This allows you to switch to a different operating system or overwrite a corrupted card with a fresh install of the current one it also provides a handy tool to let you edit the config txt configuration file for the currently installed operating system and even a web brows...

Page 8: ...phics chip Using this option you can change the amount allocated to each overscan This option can be used on some displays to make the graphics expand to fill the whole screen You can safely ignore it unless you have problems overclock Get an extra 50 per cent performance at no extra cost See Overclocking for more details boot_behaviour This rather cryptically named option changes whether your Pi ...

Page 9: ...i is designed to run at 700MHz That is perform 700 000 000 operations per second Of course designed to run doesn t 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 you re liable to have a smoking pile of silicon rather than a functional processor Fortunately Raspbian includes a...

Page 10: ...ful applications However sometimes you need an interface that s a bit more powerful and this is where the command line interface CLI comes in It s also known as the terminal or shell This is an entirely text based interface where you type in commands and get a response We won t lie to you it will seem confusing at first Don t worry though once you ve had a bit of practice it will start to make sen...

Page 11: ...n tell them exactly how we want them to behave This is done using flags which come after the command and start with a For example if we want to list all the files in the current directory including hidden ones which start with a on Unix based systems we use the flag a So in your terminal type ls a This time you should see more files appear Another flag for ls is l This gives us more information ab...

Page 12: ...l will find all occurrences of l You can use the N key and Shift N to scroll forwards and backwards through the occurrences of l As we introduce more commands it s good to take a look at the help and the man page to familiarize yourself with what they do Of course you can always Google a command if you find the text based help a little off putting but staying in the terminal will help you become m...

Page 13: ...s a file from one place to another This one takes two arguments the original file and the new file cat outputs the contents of one or more text files This takes as many arguments as you want each one a text file and simply spits their contents out on to the terminal less is a more friendly way of viewing text files It lets you scroll up and down using the arrow keys To exit the program back to the...

Page 14: ...mand line programs They re particularly useful for sorting files To copy all the txt files into a new directory you could run mkdir text files cp txt text files We can then check they made it there correctly with ls text files The second wildcard we ll look at is This matches any single character What do you think ls will match Have a guess then run it to see if you re right We can also create our...

Page 15: ...ross them and start to see how they can be linked together We ll take a look at a simple example If you run find don t do it just yet it will list every file on the system This will produce a reel of filenames that will quickly go off the screen However rather than direct it to the screen we can send or pipe it to another command that makes the output easier to read We can use the less command tha...

Page 16: ...wnload 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 don t need to worry about finding the install files or anything like that the package manager does it all for you There are a few different package managers available for Linux but the one used by Raspbian is apt get Arch uses a different one so if you want ...

Page 17: ...that can contain anything at all In order to install software with apt get you need to know the package name Usually this is pretty obvious but it needs to be exactly right for the system to get the right package If you re unsure you can use apt cache to search through the list of available packages Try running apt cache search iceweasel This will spit out a long list of packages that all have som...

Page 18: ...me way as apt get but with a graphical interface Once the package is installed you can start it with where is synaptic See below for more information The second graphical tool is the Raspberry Pi App store Unlike apt get and Synaptic this deals with commercial software as well as free software so you have to pay to install some things It comes by default on Raspbian and you can get it by clicking ...

Page 19: ... a file called INSTALL which you can read with less INSTALL This should tell you how to continue with the installation Usually but not always it will say configure make sudo make install The first line will check you have all the necessary dependencies on your system If it fails you need to make sure you have the relevant dev packages installed If that all works you should have the software instal...

Page 20: ...on page 6 to install the RaspBMC operating system from the NOOBS image This uses the popular XBMC media desktop which is quite different from LXDE which you may have experienced on Raspbian You can play media stored locally or through the use of add ons stream content from the internet Music and videos can be added to your setup either by attaching a USB device or directly on to the SD card using ...

Page 21: ...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 Taking it further It is possible to take complete control of your TV viewing using Linux including watching live TV and recording ...

Page 22: ...t anything that you can plug in to a normal desktop can be scripted by a Pi but we re going to look at cameras for a couple of reasons Firstly there s support for most in Linux and secondly there s a range of useful projects you can do once you ve grasped the basics The best command line tool for manipulating cameras in Linux is Gphoto2 Get it with apt get install gphoto2 Gphoto2 has far more capa...

Page 23: ...st command we can send to the camera is to get all the photos stored on it This is gphoto2 auto detect get all files Running this will download all the files from the camera into the current directory This would be fine on a normal computer but you may not want to do it on a Pi as you run the risk of filling up your memory card pretty quickly Instead we ll copy them on to a USB stick To do this in...

Page 24: ...e drive is properly synced and can be removed We ve called the script get pics sh and saved it in Pi s home directory To make it executable run chmod x home pi get pics sh You should now be able to run it manually You ll need to use sudo because it needs to mount the drive The final piece of the puzzle is to get the script to run automatically To do this we add it to the file etc rc local This scr...

Page 25: ...ace usb0 inet dhcp nameserver 208 67 220 220 nameserver 208 67 222 222 This used the OpenDNS nameservers but you could use others if you wish You can now either restart the interfaces or restart your Raspberry Pi to pick up the changes You should have an internet connection up and running New directions If you want to run the device headless as will most likely be the case you could attach LEDs to...

Page 26: ...ne via General Purpose Input and Output GPIO You may have wondered what the spiky pins near the SD card reader are for well you re about to find out This basic circuit can be used to display information from any source but here we re going to use it to find the final byte of the IP address This is useful if you want to remotely access your Pi but can t configure it with a static IP because for exa...

Page 27: ...ter to a 1 KOhm resistor and finally the other leg of the resistor to the common ground See figures 1 2 and 3 for details Once you have your fully set up board connected to your Pi you can make things happen To start with we ll just use the final pin This is pin 7 the layout of the pins doesn t follow a numbering pattern Open up a terminal and set it to output with gpio g mode 7 out Then you can t...

Page 28: ...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 Gertboards and Arduinos Connecting directly to your Pi s 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 ...

Page 29: ... a robot army Ohm s 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 Ohm s law which states Voltage Current x Resistance or V IR You can use this connection to make sure you don ...

Page 30: ...get started head over to s3 amazonaws com assets minecraft net pi minecraft pi 0 1 1 tar gz to download the package Once that is finished open a new terminal window or click on LX Terminal icon on the desktop To decompress your freshly downloaded package type tar zxvf minecraft pi 0 1 1 tar gz To start it Type cd mcpi Then minecraft pi At this point you can play Minecraft as a single user or over ...

Page 31: ...the player to see Congratulations you have learned to simply program Minecraft Pi Now on to a more advanced project that is Placing Block within your game To place a block let s type the following at the command prompt import block mc setBlock 0 10 0 block STONE The first line which imports block simply allows us to use the block names when we position them The name block STONE can be changed to b...

Page 32: ... The project started to look very realizable Eben now a chip architect at Broadcom Rob Jack and Alan teamed up with Pete Lomas MD of hardware design and manufacture company Norcott Technologies and David Braben co author of the seminal BBC Micro game Elite to form the Raspberry Pi Foundation to make it a reality Three years later the Raspberry Pi Model B entered mass production through licensed ma...

Page 33: ...gle 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 f...

Page 34: ... 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 A Z that is any upper case letter A z Matches any character in the range A z that is any upper or lower case letter one two Matches the words one and two Information about the computer top Displays the progra...

Page 35: ... Pastes text from the clipboard Installing software tar zxvf file tar gz tar xjf file tar bz configure When you unzip a program s source code it will usually create a new directory with the program in it cd into that 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 needs sudo This will move...

Page 36: ...www element14 com Raspberry Pi User Guide indd 36 08 07 2014 14 44 ...

Reviews: