Thursday, 19 May 2016

Hack the Teacher - A lesson in physical computing using a Raspberry Pi Zero Christmas Jumper

Just before Christmas I had some fun with a Christmas Jumper and Physical computing based around the (then) new Raspberry Pi Zero. Here is the rather belated write up of the lesson.



I was not quick enough to get hold of a Magpi issue 40 when they were first in the shops so I subscribed and waited for it to be delivered to my door. Initially I didn't really know why I wanted the attached free Raspberry pi Zero, I just knew I wanted one.

The Jumper


However when it arrived inspiration arrived with it and I decided I needed to make a Christmas jumper and that it would be a really good tool to get some of my students interested in programming. I came up with a simple plan of a Christmas tree with some lights and set about creating the base for the project.

This was all going well apart from two factors; I now only had a weekend to complete the project to be able to use the jumper in lessons (before the end of term), and my inability to sew.

Not one to be daunted I found some felt and cut out the basic shapes then had a crash course from my wife on how to attache them using needle and thread. So I eventually (after a late night sewing) managed to attache the tree using a simple running stitch in the centre of the tree and then added blanket stitch around the edge to secure it in place (and add decoration). From a distance the effect was relatively respectable. (if you look closely you can see that the quality of my blanket stitch improves as it goes around)

The second evening I spent setting up the electronics. I played with a couple of different configurations but in the end decided on individually programmable LEDs. Each LED is connected to a separate pin on the Pi Zero and to Ground. This left maximum flexibility in what could be done with the lights.


I had initially thought about hiding all the connections inside the jumper but as I was putting it all together I quite liked the idea of it all being visible. To this end all of the wiring was attached to the front of the jumper and the Pi Zero itself was sewn onto the jumper. I also used a portable USB power supply to allow me to walk around without being tethered to a plug socket.





After getting it all wired up I connected the PiZero up to a monitor and set about creating a test program that would show the lights on the tree working. It could also be used as a starting point for the students to modify the existing code to create their own sequences. To make it a little easier I set up a few functions that set groups of light as on or off and the made a short sequence using the functions. I set this up to start on boot so I could just connect the power and the light sequence would start.





The video shows one of the LEDs had failed but this proved to be a loose wire that was hastily soldered up and everything was up and running.

The Lesson

The idea for a lesson using the jumper was inspired by last years code.org hour of code which had students programming a sequence of lights for Christmas trees outside the Whitehouse.

The plan was to explain how the GPIO library is used to turn the lights on and off and then let the students view the code for the existing sequence before coming up with their own code to control the jumpers LEDs.

Preparation

To allow students access to the PiZero I needed to connect it up to the school network. The plan was to do this over wireless with a USB wireless network adapter. (in reality I had problems getting onto the school WiFi network so I took off the jumper and used a wired adapter instead) The students could then login to the PiZero using SSH and use nano to create their programs.

The students downloaded putty to their workstations in order to do this.

Introduction
Demonstration of the jumper working

Explanation of GPIO Library commands to control the LEDs (including the functions I created earlier)

Main Activity
Students to design an algorithm for the light sequence

Students to use python and the GPIO library to program the sequence - this was done by logging in over SSH using putty and copying the basic file (including the functions and GPIO setup) giving it their own name.

Students test the code on the jumper - this required a bit of co-ordination to ensure we only ran one script at a time.

Extension
Able students create their own functions that they can reuse in their sequence.


Plenary
Demonstration of some of the best (aesthetically) sequences

Discussion about code efficiency and creation of functions to avoid duplication of code


Review

The lesson went well with a good deal of enthusiasm generated by the idea of 'hacking the teacher' the students were initially very overly excited by downloading putty and being able to log in remotely to the Raspberry Pi on my jumper.

The students were fairly quick to be able to get a short piece of code working (mostly just a single flashing LED) and then move on to experimenting with using the functions I had built.

