Showing posts with label Teaching. Show all posts
Showing posts with label Teaching. Show all posts

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, 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.

Friday, 13 March 2015

Basic Computing for Sheffield Home Educators

I have been talking for some time about starting a Computing / STEM group for home educated children in Sheffield.

We home educate our 7 year old son and there is a large community of home educators around Sheffield. As computing can be quite equipment heavy it is not something that is easy to do at home and until now there hasn't been an alternative.

The difficulty was finding a venue and some equipment that I could use to run the sessions. Fortunately I had seen a post about a lending library of Raspberry Pi equipment that had been set up at Sheffield University - The Pi bank. Fortune was smiling on me as this also led to the rediscovery of the Access Space. They charge for the space but they have an ideal flexible teaching space ideal for this sort of group. A few phone calls, Facebook posts and  emails later and the group was all set


The group is a very mixed group with children raging from 5 to 15 with a different levels of prior knowledge of computers and programming. This presented a different challenge to my normal classes but makes for interesting class dynamic. I say class but the plan is to try and not be too school like and see how we can follow the children's interests as we progress. We have a few structured 'lesson' type activities planned but after that I am hoping to split the group down and work on projects that they are interested in.

Today I ran the first ever session with a focus on how computers work and an introduction to algorithms.

First we made a human computer with the children forming the components and passing information around the computer to first perform simple sums.

The children took on roles with one student acting out each part of the computer and several (the more active and excitable younger boy mainly) passing the information between the components.

The user, although not too keen to hold on to the human mouse moved the mouse around our ( A4 paper calculator display) and the mouse driver reported the position. This was passed to the processor stored in memory and also displayed on the monitor (children with with pencil and paper and whiteboard and maker respectively).

This was repeated for each of the movements of the mouse to complete the sum. I had planned on simple single digit arithmetic for our volunteer processor but the user had other plans (I did managed to keep it to 2 digits, but I think she would have gone for more if left to her own devices). The processor then calculated the answer and passed that to the monitor and memory. In this case the user forgot to save (or i forgot to ask her to) so we talked about what would happen to the information and then pretended we had saved to pass the information to the hard drive (child with paper and a pen).

After that we simplified our computer, using just a camera/computer combination, lots of willing active information conduits and a rather excitable printer (my Son Toby) we experimented with how computers see and describe images using binary. To keep things simple we used a simple 1 bit black and white image which was only shown t the camera. The camera passed the appropriate 1 or 0 (each an A4 sheet with 1 on the front and black on the back or 0 with white on the back) to the information carriers and the printer started to put the image together on the floor.

This was really great as the first stages were rendered accurately but as the information carriers gained confidence and enthusiasm we started to see some arriving out of order which corrupted our image slightly. This gave us an opportunity to talk about the importance of the data arriving in the correct order.

After getting everyone sat down again I introduced our next activity which was the Sandwich making robot by Philip Bagge. I explained the activity and handed out the sheets to allow the children to plan their Sandwich making algorithms.

After donning the special robot uniform (pink pinny borrowed from home) i took on the role of robot and we tested some algorithms. We didn't get as far as a full sandwich but we learnt some good lessons about how to think through a problem. We also took the opportunity to talk about debugging.

I was surprised by how many children though that cutting the bread bag was the way to open bread until at the end someone mentioned there was no open on the instruction set. I thought this was an error until I watched the videos again and noticed that Phil starts with his bread bag open.

Overall I am quite happy with how the session went and the children seemed for the most part engaged in the activities. I now need to go off and plan for next weeks introduction to Raspberry Pi and programming in python.




Thank you to Computer Science Unplugged and Philip Bagge for the inspiration for the activities for the session.

This is Phil in action -




Outtakes - https://www.youtube.com/watch?v=leBEFaVHllE - very good lessons on how important it is to get the algorithm correct.

Wednesday, 19 November 2014

Raspberry Pi CPD in Sheffield


Part of the idea of Picademy was that delegates would go out and spread the word. So as part of my effort I spent this evening delivering Raspberry Pi CPD to the Sheffield CAS hub at Sheffield Hallam University.

The session was mainly made up of Computing ITT students from Sheffield Hallam University so it was really interesting to see a different approach to new information (from my secondary pupils). Most of the delegates had little or no exposure but there were two who had used the Pi for their own projects (a security camera and a remote media center).

