93

Computers to Crime

Linux Manual Everything you need to get started with Ubuntu Linux by Mike Saunders

Hardback, 270 x 210mm, 176pp 500 colour illustrations ISBN: 978 1 84425 970 0 Book No: H4970 Haynes RRP: £19.99

Build Your Own Computer (5th Edition) The complete step-by-step manual to constructing a PC that s right for you by Kyle MacRae, Gary Marshall

Hardback, 270 x 210mm, 176pp 237 colour illustrations ISBN: 978 0 85733 268 4 Book No: H5268 Haynes RRP: £21.99

Computer Manual (5th Edition) The step-by-step guide to upgrading, repairing and maintaining a PC by Kyle MacRae

Hardback, 270 x 210mm, 232pp 400 colour illustrations ISBN: 978 1 84425 928 1 Book No: H4928 Haynes RRP: £19.99

Raspberry Pi Manual A practical guide to the revolutionary small computer by Gray Girling

Hardback, 270 x 210mm, 176pp 150 colour illustrations ISBN: 978 0 85733 295 0 Book No: H5295 Haynes RRP: £17.99

Hardback, 270 x 210mm, 176pp 400 colour illustrations ISBN: 978 0 85733 802 0 Book No: H5802 Haynes RRP: £22.99

Build Your Own Gaming PC The step-by-step manual to building the ultimate computer by Russell Barnes

Bank Raids Crimes of the Century by Ian Welch, Claire Welch

Paperback, 197 x 128mm, 224pp 40 colour illustrations ISBN: 978 0 85733 192 2 Book No: H5192 Haynes RRP: £8.99

Hardback, 270 x 210mm, 176pp 150 colour illustrations ISBN: 978 1 78521 073 0 Book No: H6073 Haynes RRP: £18.99

Raspberry Pi 2 Manual A practical guide to the revolutionary small computer by Gray Girling

C M Y K

Haynes Publishing Sparkford, Yeovil, Somerset BA22 7JJ, UK Tel: +44 (0) 1963 442030 Fax: +44 (0) 1963 440001 E-mail: sales@haynes.co.uk Website: www.haynes.co.uk

£17.99 / $28.95

ISBN 978 0 85733 295 0 £17.99 rrp

H5295

Owners Workshop Manual

Gray Girling Foreword by Eben and Liz Upton

RaspbeRRy pi2

RaspbeRRy pi

R a

s p

b e

R R

y p

i M anual

A practical guide to the revolutionary small computer

A practical guide to the revolutionary small computer

R

G ray G

irlin g

The Raspberry Pi Manual is the perfect introduction to the affordable small computer. With authorship from an expert close to the project and the trademark Haynes how to approach, this is the manual everyone needs to get started with their Raspberry Pi, whether at home or in the classroom.

Printed in full colour throughout, the Raspberry Pi Manual is aimed at those switching on their Pi for the first time, guiding them through the full process of set-up and configuration. The book then introduces various aspects of computing and programming subjects that have been sadly absent from the school curriculum for many years and provides a variety of recipes to demonstrate the acclaimed versatility of the Raspberry Pi s hardware and software.

n Designed for the capable but uninformed reader, assuming little previous knowledge

n Introduces key aspects of computing, providing background and historical context

n Covers a range of practical topics including operating systems (Linux), programming languages (Python) and networking

n Teaches essential hardware and software recipes to use in your own projects

n Complete meal plans provide fully worked and ready-to-go examples

n Pointers to online resources encourage further investigation

Dr Gray Girling studied computer science at Imperial College and the University of Cambridge and was involved in testing one of the very first BBC Micros for Acorn Computers in the early 1980s. He has since worked for Acorn and a host of other computer and technology companies, writing and designing his own embedded operating system and computer languages. As an engineer for Broadcom, he has been involved closely with the development of the Raspberry Pi, and is perfectly placed to provide a thorough and authoritative introduction to using and programming it.

which should result in the directory python-twitter-0.8.2 appearing. The Python library can now be installed using

cd python-twitter-0.8.2 python setup.py build sudo python setup.py install

This will be suffi cient for our needs. You may be interested, however, in the range of things that this Twitter software can do for you. They re described at

http://code.google.com/p/python- twitter/

which has examples of the way that you can get a list of your friends, fi nd the most recently posted texts by those you re following and even make a new tweet. The documentation for all the functions that Twitter make available are documented at

http://dev.twitter.com/doc

