Tag Archives: Education

GPIO Zero: a friendly Python API for physical computing

via Raspberry Pi

Physical computing is one of the most engaging classroom activities, and it’s at the heart of most projects we see in the community. From flashing lights to IoT smart homes, the Pi’s GPIO pins make programming objects in the real world accessible to everybody.

Some three years ago, Ben Croston created a Python library called RPi.GPIO, which he used as part of his beer brewing process. This allowed people to control GPIO pins from their Python programs, and became a hit both in education and in personal projects. We use it in many of our free learning resources.

However, recently I’ve been thinking of ways to make this code seem more accessible. I created some simple and obvious interfaces for a few of the components I had lying around on my desk – namely the brilliant CamJam EduKits. I added interfaces for LED, Button and Buzzer, and started to look at some more interesting components – sensors, motors and even a few simple add-on boards. I got some great help from Dave Jones, author of the excellent picamera library, who added some really clever aspects to the library. I decided to call it GPIO Zero as it shares the same philosophy as PyGame Zero, which requires minimal boilerplate code to get started.


This is how you flash an LED using GPIO Zero:

from gpiozero import LED
from time import sleep

led = LED(2)

while True:

(Also see the built-in blink method)

As well as controlling individual components in obvious ways, you can also connect multiple components together.


Here’s an example of controlling an LED with a push button:

from gpiozero import LED, Button
from signal import pause

led = LED(2)
button = Button(3)

button.when_pressed = led.on
button.when_released = led.off


We’ve thought really hard to try to get the naming right, and hope people old and young will find the library intuitive once shown a few simple examples. The API has been designed with education in mind and I’ve been demoing it to teachers to get feedback and they love it! Another thing is the idea of minimal configuration – so to use a button you don’t have to think about pull-ups and pull-downs – all you need is the pin number it’s connected to. Of course you can specify this – but the default assumes the common pull-up circuit. For example:

button_1 = Button(4)  # connected to GPIO pin 4, pull-up

button_2 = Button(5, pull_up=False)  # connected to GPIO pin 5, pull-down

Normally, if you want to detect the button being pressed you have to think about the edge falling if it’s pulled up, or rising if it’s pulled down. With GPIO Zero, the edge is configured when you create the Button object, so things like when_pressed, when_released, wait_for_press, wait_for_release just work as expected. While understanding edges is important in electronics, I don’t think it should be essential for anyone who wants to

Here’s a list of devices which currently supported:

  • LED (also PWM LED allowing change of brightness)
  • Buzzer
  • Motor
  • Button
  • Motion Sensor
  • Light Sensor
  • Analogue-to-Digital converters MCP3004 and MCP3008
  • Robot

Also collections of components like LEDBoard (for any collection of LEDs), FishDish, Traffic HAT, generic traffic lights – and there are plenty more to come.

There’s a great feature Dave added which allows the value of output devices (like LEDs and motors) to be set to whatever the current value of an input device is, automatically, without having to poll in a loop. The following example allows the RGB values of an LED to be determined by three potentiometers for colour mixing:

from gpiozero import RGBLED, MCP3008
from signal import pause

led = RGBLED(red=2, green=3, blue=4)
red_pot = MCP3008(channel=0)
green_pot = MCP3008(channel=1)
blue_pot = MCP3008(channel=2)

led.red.source = red_pot.values
led.green.source = green_pot.values
led.blue.source = blue_pot.values


Other wacky ways to set the brightness of an LED: from a Google spreadsheet – or according to the number of instances of the word “pies” on the BBC News homepage!

Alex Eames gave it a test drive and made a video of a security light project using a relay – coded in just 16 lines of code.

GPIO Zero Security Light in 16 lines of code

Using GPIO Zero Beta to make a security light in 16 lines of code. See blog article here… http://raspi.tv/?p=8609 If you like the look of the RasPiO Portsplus port labels board I’m using to identify the ports, you can find that here http://rasp.io/portsplus

Yasmin Bey created a robot controlled by a Wii remote:

Yasmin Bey on Twitter

@ben_nuttall @RyanteckLTD pic.twitter.com/JEoSUlHtF6

