The MagPi Issue 1 - Raspberry Pi
The MagPi Issue 1 - Raspberry Pi
RacyPy
Debian
Scratch
Python
Introducing...
The
Raspberry Pi
A new breed
of computer
NO MORE
APPLES
FOR
TEACHER!
hhttttpp::///wwwwww..tthheem
maaggppii..ccoom
m
Contents
Affordable Computing
The Fall Of Programming
The Pioneers
Hardware Development
Skutter
RacyPy LiveCD & Virtual Machine
P.04
P.05
P.06
P.09
P.10
P.12
Debian VirtualBox
Programming
The Scratch Patch
The Python Pit
Feedback
Web Links & Credits
P.16
P.18
P.20
P.23
P.30
P.32
The Dawn Of
Affordable
Computing
The ZX81 and Spectrum by Sinclair
Research, were among the first
affordable home computers available
during the early 1980's.
Although these 8bit computers were
crude by today's standards, they gave
ordinary people the opportunity to
write computer programs and games.
The BBC Acorn computer was
backed by the British Government
for use in education and subsidies
were granted to schools. These
computers were a little too expensive
for most families to have at home.
The 'Electron' was Acorn's attempt at
addressing the price issue. They sold
a number of units, however despite
being more powerful on the hardware
side, the range of game titles was
significantly smaller than rivals
Sinclair and Commodore.
The Fall Of
Programming
The Pioneers
The story of how the Raspberry Pi computer came to be.
Article by Jaseman
H a r d wa r e D e ve l o p m e n t a n d R o b o t i c s
Gert van Loo has developed a General
Purpose Input/Output (GPIO) expansion
board for the Raspberry Pi, called the
Gertboard. The board is able to control
flashing light-emitting diodes (LEDs),
and connect to servo motors, sensors
and other electronic components.
SKUTTER
By Bodge N Hackitt
10
11
What is RacyPy?
Get Ready!
SeaMonkey - web-browsing
12
the
guide
from
http://goo.gl/S4VTI but instead of
"Lucid Puppy" select "Racy Puppy".
Then press "browse" to RacyPy4_1 .iso
you downloaded above. If you don't
see it, try ensure you have named it
with racy at the start of the filename.
LiveCD Boot
The simplest way to use this image is
to "burn" the "image" to a CD. You can
use your own software or you can use a
free program called ImgBurn, which will
ensure the CD is written correctly to
allow it to boot.
ImgBurn - http://www.imgburn.com
Once you have
installed
the
software, you
can right click
on the iso file and select Burn using
ImgBurn. Alternatively, run the
program and select, Write Image
File To Disc and select the iso file
(File ->Browse for a source file).
Virtual Machine
A really useful way to try out Linux
is to use a virtual machine (VM). A
VM is simply a simulated computer
which runs on top of whatever
operating system you are using.
This means you can run this virtual
computer in a window alongside
your other windows, and everything
to do with it is contained within a
few files separate to your normal
operating system. When you are
done, you can simply remove them!
To run RacyPy we recommend using
VMPlayer, which can be obtained
from http://www.vmware.com or
directly from http://goo.gl/8oKED.
13
14
VMPlayer Tips:
1 . To control the VM, click in the
window to capture your mouse and
keyboard, then press Ctrl+Alt to
release.
2. If you use a USB Flash Memory
to store your user data, next time
you run the VM it will remind you to
re-attach your key if it is missing!
First Boot
When you boot for the first time, you will
be able to configure your setup. Puppy
allows you to store all your user data
conveniently on a USB memory device
so it is available next time you boot
(regardless of which machine you are
using).
choose filesystem
save-file name
encryption
size save-file
sanity check
Select "administrator"
Plug the USB memory
device in*
Select "ext2"
Leave blank
Select NORMAL
Select 51 2MB**
Should match below!
NOTES:
*If using a VM, you may need to click
on the device icon at the bottom of
the window (next to VMWare logo). If
successful you will see the following
icon appear on the desktop.
**The remaining space can then be accessed
and used by both Linux and Windows.
***On the 1 st boot after this, you may be
asked about adding "BootManager:SFS files".
Press ok for now, we will cover this another
time.
Optional "Pets"
Installing Pets
http://raspberrypy.tumblr.com
Article by meltwater
15
2. Click 'New'
3. Click 'Next' to start the 'New Virtual Machine Wizard'
8. Click 'Create'
5. Memory: 256 MB
16
http://goo.gl/gLmjf
Article by Jaseman
17
>Programming
Computer
programming
or
'coding' is a method of getting a
computer to perform tasks, such
as displaying and processing
information, creating games and
applications
or
controlling
devices, motors or robots.
The computer can interpret our
commands through programming
languages, which help to make the
processes of instructing the computer
easier.
When we 'run' a computer program,
the computer starts to carry out our
instructions step by step and reacts to
'events'. We can tell the program how
it should deal with certain events. For
example, your program might be
instructed to sense events such as a
18
Article by Jaseman
All logos and trademarks remain the property of their respective owners.
'JavaScript is a prototype-based
scripting language that is dynamic,
weakly typed and has first-class
functions. It is a multi-paradigm
language, supporting object-oriented,
imperative,
and
functional
programming styles.'
<HTML>
There
are
many
other
programming
languages
available to try. We will try to
introduce some of them. Feel
free to submit your own
programming articles.
19
Here at The MagPi, we highly recommend you to try out 'Scratch' - An easy to use
programming language for beginners. If you don't already have Scratch, you can
download it from the following website:
http://info.scratch.mit.edu/Scratch_1.4_Download
Once you have it installed and running, the best way to get started is to click on the
Help pull-down and take a look at the Help Page and Help Screens. Most of the
information you will need is already there. Spend some time familiarizing yourself with
the scratch interface - It is very intuitive. Then try our Dizzy Cat / Crazy Drum tutorial on
the following pages.
20
8. Change the '15' in 'turn 15 degrees' to '5' and change the '10' in change size by 10'
to '-1'. See how the cat starts spinning in
the other direction and slowly starts to
shrink.
21
By Jaseman
22
Note: The examples in this issue are written for Python 3. They will work on older versions by making a
change to all the print commands: Change print ("TEXT") to print "TEXT" remove the ( ) brackets.
# PUTTING TEXT ONTO THE SCREEN
# By Jaseman 23rd April 2012
# ARITHMETIC
# By Jaseman 23rd April 2012
print("Two plus two equals ",2+2); print()
print("Eight minus three equals ",83); print()
print("Four times two equals ",4*2); print()
print("Ten divided by two equals ",10/2); print()
23
In this example we use the 'INT()' function to remove the decimal places in the answer. The
number is rounded to the nearest whole number. INT is short for Integer - another word for a
whole number.
# SPARE ME THE DETAILS
# By Jaseman 24th April 2012
print("Seven divided by three is",7/3); print()
print("Seven divided by three is roughly",int(7/3)); print()
print("Five divided by two is",5/2); print()
print("Five divided by two is roughly",int(5/2)); print()
Using variables, we can get our program to remember numbers and words that it can use later on.
You may remember doing this sort of thing in school.
# ALGEBRA
# By Jaseman 24th April 2012
a = 3
b = 7
c = 4
print("A is equal to",a); print()
print("B is equal to",b); print()
print("C is equal to",c); print()
print("A plus B equals",a+b); print()
print("A plus B plus C equals",a+b+c); print()
print("A plus B minus C equals",a+bc); print()
24
As well as numbers, variables can be words. We call these 'strings' because they are a string of
alphanumeric characters strung (or grouped) together.
# STRINGS OF WORDS
# By Jaseman 24th April 2012
a = "If you"
b = "notice"
c = "this"
d = "you will"
e = "is not worth"
f = "noticing!"
print(a,b,c,b,d,b,c,b,e,f); print()
It is possible to count in steps too. Try changing the for command as follows:
for n in range(0,1 00+1 ,5):
This counts up to a hundred in increments of five. We can even do it in reverse:
for n in range(1 00,0-1 ,-5):
(continued over page...)
25
The WHILE LOOP continues until a certain criteria is met. In this program the number (n) starts off
as zero. It keeps increasing by 1 for as long as the number is less than or equal to the value of ten
(<=1 0).
# COUNTING WITH WHILE LOOPS
# By Jaseman 24th April 2012
n=0
while n <= 10:
print (n)
n += 1
To achieve the incremental steps in the counting, change the n += 1 to a higher number. Counting
in reverse could be done like this:
n=1 0
while n >= 0:
print (n)
n -= 1
# LOTTERY NUMBERS
# By Jaseman 24th April 2012
import random
for n in range(1,6+1): # We want six random numbers
print (random.randint(1,100)) # Picks a number between 1 and 100
26
This time, the WHILE LOOP keeps generating random numbers until it finds a number '1 3'. The
operator '!=" means 'not equal to', in other words keep looping while it's any number but thirteen.
# BINGO!
# By Jaseman 24th April 2012
import random
n =0
for n in range(0,5):
print (mytext[n])
print()
27
This game will take a bit more typing, but it is a good example of what the Pygame library can do.
Don't worry if you do not understand all of the commands. We will be covering these in more detail
in the next issue. Note: You will need a mouse connected to your computer to control the bat.
# BAT AND BALL
# By antiloquax 28th April 2012
import pygame
from pygame.locals import *
pygame.init()
# set the width and height of the screen
size = [400, 400]
screen = pygame.display.set_mode(size)
# give the window a title
pygame.display.set_caption("Bat and Ball")
# This makes the normal mouse pointer invisible in graphics window
pygame.mouse.set_visible(0)
# create surfaces for the bat and ball
bat_surf = pygame.Surface((64,12))
bat_surf.fill((0,255,0))
batrect = bat_surf.get_rect()
ball_surf = pygame.Surface((30,30))
ballrect = ball_surf.get_rect()
ball = pygame.draw.circle(ball_surf, (0,0,255),[15, 15], 15)
# set speed of ball
speed = [3, 3]
# puts the bat centre of screen, near the bottom
batrect.center = ((size[0]/2), (size[1] 50))
# make a text object
font = pygame.font.Font(None, 36)
text = font.render("Game Over", True, (255,0,0))
textRect = text.get_rect()
textRect.centerx = (size[0]/2)
textRect.centery = (size[1]/2)
# loop until the user clicks the close button
done=0
# create a timer to control how often the screen updates
clock = pygame.time.Clock()
# main game loop
while done == 0:
screen.fill((0,0,0))
# event handling
for event in pygame.event.get(): # if we click something ...
if event.type == pygame.QUIT: # if we click close ...
done=1 # this will cause the loop to finish.
28
Make sure to observe UPPER and lower case text, for example:
.font.Font
.Surface
.Clock
Try altering the '# set speed of ball' section:
Eg: speed = [5,5]
You can also alter the width and height of the screen.
Let us know how you get on with these programs. We will bring you some more Python and
Pygame examples in Issue 2.
29
Feedback
'Magazine has to be
done.'
SN
'The magazine is
looking great. There is
certainly a need for this
sort of
'step by step' guide.
Keep up the good
work!'
Montala
'Hi Guys... I'm
education coordinator
for the Foundation and
(at the moment) the
only employee. The
MagPi is a great idea!.'
Myra
'Exciting! We're very
happy to see you guys
doing this, and we're
looking forward to
seeing what you come
up with.
Thanks for letting me
know about it.'
30
Liz
Raspberry Pi is a trademark of the Raspberry Pi Foundation. The MagPi magazine is collaboratively produced by an
independent group of Raspberry Pi owners, and is not affiliated in any way with the Raspberry Pi Foundation. The
Magpi does not accept ownership or responsibility for the content or opinions expressed in any of the articles included
in this issue. All articles are checked and tested before the release deadline is met but some faults may remain. The
reader is responsible for all consequences, both to software and hardware, following the implementation of any of the
advice or code printed. The MagPi does not claim to own any copyright licenses and all content of the articles are
submitted with the responsibility lying with that of the article writer.
31
editor@themagpi.com
http://www.themagpi.com
Official website of The MagPi magazine.
http://www.raspberrypi.org
Official home of the Raspberry Pi Foundation.
http://elinux.org/R-Pi_Hub
Wiki hub for the Raspberry Pi computer.
http://www.youtube.com/RaspberryPiTutorials
Video tutorials and python / pygame programming examples by Liam Fraser.
http://www.raspberrypi.org/forum/educational-applications/jasemans-python-lessons
Python / Pygame tutorials by Jaseman.
http://www.python.org
Official site for the Python programming language.
http://www.debian.org
Homepage for the Linux Debian Operating System.
Ash Stone
Photographer / Graphics
Bodge N Hackitt
Writer
antiloquax
Python Tutor