After a quick introduction to the Pi we spent time describing how the Pi could be set up in classrooms and introduced the Raspberry Pi foundation's resources. Preparing for this event gave me the chance to look again at what is provided and the resources there really do give all the information that you need to get started using the Raspberry Pi and moving on to using it productively in the classroom.

After the set up and a brief summary of some of activities available for using the Pi in the classroom I spent some time focusing on some of my favorite schemes. as a parent of a 7 year old I can't avoid minecraft at home and have found that it is equally as engaging for secondary pupils. I shared some of Craig Richardson's resources from his blog on Minecraft Pi - Arghbox. the delegates were also given a chance to try out some of the scripts on the Pi's they had set up. This may have been a mistake with some of the more game obsessed ITT students (mainly male). This was hastily used to point out the importance of choosing classes and classroom management strategy carefully when using a game students are already familiar with.

We then looked at some of the other ideas I have used in the classroom. The use of Sonic Pi (paticularly as an application that appears to appeal more equally to both genders) to engage students creativity and teach programming in a fun way. We also looked at the possibilities using the GPIO pins for physical computing. I am very interested in 'Personally Meaningful Projects' as a key motivator for students to get involved in programming and the GPIO pins provide this possibility. I shared some example of projects my students and students from further afield have created using the Pi. We also discussed the support available from the community.

The great thing about the ITT students is that once they had a spark of an idea they appeared very enthusiastic to take this on and try using this in their teaching practices. Several were keen to borrow the university Raspberry Pi set and some were talking about purchasing their own and projects they could work on. Hopefully this talk will be converted to action and there will be a few more computing teachers in Sheffield schools enthused about the benefits of using Raspberry Pi in the classroom. If nothing else I did a little Picademy product placement and did my best (if not quite 'The Apprentice' level) pitch for the resources available on the Raspberry Pi site. I left the event feeling buzzy and motivated to do it again so it can't be all bad.

The Prezi I used to as a place holder for the introductory videos and some links for the resources we discussed is here.



As a side / end note this was a chance to play with some presentation tech I can only dream of in my classroom. I had a Pi on one button, the Prezi on another and a visualiser showing the actual Pi on a third. This was the first time I had used the set up at the university and I was very pleased with the possibilities. At the press of a swanky touch screen I could switch between the projected picture of my hands doing magic with the Pi and the actual out put of the Pi, then switch to the diagram on the Prezi showing the possible connections. This made the screen work hard for me and really helped to show what was going on. The only downside was managing multiple mice and a second keyboard a few paces away (due to the university padlocked setup) and talking at the same time. I don't imagine I will be getting this sort of system in my classroom anytime soon but it was good to try it out for an evening.

Monday, 8 September 2014

Conversations with computers using python


I had the idea of making the standard 'Hello World' introduction to programming a new language a little bit more interesting for my Y7 class.

The idea of the computer conversations and the recent Turing test success or (near success) by Eugene gave me the idea of getting the students to make a (vastly simplified) version of Eugene using Python. The plan would be to teach them some basic Python concepts like displaying information and filling variables based on user input and then maybe progress onto selection.

This would initially start as a very simple program with them entering their name and then including the name in the response. The students could then work up some complexity from there using more questions. The next step would be to switch things round and have the computer answer user question based on a list of pre-programmed responses.

The Plan

Introduction

Show the class a video by way of introduction to the test. Something like - Jeremy Clarkson Explains the Turing test or The Turing test, as described by Expect Labs CEO, Timothy Tuttle.

Explain the plan to create a basic chat bot that can have a basic conversation with the user.

Task 1- Hello World

Students to open IDLE and the a new window. They then create a basic 'Hello World' program and save and run.

e.g. 

print ('hello world!') 

Students to experiment changing hello world for whatever greeting they choose. (Yes they will probably make it say rude words!)

Task 2 - Talk to me

Obviously this is a pretty one boring conversation so we need to add in the ability for the user to input information.

e.g.
myName == input('What is your name?')
print ('hello ' + myName)

Students to experiment with this and then try adding more questions.