At this stage there was a good deal of discussion about what they could do that would be amusing (fortunately I had thought of this at the design stage and I think I managed to avoid any embarrassing light combinations of a phallic nature, or at least they didn't find any during the lesson). Once they had discovered they could not create anything rude they settled for pretty and started to compete on who could create the best sequence.

There was lots of experimentation of how fast they could get lights to flash or change and with what sort of changes looked good. Some of this was a little held up by the fact that there was only one jumper so students occasionally had to wait for someone else to test their code before they could run theirs. It might have been good to have some breadboard prototypes for testing to reduce some of the waiting but i feel that that may have spoiled the interest provided by making the code run on my jumper. This would have been even better if we could have got on over wireless and I could have been walking around the room whilst they were testing their code on me but this was a small niggle.

Overall the lesson was a great success with students engaged in creating code and experimenting to see what they could do as they learnt more about how the Library worked. There were some great creative responses and some good use of functions with parameters for time that could be reused at different points in the code.

If i did this again with another class I would probably use the GPIO Zero library to reduce the code required to get things working but with students staring by using my example code they had a reasonable start anyway.


The rest of the day as I walked around school I did spend alot of time assuring students (and some staff) that "No it's not a bomb" (it was just after Ahmed's clock incident) and "No I won't catch fire". However I did get several question about how it was made and could they make one too, so hopefully some more students aware of the possibilities of computing.

Wednesday, 3 February 2016

BETT 2016 - Raspberry Pi physical computing workshop

Last year I was intending to run a workshop for Raspberry Pi at BETT but was recovering from an appendectomy instead. This year tempting fate I volunteered again and fortunately avoided any surgery in the run up to the show.

I had been working with ,my son Toby who had created his own robot using the CamJam EduKit 3 and I had used GPIO Zero to help to reduce the level of typing required to get his creation working. As I intended to talk about Physical computing Toby came along too with his robot. to show what could be done with a few simple lines of code.



He was very pleased to be able to show off his creation and say a little about how he had made it. he was also very excited to have his own badge with his newly created job title.





We then got hands on and had the attendees making their own simple circuits and writing the code to make things happen in the real world. Having some hands on time was a really powerful tool to demonstrate how quickly results could be seen using simple components and GPIO Zero. I did promise at the show that I would add the presentation here with the information links so here it is on Prezi - Lets get physical -  an introduction to Physical computing with GPIO Zero.


The show was challenging environment to deliver training in with all of the competing noise and activities occurring around the stand. It was an interesting cross between market trader and teacher. Attracting people into the stand and then guiding them through creating a circuit and controlling it with code It was also a challenge with people arriving to the stand (attracted by what was happening) part way through the session and wanting to join in.

The sessions both ran slightly different to the plan (and  to each other) but I think we were able share the power of being able to make things happen in the physical world.  I think especially with the late arrivals it was a great demonstration of how results can be achieved really quickly using GPIO Zero due to the less onerous volume of code required.

If i was going to do this again i would probably take some pre-prepared  kits with the components for the circuits or even use a HAT to simplify the process. I would also think about printing some copies of the code / circuit diagrams to make it easier to manage with late arrivals and swapping the screen around from basic to advanced tasks. Having both on a laminated card (or just a bit of paper would do) would have made it easier for those who arrived late to have a play with the basic example without me having to switch the screen back and forward.

Wednesday, 13 January 2016

GPIO Zero - making coding less language intensive.




In a previous post Getting Physical with Python I wrote about the difficulty some of the younger children in my computing group had with the volume of typing required to get started with physical computing. They did not struggle with understanding but it took too much time and help to enter the volume of text required. This took away some of the excitement and slowed things down.

At the time I thought to speed this up it would be good to write a python library to reduce the amount of text needed to get things to happen. Unfortunately I had lots of other things to do and this never went anywhere. However someone else also thought it would be good to make it easy to get started with physical computing and was able to do something about it.

That person was Ben Nuttall of the Raspberry Pi Foundation. Along with Martin O'Hanlon and Dave Jones he has created GPIO Zero. You can read his account of how it happened on his blog.

This python library can be used to very simply control components using the GPIO pins. The initial function set is based around the popular CamJam EduKits  (Kit 1- Starter, Kit 2 - Sensors) and makes a great starting point for physical computing using python.

A simple light and button combination can be controlled with the below example:

from gpiozero import LED, Button led = LED(15) button = Button(14) button.when_pressed = led.on button.when_released = led.off

instead of something like this:

import os 
import time  
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) 
GPIO.setwarnings(False) 


GPIO.setup(14, GPIO.IN)
GPIO.setup(15, GPIO.OUT) 

while True: 
        if GPIO.input(14) == False: 
              GPIO.output(15, HIGH)   
        else: 
               GPIO.output(15, LOW)  

 time.sleep(0.5) 

The reduction in volume of code and setup required is brilliant. GPIO Zero is an amazing tool for education. This is especially true where the volume of text entry is a barrier (either with younger or SEN children).

The tool allows the focus to be on the programming concepts and not on the entry of text. When i worked with my HomeEd computing group there was a difficulty fro a number of the students (aged between 5 and 15) in using the GPIO library as there was a lot of code to enter. They were generally happy with what they were trying to achieve but found that it took a long time to enter the lines of code required just to light up the LEDs.

This meant that in the one hour session that is what we achieved, lighting up the LEDs. Whilst this was a success and the children were happy with getting there it would have been much better to spend more of the time in the session exploring what could be done rather than entering lots of text.

GPIO Zero takes away some of the burden allowing children to focus on what they are trying to achieve rather than on copying out lots of lines of code (especially the set up parts that are conceptually more difficult to grasp and result in questions about what is BCM etc).

I have found that where I have used this it has meant I can more on more quickly and cover more of the computational thinking ideas where previously there would have been more time waiting for the students to catch up with the typing required. It also works well to satiate the desire for instant gratification that appears to be fairly common among my pupils. They only have to spend a short time entering code before they can see a result.

It is also much easier in a classroom to debug the code they have written if there are errors. The reduced volume of code makes for less searching to find the capitol that should't be there. This make students more able to do it themselves or makes it quicker for me when they can't see what is wrong. The reduction in time taken here give me the opportunity to get to more pupils and help them to progress.



I have also used this at home with my son (8) whilst he has been creating a robot using the CamJam EduKit 3 - Robots. This was really powerful because it allowed him to achieve results in short pockets of time before he lost focus and wanted to move on. He used the provided worksheets to set up the robot and connect the components and I translated the code parts into GPIO Zero for him to get the robot working.

So in summary the feedback is - Thanks Ben this is an awesome tool to help me teach computing.

If you are interested in using GPIO Zero there is a great getting started guide on the Raspberry Pi website in the resources 'Learn' Section.

More information can be found on pythonhosted.org or on GitHub. There is also a Google Doc with information and a place to add comments / requests.

Tuesday, 22 September 2015

Shifting the Smile - Freeing up some ports on AgoBo

This week I finally got around to setting up the code for the shift register I soldered onto AgoBo's 
prototyping board several months ago.


I used one of the preset positions for chips so it was relatively easy to add the board and some resistors to keep everything safe.

The seven segment display was then reconnected to the outputs and the head scratching began. I had a good look at the data sheet to get everything connected up then tried to sort out some test code to get the smile back on AgoBo's face.

I put some quick code making a short library so that i could call on mouth.smile in my code for AgoBo. I could probably make the code more efficient but this was a quick first attempt. I will try and get the code uploaded to my Git Hub repository when I have a chance to connect up AgoBo to the network

I have also added a talking mouth pattern to the different expressions that I may use if add some sound later on.

My next plan is to use some of the now free GPIO pins to light up some fibre optics I was given by my wife to make some hair. The current plan is to have the hair change colour to suit AgoBo's current emotions but some cycling also seems an appealing idea.

Acting the Part - A lesson in processor architecture

Part of the syllabus for my A-level computing group (OCR A Level) is to learn about and understand the make up of a CPU. This goes beyond the basic "this is the brains of a computer" and starts to look at how the CPU does it's job and which parts of the CPU do each part of the job.

To do this I could have done a 'chalk and talk' lesson telling the students all about the functions but I felt they would learn better if i could get them more involved. I also wanted to get them interacting and working together.

I did a lesson before with my Home Education group based on a CS unplugged activity - class simulation of a computer. I had adapted the ideas on the page to make a human calculator program using children to move the information around the parts of the computer. this was a little basic but it seemed like a good basis to expand on for my lesson.

As this was an A-Level group I wanted to get the students to do the thinking. So i came up with a plan based on a simple introduction to the parts and functions then set the students the task of designing activities to explain the working of the CPU to their classmates.

For the introduction we did a revision of the fetch-execute cycle and then went smaller to look at the parts of the CPU and what part they play in the process. The students were also given access to a YouTube playlist of videos about processor architecture to help them research the topic.

The students were split into small groups then set the task to design an activity to explain the process to their peers.

The Groups came up with a variety of ways of delivering the idea. All of the groups had an activity which showed they understood the process. The best group came up with an activity that involved the other students to take the role of each of the components and memory.

Their activity is detailed below (with a little editing):

Equipment:
Pens
Plain paper
Whiteboard pens
Mini Whiteboards
Labels for each of the components (can be written on the boards)

Set up:
1) Write a simple program to be used by the simulated computer the students used the following program:

     1 Load 70
     2 Add 71
     3 Store 72
     (at location 70 they had 712, at location 71 they had 73)

