Archive for January, 2014

Coding on an iPad with Codea app by @TwoLivesLeft

Posted: January 30, 2014 by schoolpiclub in General News

Check out ‘Pi in the Sky’ game, coded on an iPad using an app called Codea by TwoLivesLeft


Here is a short video clip

Raspberry Pi – Lucky Dip and Random Name Picker

Posted: January 27, 2014 by schoolpiclub in General News

This week we are hoping for a lottery win from our Raspberry Pi Lucky Dip!

Students had to guess the programme as the code was being input – well done to NJ who guess correctly. Here is the code we used:-

import random

nums = []

balls = [i for i in range(1,49)]


nums = balls[:6]

print(“Here are your ‘lucky dip’ numbers:”)


print(“Remember to split any winnings with me!”)


We then looked at adapting the code to have a Random Student Name Picker. Here is the code for that programme:-


import random

names = []

students = [‘name1′,’name2′,’name3′,’name4′,’name5′,’name6′,’name7′,’name8′,’name9′,’name10’]


names = students[:2]


print(“Here are your ‘lucky dip’ students:”)


print(“Good luck!”)


JW Raspberry Pi Guide

Posted: January 19, 2014 by bungleofhay in General News

Today, I have setup a website which is a guide to the Raspberry Pi. I have only just started it so it doesn’t have much content at this present moment. Please use the hashtag #RPiGuide on Twitter to spread the word.  The URL is

This weekend I thought I would try to set up my Raspberry Camera and try to take photos remotely.

Firstly I install the iOS BerryCam app onto my iPhone, and typed the ip address for my Raspberry Pi into the app.

berrycam 2



I then created a file on my Raspberry Pi using the following code:-

#!/usr/bin/env python
#  BerryCam - Raspberry Pi Camera Controller for use with iOS devices
#  Created by James Moore on 22/05/2013.
#  Copyright (c) 2013 Fotosyn. All rights reserved.
#  Raspberry Pi is a trademark of the Raspberry Pi Foundation.
#  IOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used by Apple Inc. under license.

import SimpleHTTPServer, SocketServer
import urlparse
import os

PORT = 8000 # CHange this if you wish to listen on a different port

class BerryCamHandler (SimpleHTTPServer.SimpleHTTPRequestHandler):

   def do_GET(self):

       # Parse query data
       parsedParams = urlparse.urlparse(self.path)
       queryParsed = urlparse.parse_qs(parsedParams.query)

       # Add 'berrycam' prefix to URL to perform query
       if parsedParams.path == "/berrycam":

          awb = "'" + queryParsed['awb'][0] + "'" # Set AWB mode
          mm = "'" + queryParsed['mm'][0] + "'" # Set metering mode
          ev = queryParsed['ev'][0] # Set EV compensation
          ex = "'" + queryParsed['ex'][0] + "'" # Set exposure mode
          sh = queryParsed['sh'][0] #  Set image sharpness 
          br = queryParsed['br'][0] # Set image brightness
          co = queryParsed['co'][0] # Set image contrast
          sa = queryParsed['sa'][0] # Set image saturation
          #iso = queryParsed['iso'][0] #  Set capture ISO - NOT YET IMPLEMENTED        
          ifx = "'" + queryParsed['ifx'][0] + "'" # Set image effect
          #cfx = "'" + queryParsed['cfx'][0] + "'" # Set colour effect - NOT YET IMPLEMENTED IN BERRYCAM
          #rot = queryParsed['rot'][0] # Set image rotation - NOT YET IMPLEMENTED IN BERRYCAM
          filequality = queryParsed['fquality'][0]
          filewidth = queryParsed['fwidth'][0]
          fileheight = queryParsed['fheight'][0]
          filefolder = queryParsed['ffolder'][0]
          fileseq = queryParsed['fseq'][0]
          hflip = queryParsed['hf'][0]
          #exifmake = queryParsed['exifmake'][0]

          #filewidth = 2592 #- ((2592/4)*filesize) # Take the values passed, divide by 4 and multiply to get new size
          #fileheight = 1944 #- ((1944/4)*filesize) # Take the values passed, divide by 4 and multiply to get new size

          #Exposure mode options :

          #AWB mode options :

          #Image Effect mode options :

          #Metering Mode options :

          directory = 'berrycam/' + str(filefolder)
          if not os.path.exists(directory):

          # Build up a raspistill command line string
          command = "raspistill -v" # Initiate command for Raspicam
          command += " -awb " +   str(awb) # Define WB
          command += " -mm " +   str(mm) # Define Metering Mode
          command += " -ev " + str(ev) # Define the Exposure Adjustment
          command += " -ex " +   str(ex) # Define Exposure Mode
          command += " -sh " + str(sh) # Define Image Sharpness
          command += " -br " + str(br) # Define Image Brightness
          command += " -co " + str(co) # Define Image Contrast
          command += " -sa " + str(sa) # Define Image Saturation
          #command += " -ISO " + str(iso) # Define Image ISO - NOT YET IMPLEMENTED          
          command += " -ifx " +   str(ifx) # Define Image Effect
          #command += " -cfx " +   str(cfx) # Define Colour Effect - NOT YET IMPLEMENTED IN BERRYCAM
          #command += " -rot " +   str(rot) # Define Image Rotation - NOT YET IMPLEMENTED IN BERRYCAM
          command += " -q " + str(filequality) # Define Image Quality
          command += " -w " + str(filewidth) # Define output image width
          command += " -h " + str(fileheight) # Define output image height
          #command += " -o /berrycam/" + str(filefolder) + "/IMG-" + str(fileseq) +".jpg" 
          command += " -o berrycam/" + str(filefolder) + "/IMG-" + str(fileseq) +".jpg" 
          #command += " -x IFD1.Make=" + str(exifmake)  #Define Make for ESIF Data 'Raspberry Pi'

          if hflip == "1":
              command += " -hf "
              command += ""


          # Default to serve up a local file 

   def processRequest(self, query):