Python development environment If you haven t done so already, you could install a program to use for developing Python programs. We describe how to use Geany in the section about Python. It s installed using

sudo apt-get install geany

Test the toy First we should write a quick Python program that ll demonstrate whether or not our hardware is working. You can do this by creating a new Geany project and typing this program into a new Python fi le yoda.py .

Naturally this Python program can be used as it is for various purposes in other programs. For example, it could be incorporated into a Python or Bash program to indicate an error condition. If, like this toy, your toy makes a noise it could be made the subject of a cron entry to turn it into a daily alarm (see the section about running programs regularly).

subdirectory of your home directory called tree (but you can place it where you like).

mkdir -p ~/tree/piface cd ~/tree/piface git clone https://github.com/thomasmacpherson/ piface.git

This creates a place to put the fi les, selects it as your current working directory and then uses the git command (installed in the previous step) to make a copy of the programs. (Because this code is still being developed you may fi nd that you ll get access to improvements in the code at a later date by executing the command

git pull

in this directory.) You should fi nd that a directory called piface has been created. To install the Python software you ll need to use

cd piface/python/ sudo python setup.py install

This is all we need from this software at the moment, but do have a look at the README.md fi le which details the other features that it provides, including a C library and an emulator which will represent the effects of any program that you execute graphically.

Twitter Python library The Python library that supports access to your Twitter account is provided on the Web at

http://code.google.com/p/python-twitter/

It requires one or two Python libraries before it ll work properly, which you can install using

sudo apt-get install python-simplejson python-httplib2 python-oauth2

The library itself is obtained from this website:

http://code.google.com/p/python-twitter/ downloads/list

It s updated with different versions from time to time. If the most up-to-date version is 0.8.2 you could use wget to obtain a copy:

mkdir -p ~/tree/twitter cd ~/tree/twitter wget http://python-twitter.googlecode.com/ fi les/python-twitter-0.8.2.tar.gz

(The wget command should all be typed on the same line.) This will create a fi le python-twitter-0.8.2.tar.gz which can then be unpacked using

tar -zxf python-twitter-0.8.2.tar.gz

To connect Yoda take the two wires from the toy and, using a screwdriver, attach them to the left-hand pair of holes in the grey connection block in the centre of the rear of Pi-Face.

Software preparation

SPI device To use Pi-Face you ll need to set up SPI on Raspberry Pi as described in the section about SPI. In particular you need to

 Ensure that the spi_bcm2708 module loads.  Make sure udev gives the SPI devices usable access

controls.

Pi-Face Python library To use Raspberry Pi we ll make use of the Python library that the School of Computer Sciences at Manchester University has already provided. This is contained in a software release that s provided using the git source control program (which we discussed briefl y in the section about recompiling the Linux kernel). To ensure that you have this and other useful programs use

sudo apt-get install git make gcc python-dev python-gtk2-dev

You ll need somewhere to place this software. One suggestion is to keep it alongside any other source trees you acquire in a

You should be able to test how successful you ve been in avoiding a short circuit by touching together the other end of the two wires to make sure the toy still behaves as it should when the button is pressed.

Pi-Face Pi-Face is designed to fi t directly on top of a Raspberry Pi board using the expansion header as both an electrical and a mechanical connector. To attach Pi-Face simply position the expansion connector pins under the corresponding socket on Pi-Face and press the two together.

Pi-Face connected to Raspberry Pi.

Connecting Yoda to Pi-Face.

You should see or hear your toy perform its action when the Execute button is used. (In the example, the toy said A Jedi uses the force. )

The first incision.

Wires for an external button.

Removing the tummy button.

After the tummy tuck.

146 Raspberry Pi Manual

06.

147Raspberry Pi Manual

06.

H5295_pt_06.indd 146-147 10/1/13 14:37:07

It s now necessary to reconnect the wires on the cable to the stubs on the header in the order: (header) black to (cable) orange; (header) brown to (cable) yellow; and, (header) red to (cable) black. We have no use for the other wires. They can be bent out of the way. You should be able to do this by lining each pair of wires to be connected next to each other (touching) and then applying the soldering iron so as to melt the tinning on each wire. With a little care you may fi nd it possible to fashion a tiny strip of insulating tape to wrap around the solder join on each connection. Alternatively you might try a small quantity of Sellotape the purpose of this is to gain some confi dence that adjacent connections cannot make electrical contact with each other.