2) Select students to take the following roles -

     Registers:
     Program control - PC
     Memory Address Register - MAR
     Memory Data Register - MDR
     Current Instruction Register - CIR

     Arithmetic Logic Unit - ALU
     Control Unit - CU
     Accumulator - AC

     Cache Memory

     Address Bus
     Data Bus
     Control Bus

3) Hand each student the correct label, a whiteboard whiteboard pen, paper, and pen then position them around the classroom. Ensure the registers are together and the other components are spaced out around the room.

4) Hand Memory the Program and data loaded into memory


Activity

The students then act the parts of the CPU to carry out the program. To pass data / instructions / control around they write the information on to paper screw it into a ball and throw it to the next part in the process.

So for this example program the following happens:

1) PC is set at 1. This is transferred to the MAR (by throwing paper).
2) CU requests contents of address 1 from memory. (throwing paper via the address bus)
3) The data in the memory (LOAD 71) at address 1 is transferred to the MDR (via the data bus)
4) Contents of MDR loaded into the CIR
5) Contents of CIR sent to CU to be decoded (Data bus)
6) CU decodes the instruction and sends the required address to the MDR and increments the PC. (control bus)
7) Control signal sent (control bus) to fetch the data at the new address (70) (address bus)
8) Data from memory address 70  (712 ) loaded into the MDR (via the data bus)
9) Data from MDR (712) sent to the AC as required by the Load command


