ISSUE 05 SEP 2012 A Magazine for Raspberry Pi Users Steady Hand Fun With The RaspberryPi Tutorial by Mike Cook Also in this issue Squeezy or Wheezy? DebianDistro'sExamined RaspberryPi Media Centre A Guide To OpenELEC and Raspbmc http://www.themagpi.com Raspberry Pi is a trademark of The Raspberry Pi Foundation. This page was created using a Raspberry Pi computer.
Welcome to Issue 5, This month we have a collection of hardware projects for you, as well as our usual selection of programming articles and general operating tips. We are proud to present an article by none other than Mike Cook , who designed several projects for THE MICRO USER magazine. This magazine had a great influence on many of those who were fortunate to have access to a BBC microcomputer.
Contents 04 STEADY HANDS Are your hands steady enough to beat the Pi? by Mike Cook 07 ENVIRONMENTAL MONITORING Track temperature fluctuations, by Duncan Rowland 1 0 WHAT'S ON GUIDE & COMPETITION Find out where Raspberry Jams' are happening and win a starter kit 1 2 XBMC: RASPBMC AND OPENELEC Get to grips with your media centre setup, by Colin Deady 1 6 SQUEEZE OR WHEEZY Improvements and changes, by Jaseman 1 8 COMMAND LINE CLINIC Learn how to backup important data, by Bobby (bredman) Redmond 20
STEADY HANDS You don't have to get complicated to get a great deal of fun from an interfacing project. Electrically this is just about as simple as you can get, however it has a very good fun to technology ratio. DIFFICULTY: INTERMEDIATE Steady hands is a very old game; however, with a Raspberry Pi we can give it a new twist. The idea is that you have to guide a wire loop along a bendy wire without letting the two touch.
7. Solder a length of normal wire (insulated) to each end stop. 8. On each end of the 'bent coat hanger / wire' and both rests, from where they hit the block of wood, tape them with insulated electrical tape 4 cm high. The following table and image show how each part of the 'STEADY HAND' attaches to each pin of the Pi GPIO via the 2.
# python3 # Steady hands game import RPi.GPIO as GPIO import time # use BCM GPIO numbering use anything else and you are an idiot! GPIO.setmode(GPIO.BCM) # set up GPIO input pins # (pull_up_down be PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF) GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO 0 & 1 have hardware pull ups fitted in the Pi so don't enable them GPIO.setup(0, GPIO.IN, pull_up_down=GPIO.PUD_OFF) GPIO.setup(1, GPIO.IN, pull_up_down=GPIO.
DIFFICULTY: INTERMEDIATE This article builds on topics from previous issues of The MagPi and shows how to add a temperature sensor to your Pi together with a simple method to record and display the data on the web. The temperature sensor used is the ‘tmp1 02’ (http://www.ti.com/product/tmp1 02) and connects via the i2c bus (i.e. the same way Rob McDougall connected his accelerometer in last month's issue). The temperature sensor is readily available already mounted on a breakout board from sparkfun.
Wiring Connections: Tmp102 GND SCL SDA V+ ALT ADD0 Pi GPIO PIN 06 (Ground) PIN 05 (I2C0_SCL) PIN 03 (I2C0_SDA) PIN 01 (3V3 Power) leave disconnected GND awk '{printf("%.2f\n", (a=( \ "0x"substr($1,5,2)substr($1,3,1))*0.0625 \ )>1 28?a-256:a)}' Now you should be able to communicate with the device: i2cget y 0 0x48 0x00 w This will read the value in address (0x48) on I 2C bus (0) which is the current value of the sensor.
top-right corner in a drop-down menu next to your name) and click “+ Key”. Choose a label and leave the Feed Restrictions as the default “Use any public feed” and Access Privileges can be set to all. The key that is generated is a long string of characters and this is required to authenticate updates. In the “update.sh” script below you should put this value where I have left ZZZZZ. The COSM server expects data in a specific format. Save the following in a file called “blank.
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 Raspberry Pi calendar for the month ahead. Are you in charge of running a Raspberry Pi event? Want to publicise it? Email us at: editor@themagpi.com E-DAY @ GATESHEAD When: 29th September 201 2 Where: Gateshead Library Makerspace Newcastle will deliver a Raspberry Pi intro/workshop.
SEPTEMBER COMPETITION This month The MagPi and PC Supplies Limited are proud to announce yet another chance to win some fantastic Raspberry Pi goodies! First prize will recieve the following: Limited Edition MagPi Case HDMI Cable Power Supply Audio Cable Video Cable GPIO Cable Network Cable 32GB SDHC Card with Raspbian With two runners up winning a MagPi engraved case! For a chance to take part in this month's competition visit http://www.pcslshop.com/info/magpi Closing date is 20th September 201 2.
XBMC Media Center: OpenELEC and Raspbmc A low power Raspberry Pi media centre equipped with HDMI and capable of high definition 1080p output. As more people are looking to access their media catalogue via their computer or TV without the use of physical media, the freely available XBMC is an ideal solution. XBMC is known as a 1 0-foot GUI: you can comfortably sit on your sofa across the room and clearly view the user interface on your television.
pre-compiled image. Building OpenELEC from source may well seem complex but it is worth attempting if you have not compiled and installed an operating system before as it is a great worked example that yields a genuinely useful result. Raspbmc installs from a downloadable Python program (see Useful Links) on Mac OS X and Linux. On Windows executing the installer.exe is the equivalent.
that XBMC provides access to greatly increases the media centre's capabilites. Installing Raspbmc extra software on Installing additional software on Raspbmc outside XBMC is possible. As noted earlier care should be taken not to install too many resource hungry services that may impact on the performance of XBMC. Backup the SD card before installing extra software by using the dd command (instructions for this are easy to find with a Google search).
your Raspberry Pi can be connected via either wired or wireless ethernet meaning line of sight is not required unlike infrared. Configure as follows: - On the Raspberry Pi select Settings / Services / Remote control and enable the two "Allow programs" options. Under Settings / Services / Webserver select "Allow control of XBMC via HTTP" and set both a username and password. This will permit the smartphone to make the connection. - On the smartphone tap Menu / Settings / Manage XBMC Hosts / Menu / Add Host.
SQUEEZY OR WHEEZY? Debian Distro's Examined In this article I look at the differences between the Debian 6 (Squeeze) and Debian 7 (Wheezy) distributions. SQUEEZE (Debian 6) SPEED Things are very slow - particularly if you are attempting to run larger apps such as Scribus. STABILITY Squeeze would randomly freeze or completely lock up requiring a reboot.
WHEEZY (Debian 7) SPEED Everything runs MUCH quicker under Wheezy. STABILITY With Raspbian Wheezy the random freezing seemed to have been fixed. IMAGING AND PARTITIONING After imaging Wheezy onto the SD Card, the primary partition can be resized easily using an in-built tool that autoloads the first time you run the Operating System. You are confronted with a menu which allows you to easily configure a number of settings.
Linux commands can be joined together to create scripts. These scripts allow you to create programs which can be just as powerful as any other programs on the Raspberry Pi. Scripts can be very useful to hold commands that you need to type regularly. It can be very inconvenient to have to type the same command again and again, especially if the command is long and complex. Let's take an example of a useful command that you may need to enter regularly.
Remember, if the list of files is long, you can pipe the result through the "less" command: bash backup | less You can move through the list with the up/down arrow keys or Page Up/Page Down keys. Press the Q key to quit. The last step is to make this script an executable file. This will allow you to run the script without putting "bash" before the name. To make the file executable, enter the command: This turns on (+) the executable (x) permission for this file.
A place of basic low-level programming Tutorial 3 - Functions, pointers and files. How did you get on with the challenge problem? Let us take a quick look at the solution before continuing . Challenge solution #include
the compound statement within {} as long as the condition between the parentheses () is true. The new function can now be used in a program, #include unsigned int factorial(unsigned int x); int main() { unsigned int i = 3; /* Declare an int and assign it the value three. */ printf("%d! = %d\n",i,factorial(i)); /* Print factorial of i */ return 0; /* Return success to the operating system.
Pointers can also be used together with arrays, #include int main() { int i, *p, arr[4] = {6,2,4,7}; p = &arr[0]; /* Assign the address of the first element to p */ for(i=0;i<(sizeof(arr)/sizeof(int));i++) { printf("arr[%d]=%d\n",i,*p); p++; /* Increment the address by sizeof(int) */ } return 0; /* Return success to the operating system. */ } The name of an array is also a pointer.
fprintf(filePtr,"Writing out some important data...%d, %d, %d\n",2,3,4); When the file access has been completed it has to be closed, flushing any data in memory to the disk, fclose(filePtr); /* Close textFile.txt, flushing data to disk */ The final example program uses many of the concepts discussed so far to provide a simple encryption algorithm , #include int main(int argc, char *argv[]) { int mask = 163; /* Declare an int and assign it with a value less than 256.
Make a "Simon" Memory Game! This month we are going to use Scratch to make a memory game based on the classic toy: "Simon". If you've never heard of it, ask your parents (or grandparents! ). It's a simple game. Simon plays four notes and you have to repeat them in order. If you get it right, you get another sequence with more notes to remember - and it goes faster each time! The original "Simon". First, make four quarter-circle sprites.
The Scripts These scripts control a sprite that is just a button with "New Game?" written on it. This is the main script that controls the game! I gave it to the yellow segment sprite, but it doesn't really matter which sprite owns it. Each segment sprite will need these scripts. You'll need to vary the numbers for the notes. I used: 60, 62, 65 and 67.
RasPiThon 2012 The Story Behind The Marathon On Friday 20th July, four teenagers set out on a 48-hour coding marathon, learning Python as they wrote a game called 'Rasperroids', and raising money for the Raspberry Pi Foundation. Why did we do it? After watching Mario marathon 5 I decided that I would like to do a marathon for charity, but most computer games had been covered in previous marathons, and almost all of them donate to Child's Play.
This month we show you a method of creating a gradient fill, to add depth to flat looking rectangles. We also show how to use transparency effects to change the shape of gradient filled surfaces, how to plot points of a circle, as well as some cool examples of why you would want to do so. # GRADIENT FILL # By Jaseman 8th August 2012 import os, pygame; from pygame.locals import * pygame.init(); clock = pygame.time.Clock() os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' pygame.display.
# MOUNTAINS # By Jaseman 18th August 2012 import os, pygame; from pygame.locals import * pygame.init(); clock = pygame.time.Clock() os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' pygame.display.set_caption("Mountains") screen=pygame.display.set_mode([600,382],0,32) sky = pygame.Surface((600,255)) r=0; g=64; b=128 for l in range (0,255): pygame.draw.rect(sky,(r,g,b),(0,l1,600,l)) r=r+1;g=g+1;b=b+1 if r>=255: r=255 if g>=255: g=255 if b>=255: b=255 ground = pygame.
# POINTS OF A CIRCLE # By Jaseman 21st August 2012 import os, pygame; from pygame.locals import * from math import sin, cos, pi pygame.init(); clock = pygame.time.Clock() os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' pygame.display.set_caption("Points Of A Circle") screen=pygame.display.set_mode((600,600),0,32) background=pygame.Surface((600,600)) background.fill((0,0,192)) dot=pygame.Surface((8,8)) pygame.draw.circle(dot,(255,255,255),(4,4),4,0) dot.set_colorkey([0,0,0]) screen.
# CIRCLE DEMO # By Jaseman 22nd August 2012 import os, random, pygame; from pygame.locals import * from math import sin, cos, pi pygame.init(); clock = pygame.time.Clock() os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' pygame.display.set_caption("Circle Demo") screen=pygame.display.set_mode((800,600),0,32) bk=pygame.Surface((800,600)); bk.fill((0,64,0)) dot=pygame.Surface((4,4)); dot.set_colorkey([0,0,0]) pygame.draw.
pdl(bk,[rcol,gcol,bcol],(bgcx[b]+cx 2,cy+bigradius+10),(smcx[b]+cx2,cy+bigradius+30)) pdl(bk,[rcol,gcol,bcol],(cxbigradius14,bgcy[a]+cy2),(cx bigradius34,smcy[a]+cy2)) pdl(bk,[rcol,gcol,bcol],(cx+bigradius+14,bgcy[b]+cy 2),(cx+bigradius+34,smcy[b]+cy2)) # Ellipse (Big and Small Radius points mixed) screen.blit(dot, (bgcx[a]+cx2+bigradius+160,smcy[a]+cy2)) screen.blit(dot, (smcx[a]+cx2bigradius160,bgcy[a]+cy2)) screen.blit(dot, (cx2+bigradius+160,cy2)) screen.
Feedback Just wanted to say great mag. I read it page to page. I am aged 45 and think your mag is good for anyone. I went out and purchased a robot to follow the Skutter series. I was a bit disapointed not to see it in issue 4, but I hope it will be in the next one. Please keep up the good work - I look forward to the next issue. What a great magazine. This should be required reading for Pi owners. Adam I'd just like to say that I love it! Keep up the good work chaps. Scep I think it's great.