The_MagPi_issue_5.pdf

(8810 KB) Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
I I S S S S U U E E 0 0 5 5 ­ ­ S S E E P P 2 2 0 0 1 1 2 2
A A M M a a g g a a z z i i n n e e f f o o r r R R a a s s p p b b e e r r r r y y P P i i U U s s e e r r s s
S S t t e e a a d d y y H H a a n n d d F F u u n n
W W i i t t h h T T h h e e R R a a s s p p b b e e r r r r y y P P i i
T T u u t t o o r r i i a a l l b b y y M M i i k k e e C C o o o o k k
A A l l s s o o i i n n t t h h i i s s i i s s s s u u e e
RaspberryPiMediaCentre
AGuideToOpenELECandRaspbmc
SqueezyorWheezy?
DebianDistro'sExamined
http://www.themagpi.com
RaspberryPiisatrademarkofTheRaspberryPiFoundation.
ThismagazinewascreatedusingaRaspberryPicomputer.
884156120.025.png 884156120.026.png 884156120.027.png 884156120.028.png 884156120.001.png 884156120.002.png 884156120.003.png 884156120.004.png 884156120.005.png 884156120.006.png 884156120.007.png
WelcometoIssue5,
Thismonthwehaveacollectionofhardwareprojectsforyou,aswellas
ourusualselectionofprogrammingarticlesandgeneraloperatingtips.
WeareproudtopresentanarticlebynoneotherthanMikeCook,who
designedseveralprojectsforTHEMICROUSERmagazine.This
magazinehadagreatinfluenceonmanyofthosewhowerefortunateto
haveaccesstoaBBCmicrocomputer.WithouttheeffortsofMikeand
fellowauthors,theyoungmembersoftheRaspberryPifoundationmay
neverhavethoughtofbuildingtheRaspberryPI.
Wearestilllookingforvolunteerstohelpwithlayoutaswellasauthors
ofnewandexcitingprojects.
AshStone
ChiefEditorofTheMagpi
Ash Stone
ChiefEditor/Administrator/Header
Jason 'Jaseman' Davies
Writer/Website/PageDesigns
Meltwater
Writer/Photographer/PageDesigns
Chris 'tzj' Stagg
Writer/Photographer/PageDesigns
Matt '0the0judge0'
Administrator/Website
Mike Cook
Writer
Duncan Rowland
Writer
Colin Deady
Writer/PageDesigns
Bobby 'bredman' Redmond
Writer/PageDesigns
W.H. Bell & D Shepley
Writers
Colin Norris
Editor/Graphics(CCaveHeader)
Antiloquax
Writer
Lix
PageDesigns/Graphics
Paisleyboy
PageDesigns/Graphics
Andrius Grigaliunas
Photographer
2
884156120.008.png
Contents
04 STEADY HANDS
Are you r h an d s stread y en ou g h to beat th e P i ? by M i ke Cook
07 ENVIRONMENTAL MONITORING
Track tem peratu re fl u ctu ati on s. by Du n can Rowl an d .
10 WHAT'S ON GUIDE & COMPETITION
Fi n d ou t wh ere Raspberry J am s' are h appen i n g an d wi n a starter ki t
12 XBMC: Raspbmc and OpenELEC
G et to g ri ps wi th you r m ed i a cen tre setu p. by Col i n Dead y
16 SQUEEZE VS WHEEZY
I m provem en ts an d ch an g es. by J asem an
18 COMMAND LINE CLINIC
Learn h ow to backu p i m portan t d ata. by Bobby (bred m an ) Red m on d
20 C CAVE
Fu n cti on s, poi n ter an d text fi l e en crypti on . by W. H . Bel l & D. Sh epl ey
24 THE SCRATCH PATCH
P rog ram you r own Si m on says g am e. by An ti l oq u ax
26 48HR RASPITHON
Ben , Lu ke, Ryan an d Ed ward recou n t th ei r pyth on ch al l en g e.
27 THE PYTHON PIT
G rad i en t fi l l s, an d u si n g m ath s to pl ot poi n ts of a ci rcl e, by J asem an
32 FEEDBACK & DISCLAIMER
3
884156120.009.png 884156120.010.png
STEADYHANDS
Youdon'thavetogetcomplicatedtogetagreatdealoffun
fromaninterfacingproject.Electricallythisisjustaboutas
simpleasyoucanget,howeverithasaverygoodfunto
technologyratio.
DIFFICULTY: INTERMEDIATE
Steady hands is a very old game, however,
with a Raspberry Pi we can give it a new twist.
The Construction
1. Drill holes in the wooden block for the 'bent
coathanger/wire' just smaller than the
diameter of the coathanger/wire so that the
wire will hold itself up. Make sure to space the
two holes far enough apart to accomodate
your design.
The idea is that you have to guide a wire loop
along a bendy wire without making the two
touch. You can make this as complex or as
easy as you like by having more bends in the
wire or having the loop smaller.
2. Make the wire loop and solder a length of
wire to it. You might want to add a covering of
insulation tape, or better self amalgamating
tape, over the end you hold.
Materials
-Bare single core Wire (2mm Dia)
e.g. Metal coat hanger. If using wire it
needs to be thick enough to hold its shape.
-Stranded wire (insulated)
-Block of wood (size depends on your
design of 'bent coathnager')
-Electrical Tape
3. Put the 'bent coathanger/wire' through the
wire loop and then into the wooden block.
4. Solder a length of stranded wire (insulated)
to one end of the 'bent coathanger/wire'.
Tools
-Drill
-Drill Bit (just smaller than the diameter
of the wire)
-Solder
-Soldering Iron
5. Drill two holes on either side the bent
coathanger/wire as shown in the image below
for the rests.
6. Put two short lengths of coathanger/wire to
act as rests in these holes. These will detect
when the game starts and when the wireloop
reaches the end. Bend them so the loop will
rest against them without shorting out to the
bent wire.
A - Physical pin 7 GPIO pin 4
B - Physical pin 3 GPIO pin 0
C - Physical pin 5 GPIO pin 1
D - Physical pin 6 Ground
4
884156120.011.png 884156120.012.png 884156120.013.png 884156120.014.png
7. Solder a length of normal wire (insulated) to
each end stop.
First of all the three lines must be set up as
inputs. They boot up as inputs anyway but it is
always good practice to initialise the lines you
want to use.
8. On each end of the 'bent coathanger/wire'
and both rests, from where they hit the block
of wood, tape them with insulated electrical
tape 4 cm high.
I used the GPIO numbers and not the physical
pin numbers in the code as I strongly believe
that using physical pin numbers is actually not
a sensible thing to do, and not a good way to
teach children. It's like the ITA (Initial
Teaching Alphabet) mistake all over again.
The following table, and image, show how
each part of the 'STEADY HAND' attaches to
which pin of the PI GPIO via the 2.54mm
header:
The game is in three phases:
1) Wait until the loop is placed on the start
rest.
2) Wait until the loop is removed from the start
rest.
3) Time the interval from lifting it off the start
rest until it reaches the end rest. While it is in
this phase monitoring the bendy wire for
touches.
STEADY HAND
PI GPIO
WIRE LOOP
GROUND - PIN 6
BENT WIRE
GPIO 1 - PIN 5
START REST
GPIO 4 - PIN 7
This is then repeated forever, so a control C is
needed to stop the program.
END REST
GPIO 0 - PIN 3
This is just the bare bones of what is possible.
I always think a good way to learn anything is
to extend and modify from a base. This is your
base.
One extension would be to add a sound
whenever the bendy wire is touched. The
August issue of the MagPi showed you how to
incorporate sound effects into a Python
program, so take those bits and graft them
into this program.
Raspberry Pi Physical Pins
You could also keep track of the high scorer,
or even have a table of high scores along with
the names. You can make that permanent by
writing it out to a file and reading the file when
the program first starts up.
How does the GPIO work?
Basically we have three signal wires and a
ground. Using GPIO 0 & 1 means that a pull
up resistor is already connected on the Pi, just
leaving GPIO 4 to have either an external pull
up attached or activating the internal pull up
resistor. I opted for the latter option.
You can add penalty points into the time, say
3 seconds per point to give a single figure. On
a more practical level, see if you can abort a
timed run when the loop is placed back on the
start loop.
There is plenty of scope for adding your own
refinements. Have fun.
The Program
The software was my first venture into writing
in the Python language. It is quite straight
forward.
Continuesonthenextpage
5
884156120.015.png 884156120.016.png 884156120.017.png 884156120.018.png 884156120.019.png 884156120.020.png 884156120.021.png 884156120.022.png 884156120.023.png 884156120.024.png
Zgłoś jeśli naruszono regulamin