Page 1 of 1

GPIO Zero - a new Python library designed for education

Posted: Thu Oct 01, 2015 10:35 am
by ben_nuttall
[Cross-posted from the Education sub-forum]

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 11:09 am
by scotty101
Not a teacher but I've been a STEM ambassador and have taught MindStorms to kids and developed an Arduino Scratch workshop.

Only comment so far, without running it, is on the following syntax

Code: Select all

is_active
I think I'd replace this with

Code: Select all

is_on
and

Code: Select all

is_off

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

Posted: Thu Oct 01, 2015 11:18 am
by ben_nuttall
Good point. Thanks! Are you referring to generic output devices? We have domain-specific aliases for things like Button where "is_active" becomes "is_pressed" and "is_inactive" becomes "is_released". Would make sense for things like LEDs which have on/off state.

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: Wed Nov 11, 2015 9:44 pm
by Mamvcivm
Hi there, just created a new install of Jessie and ran the commands listed below:-

sudo apt-get update - succeeded
sudo apt-get install python-pip python3-pip - succeeded
sudo pip install gpiozero - failed
sudo pip-3.2 install gpiozero - succeeded

The error for the third line is:-

building 'spidev' extension

creating build

creating build/temp.linux-armv7l-2.7

arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c spidev_module.c -o build/temp.linux-armv7l-2.7/spidev_module.o

spidev_module.c:20:20: fatal error: Python.h: No such file or directory

#include <Python.h>

^

compilation terminated.

error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-KLl1oE/spidev/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-R_yDS6-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-KLl1oE/spidev
Storing debug log for failure in /root/.pip/pip.log


I'm guessing this is only a problem if I chose to use Python 2, but any ideas as to what's gone wrong?

Thanks,

Andrew

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

Posted: Thu Nov 12, 2015 7:02 am
by DirkS
spidev_module.c:20:20: fatal error: Python.h: No such file or directory
That file is part of the package python-dev.
Install it with

Code: Select all

sudo apt-get update
sudo apt-get install python-dev

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

Posted: Thu Nov 12, 2015 9:08 pm
by Mamvcivm
Cheers DirkS that sorted it! :D