The MagPi Issue 4 Final
The MagPi Issue 4 Final
The MagPi Issue 4 Final
I
S
S
S
S
U
U
E
E
0
0
4
4
-
-
A
A
U
U
G
G
2
2
0
0
1
1
2
2
A A M Ma ag ga az zi in ne e f fo or r R Ra as sp pb be er rr ry y P Pi i U Us se er rs s
http://www.themagpi.com
Raspberry Pi is a trademark of The Raspberry Pi Foundation.
This page was created using a Raspberry Pi computer.
Cover photo by Andrew Edney @ Connected Digital World
W
W
i
i
n
n
a
a
M
M
a
a
g
g
P
P
i
i
C
C
a
a
s
s
e
e
i
i
n
n
o
o
u
u
r
r
c
c
o
o
m
m
p
p
e
e
t
t
i
i
t
t
i
i
o
o
n
n
(
(
P
P
a
a
g
g
e
e
1
1
1
1
)
)
Welcome to Issue 4,
This month the team are very proud to annouce that for the first time,
The MagPi has been created entirely using Raspberry Pi computers.
As promised, we bring you our interview with Eben & Liz from the
Raspberry Pi Foundation.
We have some new articles, as well as our popular series, covering
hardware projects, programming and other general operating tips.
We have received a good response to our request for volunteers. There are
now a few new additions to the team, however we are still looking for
more help, so please do come forth!
Ash Stone
Chief Editor of The Magpi
Contents
I
N
C
O
N
T
R
O
L
I
N
T
E
R
F
A
C
I
N
G
P
R
O
J
E
C
T
S
F
O
R
B
E
G
I
N
N
E
R
S
B
Y
D
A
R
R
E
N
G
R
A
N
T
W
e
h
a
v
e
a
l
r
e
a
d
y
u
s
e
d
t
h
e
R
a
s
p
b
e
r
r
y
P
i
G
P
I
O
o
u
t
p
u
t
s
t
o
d
r
i
v
e
l
i
g
h
t
e
m
i
t
t
i
n
g
d
i
o
d
e
s
,
b
u
t
i
t
i
s
n
o
t
p
o
s
s
i
b
l
e
t
o
d
i
r
e
c
t
l
y
d
r
i
v
e
a
n
y
t
h
i
n
g
l
a
r
g
e
r
b
e
c
a
u
s
e
o
f
p
o
w
e
r
l
i
m
i
t
a
t
i
o
n
s
.
I
n
t
h
i
s
p
a
r
t
w
e
l
o
o
k
a
t
u
s
i
n
g
a
t
r
a
n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
b
a
n
k
o
f
h
i
g
h
b
r
i
g
h
t
n
e
s
s
L
E
D
s
o
r
a
s
m
a
l
l
b
u
z
z
e
r
.
T
r
a
n
s
i
s
t
o
r
s
c
a
n
o
n
l
y
b
e
u
s
e
d
f
o
r
D
C
V
o
l
t
a
g
e
s
,
s
o
c
a
n
N
O
T
b
e
u
s
e
d
f
o
r
s
w
i
t
c
h
i
n
g
A
C
m
a
i
n
s
e
l
e
c
t
r
i
c
i
t
y
.
A
k
e
y
a
d
v
a
n
t
a
g
e
o
f
a
t
r
a
n
s
i
s
t
o
r
i
s
t
h
a
t
i
t
a
s
i
t
h
a
s
n
o
m
o
v
i
n
g
p
a
r
t
s
i
t
c
a
n
b
e
s
w
i
t
c
h
e
d
v
e
r
y
q
u
i
c
k
l
y
,
t
h
o
u
s
a
n
d
s
o
f
t
i
m
e
s
a
s
e
c
o
n
d
i
f
r
e
q
u
i
r
e
d
a
n
d
h
a
s
a
v
e
r
y
l
o
n
g
o
p
e
r
a
-
t
i
o
n
a
l
l
i
f
e
c
o
m
p
a
r
e
d
t
o
a
m
e
c
h
a
n
i
c
a
l
r
e
l
a
y
.
4
P
A
R
T
3
C
O
L
L
E
C
T
O
R
E
M
I
T
T
E
R
B
A
S
E
N
P
N
T
r
a
n
s
i
s
t
o
r
S
y
m
b
o
l
2
7
6
-
1
7
5
Pin 06
Pin 11
Pin 01
3.3V
0V
GPIO17
R1 R2
R3
Pin 12
GPIO18
+
Pin 13
Pin 15
GPIO21
GPIO22
R4
R5
R6
SW1 - Tactile Switch J5, J8, Y5, Y8
SW2 - Reed Switch
R1 - 470O ResIstor D5, H5
R2 - 1kO ResIstor 1, 5
R3 - 10kO ResIstor D8, H8
R4 - 10KO ResIstor
R5 - 1kO ResIstor
IMPORTANT
Before connecting anything to the Raspberry Pi
please be aware that incorrect connections could
cause damage. Please take care.
5
Alarm System Circuit
To demonstrate the use of a transistor, we will
construct an alarm system that will sound a
small buzzer when activated.
Circuit Description
We will be using two outputs and two inputs.
The first output is the familiar LED circuit that
will be used to indicate when the alarm is
armed. The second output is connected via re-
sistor R2 to the base of the transistor, the resis-
tor is necessary to limit the amount of current
supplied to the base of the transistor so that
there is just enough to switch it on. The collec-
tor of the transistor is connected to a buzzer so
that it will sound when the output connected to
the base of the transistor is set high. Although
we could use the transistor to switch a higher
voltage for example 5V, to keep things simple
we are using a 3.3V buzzer so that the whole
+3.3V
IO2
0V
LED1
R1
R3
SW1
IO0
IO1
R2
BZ1
TR1
IO3
R4
SW2
R5
R6
Pin 06
Pin 01 Pin 11
Pin 12
Pin 15
Pin 13
circuit can be powered from a single voltage.
The first input is the same small push-button
switch as in previous experiments, this will be
used to arm and disarm the alarm. The second
input is a magnetically operated reed switch.
A magnet would be attached to a door and
the switch to the door frame so that the switch
will be opened and closed when the door is
opened and closed. If you dont intend to use
the circuit on a real door and prefer not to buy
a reed switch for the purpose of experiment-
R6 - 1kO ResIstor
LED1 - Red LED C4, C5
TR1 - 2N2222 D21, D22, D23
8Z1 - MInI 3.3V 8uzzer X21, 821
WIre IInk X4, 84
WIre IInk X8, 88
WIre IInk E23, Y23
6
import RPi.GPIO as GPIO
import time
GPIO.setup (11, GPIO.IN)
GPIO.setup (12, GPIO.OUT)
GPIO.setup (13, GPIO.IN)
GPIO.setup (15, GPIO.OUT)
while True:
if not GPIO.input(11):
if GPIO.input(13):
print The door is open - please close the door and try again.
GPIO.output(15, True)
time.sleep(.3)
GPIO.output(15, False)
Fash = 3
while Fash > 0.
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
Fash -= 1
else:
ac11vc = `1uc`
ac11va1cd = `!a1sc`
time.sleep(.1)
if GPIO.input(11):
print Alarm Armed
while ac11vc == `1uc`.
GPIO.output(12,False)
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
print Alarm Disarmed
time.sleep(.1)
ac11vc = `!a1sc`
if GPIO.input(13):
print **** Alarm !!! ****
ac11va1cd = `1uc`
GPIO.output(15, True)
11mc.s1ccp{10)
GPIO.output(15, False)
while ac11va1cd == `1uc`.
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
print Alarm Disarmed
time.sleep(.1)
ac11vc = `!a1sc`
ac11va1cd = `!a1sc`
else:
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
else:
GPIO.output(12,True)
Conclusion
We have covered how to control high power
devices using a transistor. There are many
other options available for switching higher
power loads such as adding a second Power
Transistor to the circuit to create what is known
as a darlington pair. Unfortunately there is not
enough space in this section to cover darling-
ton pairs and other switching methods.
If you have questions or ideas I would encour-
age you to get involved on the offcial Rasp-
berry Pi forum to share ideas with others about
your projects.
www.tandyonline.co.uk
7
1h|s arnc|e |s sponsored by 1andy.
All Lhe componenLs menuoned ln Lhls serles and much more
are available from the Tandy online shop.
hup://www.Landyonllne.co.uk/lnconLrol.hLml
Shopping List
COMPONENTS
1x 3mm Red LED (standard brIghtness)
1x 470O ResIstor
3x 1kO ResIstor
2x 10kO ResIstor
1x MInIature PC8 TactIIe SwItch
1x Reed SwItch + Magnet
1x 3.3V MInI 8uzzer
1x 2N2222 TransIstor
ACCESSORES
1x 8readboard
6x MaIe-IemaIe jumper wIres
1x SeIectIon oI short jumper wIres
TOOLS
I you don`t have them aIready then a set
oI smaII Iong nosed pIIers Ior bendIng
component Ieads and wIre cutters wIII
make constructIon easIer.
ing feel free to modify the circuit slightly to use
another small tactile switch or whatever sort of
switch you have to hand in place of the reed
switch.
The buzzer and transistor must be inserted
into the breadboard the correct way round.
The buzzer used here has a longer leg that
indicates the positive terminal that should be
connected to the top. The transistor should be
placed with the front (flat side) facing towards
the bottom of the breadboard as shown in the
illustration, the legs will need to be spread out
to fit the holes in the breadboard.
Program Description
The main loop of the program waits for GPIO
Pin 11 to go LOW when the button is pressed.
We then check to see if the door is closed by
checking the status of the reed switch on pin
13. If the door is open we briefly turn on the
buzzer to create a short beep and flash the
LED to indicate that we cannot arm the alarm.
Then we return to the main loop waiting for the
button to be pressed again.
If the door is closed we turn the LED on and
start a loop that constantly monitors the status
of the switches. If the push-button is pressed
we end the monitoring loop, switching off the
LED and returning to the main loop waiting
for the alarm to be armed again. If however
the reed switch is triggered by the door being
opened we sound the buzzer and flash the
LED. To avoid causing a nuisance with the
buzzer it will stop after 10 seconds but the LED
will remain flashing to show that the alarm was
set-off until the button is pressed again to reset
it. NOTE: You will need to press and hold the
button to reset the alarm after activation.
commands
sudo bash
wget http://www.frank-buss.de/
raspberrypi/w1-test
bash w1-test
reboot
sudo apt-get install i2c-tools
sudo apt-get install python-
smbus
sudo bash
startx
leafpad /etc/modules
i2c-dev
reboot
ls /dev
python MMA7455.py
Continues on the next page
# I2C writes =D0=0
# MMA7455 I2C address 1D (3A ,3B) write , read
# AN3745 app note for calibration
# byte read , write 1D , write address, read 1D ,DATA
# Byte write, write 1D , write address, write data.
# addresses,
# 06 XOUT8
# 07 YOUT8
# 08 ZOUT8
# 09 STATUS D0 1=data ready
# 0A detection source
# 0F who am i
# 16 Mode Control x1000101 measure 2gmode
# 18 Control1 D7 filter 0=62Hz,1=125Hz other 0
# 19 Control2 default 0
#!/usr/bin/python
import smbus
import time
#import graphics
import pygame
# Define a class called Accel
class Accel():
b = smbus.SMBus(0)
# Read the value
def getValue(self):
#address 1D, register 0x16 sets mode
self.b.write_byte_data(0x1D,0x16,0x45)
# point at reg 6
self.b.write_byte_data(0x1D,0x06,00)
# Read the x value
l = self.b.read_byte_data(0x1D,00)
return l
screen = pygame.display.set_mode((1000,300))
# Create an object called MMA7455
MMA7455 = Accel()
# Get the value from it
for a in range(1000):
Aval= MMA7455.getValue()
print Aval,a
Aval=Aval+128
if (Aval >255):
Aval=Aval-255
screen.set_at((a,Aval),(255,255,255))
pygame.display.flip()
PYTHON VERSION: 2.6.6 / 3.2.2
PYGAME VERSION: 1.9.2a0
O.S.: Debian 6 / Win7
Want to keep up to date with all things Raspberry Pi in your area?
Then this new section of the MagPi is for you! We aim to list Raspberry Jam events in your
area, providing you with a R-Pi calendar for the month ahead.
Are you in charge of running a Raspberry Pi event? Want to publicise it?
Email us at: [email protected]
Bristol Raspberry Jam
Where: The Bristol and Bath Science Park
When: 20th August
Tickets: Free at:
http://raspberrybristol.eventbrite.com
Join the Bristol Raspberry Jam and demonstrate any projects you are working on
and express ideas you have for the future of the community with other fans and
guest speakers from all over the country!
What's On Guide
COMPETITION
This month The MagPi are proud to announce our first competition in
partnership with PC Supplies Limited! PC Supplies are offering a fantastic set of
goodies to get you up and running including the following:
Limited Edition MagPi Case
HDMI Cable
Power Supply
Audio Cable
Video Cable
GPIO Cable
Network Cable
32GB SDHC Card with Raspbian
To enter visit
http://www.pcslshop.com/info/magpi
Closing date is 20/8/2012.
Winner will be notified by email. Good luck!
11
INTERVIEW
M
a
g
P
i
E
x
c
l
u
s
i
v
e
Letter of the Month!
cd /usr/share/applications
ls
sudo leafpad gpicview.desktop
cd /usr/share/desktop-directories
ls
sudo leafpad lxde-education.directory
sudo leafpad lxde-magpi.directory
[Desktop Entry]
Name=The MagPi
Name[en_GB]=The MagPi
Comment=Desktop accessories
Comment[en_GB]=Desktop accessories
Icon=applications-accessories
Type=Directory
cd /etc/xdg/menus
sudo leafpad lxde-applications.menu
<!-- Accessories submenu -->
<!-- MagPi submenu -->
<Menu>
<Name>The MagPi</Name>
<Directory>lxde-
magpi.directory</Directory>
<Include>
<Filename>gpicview.desktop</Filename>
</Include>
</Menu> <!-- End The MagPi -->
<!-- Accessories submenu -->
<Menu>
<Name>Accessories</Name>
<Directory>lxde-
utility.directory</Directory>
<Include>
<And>
<Category>Utility</Category>
<!-- Accessibility spec must have either
the Utility or Settings category, and we
display an accessibility submenu already
for the ones that do not have Settings,
so don't display accessibility
applications here -->
<Not><Category>Accessibility</Category><
/Not>
<Not><Category>System</Category></Not>
<Not><Filename>gpicview.desktop</Filenam
e></Not>
<Not><Filename>pcmanfm.desktop</Filename
></Not>
</And>
</Include>
</Menu> <!-- End Accessories -->
<!-- MagPi submenu -->
<Menu>
<Name>The MagPi</Name>
<Directory>lxde-
magpi.directory</Directory>
<Include>
<Filename>gpicview.desktop</Filename>
<Filename>pcmanfm.desktop</Filename>
</Include>
</Menu> <!-- End The MagPi -->
sudo cp /etc/modules /etc/modules.old
man modules
sudo cp /etc/modules.old /etc/modules
sudo nano /etc/modules
# Enable sound
snd_bcm2835
less /etc/modules
sudo reboot
sudo nano /etc/mod
0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1
Condition
a == b
a != b
a > b
a <= b
Meaning
a 'equal' b
a 'not equal' b
a 'greater than' b
a 'less than or equal' b
Condition
! a
a | | b
a ^ b
a && b
Meaning
'not' a
a 'or' b
a 'exclusive or' b
a 'and' b
,
# Fish Game
# By antiloquax & Jaseman - 18th July 2012
import pygame, random
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode([600,400])
pygame.display.set_caption("Fish Game")
music = pygame.mixer.Sound("tune.wav")
music.play(-1)
toy = pygame.mixer.Sound("toy.wav")
burp = pygame.mixer.Sound("burp.wav")
tux = pygame.image.load("arm_linux.png").convert_alpha()
fish = pygame.image.load("fish.png").convert_alpha()
tx=280; ty=180; txd=0; tyd=0
bx=600; by=-15
fx=600; fy=random.randint(0,370)
bkcol=[127,212,255]
lives=3; score=0; run = True;
# Draw the surfaces for Tux, Fish and Ball
tuxsurf = pygame.Surface((60,70))
tuxsurf.fill(bkcol)
tuxsurf.set_colorkey(bkcol)
tuxsurf.blit(tux,[0,0])
fishsurf = pygame.Surface((35,30))
fishsurf.fill(bkcol)
fishsurf.set_colorkey(bkcol)
fishsurf.blit(fish,[0,0])
ballsurf = pygame.Surface((60,60))
ballsurf.fill(bkcol)
ballsurf.set_colorkey(bkcol)
ballsurf.set_alpha(128)
pygame.draw.circle(ballsurf,[255,255,255],[30,30],30)
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT: run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT: txd=-4
if event.key == pygame.K_RIGHT: txd=4
if event.key == pygame.K_UP: tyd=-4
if event.key == pygame.K_DOWN: tyd=4
if event.type == pygame.KEYUP:
txd=0; tyd=0
tx+=txd; ty+=tyd
# This part stops Tux from leaving the edges of the screen
if tx<= 0: tx=0
if tx>=540: tx=540
if ty<=0: ty=0
if ty>=330: ty=330
# Make the ball chase Tux
if bx>=tx: bx=bx-1
else: bx=bx+1
if by>=ty: by=by-1
else: by=by+1
fx=fx-4
if fx<=-10: fx=600; fy=random.randint(0,370)
# Collision Detection (Tux & Fish, Tux & Ball)
if fx<=tx+50 and fx>=tx and fy>=ty-30 and fy<=ty+70:
toy.play(); fx=600;fy=random.randint(0,370); score +=1
if bx<=tx+40 and bx>=tx-40 and by>=ty-50 and by<=ty+60:
burp.play(); bx=600; by=-15; lives -=1; tx=280; ty=180
screen.fill(bkcol)
screen.blit(tuxsurf,[tx,ty])
screen.blit(fishsurf,[fx,fy])
screen.blit(ballsurf,[bx,by])
font = pygame.font.Font(None, 20)
text = font.render("Score: "+str(score), 1, (0,0,0))
screen.blit(text, [5,5])
text = font.render("Lives: "+str(lives), 1, (0,0,0))
screen.blit(text, [80,5])
if lives <= 0:
font = pygame.font.Font(None, 120)
text = font.render("GAME OVER!", 1, (255,0,0))
screen.blit(text, [36,150])
pygame.display.update();pygame.time.wait(4000)
lives=3; score=0; tx=280; ty=180
pygame.display.update(); clock.tick(100)
pygame.quit()
Feedback