A simple interface to GPIO devices with Raspberry Pi.
Component interfaces are provided to allow a frictionless way to get started with physical computing:
from gpiozero import LED from time import sleep led = LED(17) while True: led.on() sleep(1) led.off() sleep(1)
With very little code, you can quickly get going connecting your components together:
from gpiozero import LED, Button from signal import pause led = LED(17) button = Button(3) button.when_pressed = led.on button.when_released = led.off pause()
You can advance to using the declarative paradigm along with provided source tools to describe the behaviour of devices and their interactions:
from gpiozero import LED, MotionSensor, LightSensor from gpiozero.tools import booleanized, all_values from signal import pause garden = LED(17) motion = MotionSensor(4) light = LightSensor(5) garden.source = all_values(booleanized(light, 0, 0.1), motion) pause()
See the chapter on Source/Values for more information.
The library includes interfaces to many simple everyday components, as well as some more complex things like sensors, analogue-to-digital converters, full colour LEDs, robotics kits and more. See the Recipes chapter of the documentation for ideas on how to get started.
GPIO Zero builds on a number of underlying pin libraries, including RPi.GPIO and pigpio, each with their own benefits. You can select a particular pin library to be used, either for the whole script or per-device, according to your needs. See the section on changing the pin factory.
A “mock pin” interface is also provided for testing purposes. Read more about this in the section on mock pins.
GPIO Zero is installed by default in the Raspbian desktop image, available from raspberrypi.org. To install on Raspbian Lite or other operating systems, including for PCs using remote GPIO, see the Installing chapter.
Comprehensive documentation is available at https://gpiozero.readthedocs.io/. Please refer to the Contributing and Development chapters in the documentation for information on contributing to the project.
Table of Contents¶
- 1. Installing GPIO Zero
- 2. Basic Recipes
- 3. Advanced Recipes
- 4. Configuring Remote GPIO
- 5. Remote GPIO Recipes
- 6. Pi Zero USB OTG
- 7. Source/Values
- 8. Command-line Tools
- 9. Frequently Asked Questions
- 10. Migrating from RPi.GPIO
- 11. Contributing
- 12. Development
- 13. API - Input Devices
- 14. API - Output Devices
- 15. API - SPI Devices
- 16. API - Boards and Accessories
- 17. API - Internal Devices
- 18. API - Generic Classes
- 19. API - Device Source Tools
- 20. API - Tones
- 21. API - Pi Information
- 22. API - Pins
- 23. API - Exceptions
- 24. Changelog
- 25. License