10......

this continues carrying out each instruction from the program so for this program PC 2 loads the Add 72 command which fetches the data from location 72 (73) and adds it to the AC. To add the two numbers the ALU is used. The total is added to the AC then the next instruction followed which in this case stores the result at memory location 72.



This could also be extended to show the extra time required to fetch data / instruction from RAM if they are not in cache memory. To do this the RAM should be positioned further away than cache memory. The cache is checked first then the RAM queried if it is not there.

Friday, 24 July 2015

The PiCycle an amazing student project



I have had the pleasure this year to have been a supervisor for one of our sixth form students doing an Extended Project Qualification (EPQ).

The EPQ is a level 3 qualification (similar to A-level) for students to do something that they are interested in. This can be an essay or an artifact and can take a myriad of forms. In this case my student chose to do a Raspberry Pi based project which was how I became involved.

Dan had no previous experience of the Raspberry Pi or Python before starting the project. He had done some web development but wanted to try something new. He spent a large portion of the project time mastering the basics of Python and the basic hardware before moving on to getting the project up and running.


The result is the PiCycle a Raspberry Pi based cycle computer that takes the position of the rider an plots it on a map on a website. The idea was to use the device to prove the designer had completed a planned charity cycle ride across France but could be used for all sorts of tracking applications. As well as getting the device working he spent some time getting it to look good too with branded interfaces on the device and the web tracking page.





The student developed the program to collect the GPS position and store this in a file on the Raspberry Pi and then upload the data to the web to display the position(s). The design means that whilst the cyclist is in areas of poor phone reception they can still log the GPS position (assuming GPS signal) and then upload the data when the phone signal is regained.

This project was a great achievement especially considering that Dan had no prior knowledge of the Raspberry Pi or Python before he started the EPQ.

Some more information about the project can be found in his project presentation. He can be found on twitter: @DJWOOLFALL.

Wednesday, 29 April 2015

Sci Fi Your Pi a design Challenge from Element14

After my success in the Raspberry Pi Educators Roadtest winning the prize for the UK (an Up mini 3D printer) I thought I would put in a proposal for their latest design challenge.

The title of the design challenge is "Sci Fi Your Pi" and centres around the idea of creating objects from or inspired by Science Fiction. This video explains what it is all about

I struggled initially to think of anything interesting being stuck on the suggestions made in the introduction to the challenge. However it was my search for difference that gave me the idea of looking at creating a Steampunk inspired device.

The kit for the challenge comes with a GPS model so this along with the strong adventurer spirit in Steampunk fiction I ended up with the idea of a Navigation device.

My idea has been selected from a large number of applicants among a very interesting group of projects. So far I have outlined my initial inspiration and described what I am hoping to produce for the challenge.  I have received the kit and I am putting together a plan of how I am going to make it work.



For anyone not familiar with Steampunk this video gives a fairly good introduction through a number of film clips. 



The spirit of adventure and exploration (as exemplified by the work of HG Wells and Joules Verne) felt like a great basis for a project where I will be trying new things and creating something a bit different to some of my other projects.

You can follow my progress on the Element 14 community with the tag steampunk_navigation