User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 230
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

GPIO Zero - a new Python library designed for education

Thu Oct 01, 2015 10:34 am

Dear teachers and educators

I've been working on a new Python library that provides a simple interface to everyday GPIO components. It sits on top of the standard RPi.GPIO but requires much less code to get going. It's called GPIO Zero.

Simple example:

Code: Select all

from gpiozero import LED, Button

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

button.when_pressed = led.on
button.when_released = led.off
I'm aiming for minimal boilerplate (no setmode, setwarnings), easy to read, guessable and obvious.

I've released a public beta and I plan to do a full release within a month. I'd like to get some feedback, particularly from teachers, to help get the language of the interface right (function names and such), and look at some simple and complex examples to see if it's achieving its goals.

Install it on your Pi with:

Code: Select all

sudo apt-get update
sudo apt-get install python-pip python3-pip
sudo pip install gpiozero
sudo pip-3.2 install gpiozero
The library supports Python 3 and Python 2. Python 3 is recommended!

Just open IDLE or a Python shell, import the bits you're using and get going. Full documentation is available at http://pythonhosted.org/gpiozero/

Please feel free to leave feedback here or in the Google Doc: https://docs.google.com/document/d/1Ebb ... edit?pli=1#
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Thu Oct 01, 2015 8:53 pm

Thanks this sounds great. We can try to help I will get some of my lunchtime club kids to install, try and I will feed back.

User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 230
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Fri Oct 02, 2015 8:45 am

Great! Thanks
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

User avatar
KnightOfPi
Posts: 49
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Sat Oct 03, 2015 10:20 am

Great, will try it now.
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

User avatar
KnightOfPi
Posts: 49
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Sat Oct 03, 2015 10:45 am

Ok i tried some things and i like it.

A function for switching BCM and BOARD numbering would be nice;
for the DHT drivers, here is a port for Python3:
http://www.knight-of-pi.org/measure-tem ... 22-am2302/

Thanks for your work! I'll stay tuned.
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 230
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Sat Oct 10, 2015 4:19 pm

Beta 2 out now!
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

User avatar
Carrie Anne
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 87
Joined: Sat Sep 29, 2012 4:11 pm
Location: London
Contact: Website

Re: GPIO Zero - a new Python library designed for education

Sun Jan 31, 2016 4:40 pm

Anyone looking to move from block based programming with physical computing should definitely check out this great library designed for this very use case. Very simple to program components with the Raspberry Pi. I wish it was around when I wrote my book!

Simple
Posts: 31
Joined: Tue Aug 01, 2017 6:51 am
Location: Colorado USA
Contact: YouTube

Re: GPIO Zero - a new Python library designed for education

Tue Mar 19, 2019 9:57 pm

Hello and thank you

Is there a general discussion forum for GPIO Zero?
I am looking to ask general questions and perhaps gain some insight on how to code in some specific ways.
I like your examples in the documentation, especially pertaining to the LED lighting techniques and the ability to indicate whether the internet is up or down using a LED, for example. In specifics, I would like to know if it is possible to instead, check whether the Pi is DHCP connected to an unknown router, vs checking for internet via google.com in the example. Also, Is it possible to poll an occupied GPIO state using GPIO Zero and perform another function based upon the state of the GPIO? I have a DAC that reserves a GPIO to electronically unmute itself and would like to check the state of that GPIO periodically (hopefully in short span) and then indicate that status using a LED.

Thank You
S

Return to “Staffroom, classroom and projects”