httpd = SocketServer.TCPServer(("", PORT), BerryCamHandler)

print "B E R R Y C A M -- Listening on port", PORT
print "Please ensure your BerryCam App is installed and running on your iOS Device"


Using terminal I typed the following command

sudo python /home/


My Raspberry Pi was plugged in in another room in the house but I was able to connect to the camera remotely using the BerryCam app.

For more information on the set up of the BerryCam app  visit 





Maths and Raspberry Pi – Times Tables using Python

Posted: January 13, 2014 by schoolpiclub in General News

Today we looked at a Times Tables quiz using Python.

The quiz simply asks 10 random Times Tables questions and tells the students if they have got it right or wrong as they go along. At the end it gives them their score out of 10.


Here is the code (please note use IDLE and not IDLE3):-

from random import randint
correct = 0
for i in range(10):
    n1 = randint(1, 10)
    n2 = randint(1, 10)
    prod = n1 * n2
    ans = input(“What’s %d times %d? ” % (n1, n2))
    if ans == prod:
        print “That’s right — well done.\n”
        correct = correct + 1
        print “No, I’m afraid the answer is %d.\n” % prod
print “\nI asked you 10 questions.  You got %d of them right.” % correct
print “Well done!”

We then looked at how we could modify the code, for example, what if a student just wanted to learn their 8 times tables. So TW changed the fifth line of code to n2 = 8 the quiz then just asked 8 times tables questions – which he got every single one right! We then looked at other things we could modify. We changed the code to ask addition questions between 1-50, and we also increased the number of questions asked.


We are hoping to further develop the quiz by personalising it to say the students name or randomly pick a student to answer the question so that the quiz can be used in Maths lessons.

So a Raspberry Pi is not just about learning computing and coding it can help improve your numeracy skills. Maybe a literacy challenge should be next!

Learning Times Tables on a Raspberry Pi

Posted: January 12, 2014 by schoolpiclub in General News

During tomorrow’s School Pi Club we shall be looking at some python code that will help students practice their Times Tables.

When the program is run it will ask 10 random times tables questions and tell students how they are doing as they go along and keep score.

Stay tuned to find out how we get on.

VNC Starting Automatically on Raspberry Pi

Posted: January 12, 2014 by schoolpiclub in General News


We previously posted about how to connect to your Raspberry Pi via an iPad using VNC. See post

The only thing was the VNC did not start automatically when booting up the Raspberry Pi. This weekend I have been configuring my Raspberry Pi so that it started the VNC server automatically. This meant that I can just plug my Raspberry Pi in anywhere at home  – no need to connect to a TV to monitor – and then either use my iPad, Macbook or a PC to remote connect to it to control it.

Once you have set up the ‘tightvncserver’ from our previous post, this is how to config VNC to start automatically.

Start VNC automatically

Create startup file
The first thing you need to do is create the file that will actually start VNC on startup using Terminal directly from the Pi.

Type the following:
sudo nano /etc/init.d/tightvncserver

NOTE: nano is a lightweight editor – the command above will create a new file called tightvncserver in the /etc/init.d directory and open it for editing.
Once you have the file open, paste in the following:

# First configure the user you want to run this under – this will generally be pi, unless you’ve created your own users
export USER=’pi’

eval cd ~$USER

# Check the state of the command – this’ll either be start or stop 

case “$1” in
    # if it’s start, then start vncserver using the details below
    su $USER -c ‘/usr/bin/vncserver :1 -geometry 1280×800 -depth 16 -pixelformat rgb565’
    echo “Starting vncserver for $USER “
    # if it’s stop, then just kill the process
    pkill Xtightvnc
    echo “vncserver stopped”
    echo “Usage: /etc/init.d/vncserver {start|stop}”
    exit 1
exit 0

NOTE: In the file I’ve specified my own resolution with the text -geometry 1280×800 – you can leave this out of you want

To exit, press Ctrl+X.  You’ll be prompted to save – just type Y
You’ll be prompted to confirm the filename – just press Enter

Set file properties
Once that’s done make sure the file has the right properties by typing the following:
sudo chmod 755 /etc/init.d/tightvncserver

NOTE: Important to do this step every time you modify this file.

Add File to startup sequence
And now just add your file to the list of startup actions by typing the following:
sudo update-rc.d tightvncserver defaults

And that should be it!  Just restart, and you should be able to VNC straight in!


I use Mocha VNC Lite on my iPad to connect and on my Mac I use RealVNC Viewer available to download from


A useful PDF document which includes the settings for RealVNC Viewer can be found here