Showing posts with label GPIO Zero. Show all posts
Showing posts with label GPIO Zero. Show all posts

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.