e.g.
myName == input('What is your name?')
print ('hello ' + myName)
myColour == input('What is your favourite colour?')
print ('That is amazing ' + myName + ', ' + myColour + ' is my favourite colour too')

Task 3 - Selection

To try and make the computer's responses a little more realistic it would be good if the response wasn't the same what ever you type so we can add add selection to change the response based on what is input.

This can start with a simple if else:

e.g.
myColour == input('What is your favourite colour?')
if myColour == 'orange':
    print ('That is amazing ' + myName + ', ' + myColour + ' is my favourite colour too')
else:
    print ('It is nice that you like ' + myColour + myName + ' I prefer orange')

This can then be moved on to add more choice using else if (elif):

e.g.
myColour == input('What is your favourite colour?')
if myColour == 'orange':
    print ('That is amazing ' + myName + ', ' + myColour + ' is my favourite colour too')
elif myColour == 'black':
    print (myName + ' your are strange ' + myColour + ' is not even a real colour, how can it be your favourite?')
else:
    print ('It is nice that you like ' + myColour + myName + ' I prefer orange')

Task 4 - Ask me a question

This basic idea can then be used to switch things around and let the students ask questions. This will only handle a pre-programmed list of questions and answers but completes the very basic conversation idea.

This can be added to the first code or used to start a new program. if in the same program some of the old variables can be used to add more interest.

First the computer needs to prompt the user to ask a question:

myQuestion == input('Ask me a Question?')
if myQuestion == 'how old are you':
    print ('I am 12, how old are you ' + myName + ' ?')
elif myQuestion == 'What is your name?':
    print ('My name is Simon')