Version 1.0 is out now so the API will not change – but we will continue to add components and additional features. GPIO Zero is now pre-installed in the new Raspbian Jessie image available on the downloads page. It will also appear in the apt repo shortly.

Remember – since the release of Raspbian Jessie, you no longer need to run GPIO programs with sudo – so you can just run these programs directly from IDLE or the Python shell. GPIO Zero supports both Python 2 and Python 3. Python 3 is recommended!

Let me know your suggestions for additional components and interfaces in the comments below – and use the hashtag #gpiozero to share your project code and photos!

A huge thanks goes to Ben Croston, whose excellent RPi.GPIO library sits at the foundation of everything in GPIO Zero, and to Dave Jones whose contributions have made this new library quite special.

See the GPIO Zero documentation and recipes and check out the Getting Started with GPIO Zero resource – more coming soon.

The post GPIO Zero: a friendly Python API for physical computing appeared first on Raspberry Pi.

The Digital Eagles have landed

via Raspberry Pi

Like many institutions, Barclays Bank recognises that digital literacy is an essential component of modern life. It was for this reason that, back in 2013, the bank launched its Digital Eagles initiative. Branch volunteers offered to give up their time and skills to teach members of the community how to get online, perform web searches, use email and video chat, and of course how to use online banking.

The Digital Eagles have since expanded, and the project now includes an initiative to get kids coding, called Code Playground. This is more than just a website, however. Digital Eagles now run monthly sessions at branches and other venues, all over the country, where kids aged from seven to 17 can come along and learn the pleasures of coding.

So what has this to do with Raspberry Pi? Well, where there’s kids and code, the Raspberry Pi is sure to follow. Last week, the Foundation’s education team hauled themselves down to the marble-and-glass palaces of Canary Wharf to deliver workshops to a group of specially selected Digital Eagles, that they might then cascade the training down to their colleagues, and bring Raspberry Pi to Code Playgrounds all over the country.

jodie on Twitter

@Digitaleagles @Raspberry_Pi..looking forward to our training! RaspberryPi is coming to a code playground near you! pic.twitter.com/eNbcucz2sk

It was a spectacularly successful day, as we ripped through sessions on physical computing with Scratch, the new GPIO Zero library, hacking the world of Minecraft, and motion-triggered animations with the Sense HAT.

I should, by now, be accustomed to the excitement and sense of achievement that people get from blinking an LED with the touch of a button and a few lines of Python, yet each time I see it happen it brings a smile to my face and renewed enthusiasm for the Foundation’s educational mission.

Charlotte Snell on Twitter

Loving my @Raspberry_Pi training today just made my traffic light flash using Python & a button @Digitaleagles pic.twitter.com/EozSuI4DfO

The Sense HAT, in particular, went down a storm. The unique combination of sensors and the LED display means that you can jump right into physical computing with ease. Several of the Digital Eagles mentioned that they thought the little device would be a perfect addition to the Code Playgrounds, and couldn’t wait to get using it with the kids who attend.

Charlotte Snell on Twitter

So my bear gets angry when you shake him! @Raspberry_Pi training for @Digitaleagles #CodePlaygrounds pic.twitter.com/bk7kSWUXgp

So now it’s over to the Digital Eagles! Soon, Raspberry Pis, Sense HATs, CamJam EduKits and a variety of other goodies will be wending their way to Barclays Bank branches the length and breadth of the country. There the Eagles will be able to pass on their new-found skills and spread the joys that the Raspberry Pi can bring to the next generation of eager coders. We’ll be sure to report back to you on their progress and successes in the near future, so keep checking the blog for updates, or maybe check out a Code Playground near you!

The post The Digital Eagles have landed appeared first on Raspberry Pi.

Discover the role of colors in nature

via Arduino Blog


“The color Visualizer” is an immersive installation to understand how color is used in nature to communicate between living organisms and to explore biodiversity through the lens of color:

By plucking an array of multi-colored strings, which are layered over the large array of high resolution screens, visitors can explore over 100 unique color stories as vibrant images and short videos appear before them. Strum a red cord, for example, and learn how a male cardinal bird colors his vibrant red feathers with pigments from food; strum a yellow cord and see how a yellow leopard’s spotted coat allows this predator to blend in with shadow and light while moving through tall grass.