Testing your connection If you have a Windows PC you can test your connection quite easily because Raspberry Pi sends messages to its UART while it boots.

Connecting to Raspberry Pi Once you ve made up your serial lead it s particularly important that it s connected properly. Like other serial leads we could use, only three wires are connected, even though yours has a six-pin header: the wires actually used in this cable are a black one, a yellow one and an orange one. The header must be connected as shown in this diagram:

Calling the pin in the corner of the board pin 1 you should be able to see that the header is positioned with its fi rst wire in pin 3 (not pin 1). The black, yellow and orange wires will actually be connected to pins 3, 4 and 5 respectively.

Once cut there should be enough room on both sides of each cut to strip and tin the wires (that is, soak the wires lightly in solder).

Strip the plastic away from the yellow, orange and black wires on the lead and tin them.

Now also tin the black, brown and red stubs of wire on the header.

A serial line, such as that supported by Raspberry Pi s UART (which we introduced in the section about serial lines), was once the main way that users would interact with a computer. Users would sit at a terminal device that simply sent text serially (one character after another) to the computer and displayed the text that the computer sent back. Once computers routinely had their own graphics support the WIMP (Windows, Icons, Mouse and Pointer) paradigm took over and the UART fell to another use: driving the modem (short for modulator/demodulator ) that provided Internet access over a phone line. Nowadays that use is also a thing of the past and the telltale nine-pin serial line socket has disappeared from the back of new PCs. Reports of its death are, however, greatly exaggerated. A UART only really needs three wires to work and it needs virtually no software to drive it. This means that all kinds of embedded computer systems provide one, even if it s only intended to be used by the software developers who bring the platform to life. Often computer systems provide UARTs that aren t actually connected to anything once the system s in full production, and Raspberry Pi isn t much of an exception. You can gain access to the text-based terminal interface of your Raspberry Pi from a serial cable in the same way that SSH or a keyboard and display can be used to access it.

Expansion header pins You can use three of the pins from the GPIO block to support UART signals. As we described in the section about the GPIO, the UART pins are provided by one of the alternative functions of the GPIO lines that the chip labels 14 and 15. The signals implemented are just those that transmit serial data from the Raspberry Pi (TxD) and that receive serial data back (RxD).

A serial connection to a PC There s no proper UART socket on Raspberry Pi. There s every chance that there s no proper UART socket on your computer either, so this section is going to describe how to use a cheap USB-to-serial cable to connect to your PC using one of its USB (Universal Serial Bus) sockets. In the section about the GPIO pins you may remember that we have to be fairly careful about the electrical specifi cations of things we plug in to them. The type of USB-to-serial lead we need is one that supports 3.3 volt connections. The one used in this example has the model number TTL-232R-3V3 and is provided by a company called FTDI Chip.

Create a USB serial line For this project you ll need a TTL-232R-3V3 USB-to-serial lead, a soldering iron, some wire cutters and some solder. The lead has a USB plug at one end and a black header with six single pin sockets in it at the other.

HARDWARE RECIPES

Connecting to a PC using the UART

Expansion header UART pins.

USB serial lead.

Cut the connector off.

Reconnected socket.

Black socket removed.

Completed plug inserted correctly.

Tin the red, yellow and black wires on the cable.

Tin the wires on the socket.Header end of the lead, wire cutter and soldering iron.

126 Raspberry Pi Manual

05.

127Raspberry Pi Manual

05.

H5295_pt_05.indd 126-127 10/1/13 14:36:03

R

Cannibal Killers Crimes of the Century by Claire Welch

Paperback, 197 x 128mm, 224pp 40 colour illustrations ISBN: 978 0 85733 719 1 Book No: H5719 Haynes RRP: £8.99

Britain s Most Depraved Killers Crimes of the Century by Claire Welch

Paperback, 197 x 128mm, 224pp 40 colour illustrations ISBN: 978 0 85733 718 4 Book No: H5718 Haynes RRP: £8.99

Computer programming (beginners onwards)

Coding

Everything you need to get started with programming using Python Get

star ted

toda y w

ith

Hay nes

Ma nua

ls

Owners Workshop Manual

Coding Manual A step-by-step guide to programming in Python by Mike Saunders

Hardback, 270 x 210mm, 192pp 100 colour illustrations ISBN: 978 1 78521 118 8 Book No: H6118 Haynes RRP: £22.99

NEW TITLE: MAY 2017

Computers

Crime

Buy / order