else:
    print ('Sorry i didn't understand that question')

Students experiment with their own versions.


This is a fairly simple program so it only has one question opportunity and only a couple of possible questions. If students still have time then they could be challenged to find a way to give more than one question opportunity or add further questions and answers. Another idea is for the students to program a combination of questions for the student and opportunities to answer questions like in a conversation, they could also look at getting the answers from a text file and possibly they could use the text file to allow the program to 'learn' by storing answers given by students to questions and then use those to respond when it is asked that question later!


Plenary

Show some examples of students programs to the class and use them to highlight the key parts of the program.


Further Resources

Since writing this I have found a short scheme of work based on the turning test on the Rapspberry Pi website http://www.raspberrypi.org/learning/turing-test-lessons/. This 3 lesson scheme explains the idea of the Turing test and uses a speech module to have the robot speak to you.


Thursday, 3 July 2014

Making music with Y5s




We had our Y5 Day at school last week. After tweeting about the day using Sonic Pi I had a couple of requests for information about what I did. So I have documented the plan and my observations here.

We were given a slot in the creativity strand so I thought this was an ideal opportunity to do something a bit different and engaging. The plan was to make some music with Sonic Pi and teach a bit of programming along the way. I had been given three session each of one hour. I set up the classroom before the students arrived with each Pi already hooked up and running Sonic Pi v2.0 (from my Picademy SD card image).

I had an interactive whiteboard with simple display software (ActivInspire on a Promethean board) to allow me to write on the board. Unfortunately I was not able to display my Pi screen to the students using the projector. So I had a large monitor that the students could see when they initially gathered around a central table for the introduction.

The plan was heavily based on the Picademy session delivered by Dr Sam Aaron and Carrie Ann Philbin.  I also used the Sonic Pi article in  Magpie issue 23 as a reference.

The Plan

Introduction - (approx 5 min)

Find out who had done any programming before or used scratch (to adapt the complexity and to be used later as an example if they knew how to do things in scratch)

Introduce Sonic Pi, show a quick example of what can be done using a preprogrammed routine or one of the example scripts. Show what happens when some of the parameters are changed by getting students to change them.

Activity 1 - (approx 15 min)

Explain simple play and sleep commands, write some examples on the board.

e.g.
play 68
sleep 1
play 58
sleep 1


Students to experiment with their own simple tunes, and with changing the midi numbers and sleep durations.

Activity 2 - (approx 10 min)

Explain that to get a tune we often have repeated elements.Explain that this could be done by retyping the code but this would not be efficient.

Introduce loops (if some have prior knowledge of scratch ask them what we do in scratch to do this - put 'forever' around the code) show students how this is done with Sonic Pi. I did this by adding the loop do to the code I had written on the board earlier to show how it wrapped round the code like the 'forever' in scratch.

e.g.
loop do
      play 68
      sleep 1
      play 58
      sleep 1
end

Students to experiment adding loops to their code.

N.B. at this point I had some students asking 'what if i only want to repeat it x times?' so I added an adhoc extra activity to explain.

Activity 2a - (approx 10 min)

Explain that we might want to repeat a specified number of times instead of keep looping forever. Explain that this can be done with '.times do'. Again I used the code I had on the board to show how this worked removing the loop do and adding the new command

e.g.
3.times do
      play 68
      sleep 1
      play 58
      sleep 1
end

Students to experiment with repeating a specified number of times. 

Activity 3 - (approx 10 min)

Introduce the 'sample' command. I used a new slide on my display to show an example sample command then asked students what we would do if we wanted it to loop.

e.g.
sample :loop_amen
sleep 1.753

this then became

loop do
    sample :loop_amen
    sleep 1.753
end

Students to experiment with adding samples

Activity 4 - (approx 10 min)

Introduce the examples to students. Show them where to find the examples and synth information using 'Help'. Remind them that the numbers in blue are parameters that can be changed.

Students to experiment with the use_synth command and using example blocks. Put together a small piece of music

Plenary - (approx 5 min)

Quick reminder of the main learning points; sequencing, loops efficiency....

Play out students work (or some examples if not enough time) to rest of the class.


Show and Tell

At the end of the day there was a 'show and tell' assembly where parents of the y6 pupils, the primary school staff and the Y7s and staff who helped on the day were invited to hear about what the students had been doing.

Each school chose a couple of volunteer students to show what they had been doing in the last session. For the students who were in my last session this included a performance of their music in the hall. This was especially well received and really showed what could be achieved in a very short time by students who had no previous experience with Sonic Pi (or in most case any written programming at all).

How it went

The sessions on the whole worked well. We had a limited number of working Rapsberry Pi set-ups and with some groups that made it difficult to get everyone fully involved; for some large groups we had some groups of four working with one Pi. This was due to a number of factors but mainly due to a batch of corrupted memory cards and limited capacity to build new cards at short notice. For next time I am going to ensure I have plenty of spare cards on standby.

We also did not have any headphone splitters so they had to pass around the headphones to hear the results. This was again a bit challenging in the large groups, but where there were groups of three or less it actually worked really well as the students were discussing what they were typing then listening to the results in turn. This promoted more active group working and lots of discussion about what do add to their programs. We are intending to purchase some of the splitters to enable a 1:1 headphone assignment, but I may be using these only after I have the groups working well or remove them if I find that the wearing of headphones is reducing this productive interaction.

I was really pleased that all of the groups produced reasonable credible music products during the sessions. There were even some groups who were moving ahead so I had them experimenting with threading. Overall the day was really successful in getting students to be creative and engaging them in learning some computer science. 

Gender Bias

I was interested to see that during the sessions there was no noticeable gender split in the engagement of pupils. The girls and boys seemed to be equally engaged in creating music, where in previous sessions (robotics based) there was a noticable split with more boys being engaged than girls. I am unsure if this was solely because of the nature of the activity or other factors (e.g. in a different school, age of the pupils). It will be interesting to see if this is the same when we implement this as part of our standard curriculum next year.

Other options and resources

I had a bit of a short lead time to deliver the session so didn't have any time for additional research so I used the Session that Dr Sam Aaron delivered at Picademy as my main inspiration. However I have since discovered that there is now a Sonic Pi taster activity on the Raspberry Pi website. This provides a fairly good introduction that I could have used.

I did use v2.0 for these session but you could do very a similar type of session with the current release (or you could download the latest release candidate of v2.0).

The full Sonic Pi scheme of work is available on the Raspberry Pi website and you could use the first lesson from that scheme as an alternative (the scheme is currently written for Sonic PI v1 but will be updated once v2.0 is fully released).

For support with Sonic Pi Dr Sam Aaron has a dedicated Sonic Pi Google+ group. There is also the Sonic Pi website for more information. The Raspberry Pi official forums are also a great resource for support from the community. They even have a dedicated education section.