The eye-catching cylindrical installation is part of the permanent exhibition “The color of Life” that opened in June 2015 and was created by Tellart in collaboration with the California Academy of Sciences. It was prototyped using Arduino Uno and it’s currently shortlisted for the Interaction Awards, representing excellence in interaction design.

In the video below the team working at the project explain the main features of the educational installation and show a bit of the making of:

Connecting educators: Raspberry Pi hosts a CAS hub

via Raspberry Pi

One of the challenges I always found in teaching is that at times it can be quite isolating, particularly when working in a small department. You spend most of the day with your classes, or planning for them. You catch up with your colleagues in weekly meetings, but opportunities to share and reflect can be limited.

During my time in teaching I’ve always sought to connect with other teachers and share ideas (and gain reassurance that I was doing it right), and this became increasingly important back around 2011-2012 when things were starting to change in computing education. Many ICT teachers who were concerned about the lack of computing and problem-solving skills in their subject started meeting up in local CAS (Computing at School) hubs. I attended a few meetings and got a chance to connect with others who shared my concerns and gather some great ideas for lessons.

In the past few years CAS hubs have spread all over the UK and beyond, and are an opportunity for educators, developers and industry experts to meet up regularly, share ideas and participate in workshops. Last week, we hosted a CAS hub at our office in Cambridge for the first time. This event was aimed at secondary teachers, and we were delighted to have over 20 educators attend.

Emma on Twitter

Physical Computing fun @Raspberry_Pi yesterday for Cambridge Secondary CASHub meeting. pic.twitter.com/hosh5adgnX

Our first meeting focused on physical computing, something we’re really passionate about here. Teachers shared their experiences of physical computing, we discussed hardware options including Raspberry Pi and others, and we ran a hands-on workshop with our Sense HAT add-on – topical at the moment, because two Raspberry Pis with Sense HATs are soon to fly to the International Space Station as part of British ESA astronaut Tim Peake’s Principia mission.

Astro Pi poster: Your Code in Space!

To find your nearest CAS hub, training event or CAS Master Teacher you can use the CAS interactive map, by clicking the image below.

Map of CAS hubs in England and Wales

We had a really great session with teachers, and we’re looking forward to hosting future hub meetings as well as other events.

If you’re a teacher, educator, IT professional or just interested in computing education, visit the CAS community site and take part. You could attend or host a hub meeting, or see what training events are going on in your area. Let’s help support our educators who are teaching the next generations of engineers and developers.

The post Connecting educators: Raspberry Pi hosts a CAS hub appeared first on Raspberry Pi.

Astro Pi website launch

via Raspberry Pi

In a month’s time we’re sending two Raspberry Pis to the International Space Station as part of two Astro Pi flight units. We’ve all been beavering away for the last 12 months in preparation, and the launch date is almost upon us.

Tim Peake is currently doing his final press conference in the UK before he embarks on his six-month mission, during which he will be operating the Astro Pi devices and running the experiments and applications designed and coded by children in primary and secondary schools.

The new Astro Pi website

The new Astro Pi website

We’ve just relaunched the Astro Pi website which now contains not only information about the competition we ran this year, but also a whole host of information surrounding the whole mission, including a storyline of project updates, events and other ways to get involved, downloads, and a growing number of resources in Scratch and Python for learning about space and experimenting with the Sense HAT. There are plenty of exercises for use in the classroom, at home or with your Code Club or CoderDojo!

Check out the winning entries page – you can download the code for each project on GitHub, and run the code on your own Sense HAT. Some of the projects will be collecting data while running in space, and when we have the data from ESA we’ll make it available to download from the website so you can compare the data to your own. I know, super cool.

An Astro Pi displaying the icon for the 'Flags' application

The Astro Pis will display icons representing the winning applications

The Astro Pi units are made up of a Raspberry Pi B+, a Sense HAT, a camera module each (one normal and one infra-red), and a space-grade aluminium flight case (not for sale, unfortunately). You can read about the Astro Pi hardware and buy everything you need to build your own Astro Pi. Some people have 3D-printed their own Astro Pi cases, or even made them out of Lego!

