Page 1 of 1

GPIO Zero - a new Python library designed for education

Posted: Thu Oct 01, 2015 10:34 am
by ben_nuttall
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#

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

Posted: Thu Oct 01, 2015 8:53 pm
by morphy_richards
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.

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

Posted: Fri Oct 02, 2015 8:45 am
by ben_nuttall
Great! Thanks

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

Posted: Sat Oct 03, 2015 10:20 am
by KnightOfPi
Great, will try it now.

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

Posted: Sat Oct 03, 2015 10:45 am
by KnightOfPi
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.

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

Posted: Sat Oct 10, 2015 4:19 pm
by ben_nuttall
Beta 2 out now!

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

Posted: Sun Jan 31, 2016 4:40 pm
by Carrie Anne
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!

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

Posted: Tue Mar 19, 2019 9:57 pm
by Simple
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