Once you have your Pi and Sense HAT set up, you can follow the programming guides, go through the resources and come up with your own ideas. What would you do if you had the chance to run your code in space?

Thanks to Sam, Dave and Laura for their help in putting the website together, and to Carrie Anne, Marc and James for contributing the brilliant resources.

The post Astro Pi website launch appeared first on Raspberry Pi.

Putting a Code Club in every community

via Raspberry Pi

Raspberry Pi Foundation and Code Club join forces

I am delighted to announce that Raspberry Pi Foundation and Code Club are joining forces in a merger that will give many more young people the opportunity to learn how to make things with computers.

Raspberry Pi Foundation and Code Club were both created as responses to the collective failure to prepare young people for life and work in a world that is shaped by digital technologies.

We’re part of a growing worldwide movement that is trying to solve that problem by equipping people with the knowledge and confidence to be digital makers, not just consumers.

Children at a Code Club

We’ve made a good start.

Since launching our first product in 2012, we have sold 7 million Raspberry Pi computers and reached hundreds of thousands of young people through our educational programmes, resources, open source software, and teacher training.

Since its launch in 2012, Code Club has helped establish over 3,800 clubs in the UK and over 1,000 clubs in 70 other countries. Run by volunteers, Code Clubs focus on giving 9-11 year olds the opportunity to make things with computers. Right now over 44,000 young people regularly attend Code Clubs in the UK alone, around 40% of whom are girls.

But we’ve got much more to do.

Research by Nesta shows that in the UK, many young people who want to get involved in digital making lack the opportunity to do so. We want to solve that problem, ensuring that there is a Code Club in every community in the UK and, ultimately, across the world.

A child absorbed in a task at a Code Club

In many ways, the decision to join forces was an obvious step. We share a common mission and values, we hugely respect each other’s work, and there are clear benefits from combining our capabilities, particularly if we want to have impact at a serious scale.

Code Club and Raspberry Pi share one other important characteristic: we’re both, at heart, community efforts, only possible thanks to the huge numbers of volunteers and educators who share our passion to get kids involved in digital making. One of our main goals is to support that community to grow.

Code Club – volunteer with us!

Code Club is building a network of coding clubs for children aged 9-11 across the UK. Can you help us inspire the next generation to get excited about digital making? Find out more about how to get involved at www.codeclub.org.uk

The other critical part of Code Club’s success has been the generous philanthropic partners who have provided the resources and practical support that have enabled it to grow quickly, while being free for kids. ARM, Google, Cabinet Office, Nesta, Samsung and many other organisations have been brilliant partners already, and they will be just as important to the next stage of Code Club’s growth.

So what does this all mean in practice?

Technically, Code Club will become a wholly owned subsidiary of the Raspberry Pi Foundation. Importantly, its brand and approach will continue unchanged. It’s a proven model that works incredibly well and we don’t want to change it.

For the teachers and volunteers who run Code Clubs, nothing will change. Code Club HQ will continue to create awesome projects that you can use in your clubs. You will still use whatever hardware and software works best for your kids. We’ll still be working hard to match volunteers and schools to set up new clubs across the country, and developing partnerships that launch Code Clubs in other countries around the world.

For Raspberry Pi Foundation, this is an important step in diversifying our educational programmes. Of course, a lot of our work focuses on the Raspberry Pi computer as a tool for education (and it always will), but our mission and activities are much broader than that, and many of our programmes, like Code Club, are designed to be platform-neutral.

Code Club robot and Raspberry Pi robot: high five!

Personally, I’m really excited about working more closely with Code Club and helping them grow. I’ve been a big fan of their work for a long time, and over the past few weeks I’ve had the opportunity to visit Code Clubs across the country. I’ve been blown away by the energy and enthusiasm of the teachers, volunteers and young people involved.

If you don’t know them already, check them out at www.codeclub.org.uk and, if you can, get involved. I know that many people in the Raspberry Pi community already volunteer at their local Code Club. I’d love to see that number grow!

The post Putting a Code Club in every community appeared first on Raspberry Pi.