Playing with Electronics: RPi GPIO Zero Library Tutorial
A simple way to learn electronics is using Raspberry Pi and its GPIO Zero Library. With a very few lines of code in Python you will be able to control actuators, read sensors, etc. It was created by Ben Nuttall of the Raspberry Pi Foundation, Dave Jones, and other contributors.
Here in this quick tutorial, I will give you the basis for creating simple circuits controlled by the Raspberry Pi. For full details, please see this link: GPIO Zero V 1.3.1 Documentation. Also you can download it from magPi magazine a full free book that will guide you step by step on several projects using the GPIO Zero library: Simple Electronics with GPIO Zero.
On this tutorial, we will explore as input devices (“
- Motion Detector Sensor
And as output (“
- Generic Digital Output (Stepper Motor)
Bill of Material
- Raspberry Pi (V2 or 3)
- Resistor 330 ohms
- Jumper Wire Dupont Cable (Female/Male and Male/Male)
Installing the GPIO Zero Library
The first thing to do it is to update your repositories list:
sudo apt-get update
Then install the package of your choice. Both Python 3 and Python 2 are supported. Python 3 is recommended:
sudo apt-get install python3-gpiozero
Important to mention that GPIO Zero Library uses Broadcom (BCM) pin numbering for the GPIO pins, as opposed to physical (board) numbering. Any pin marked “
GPIO ” in the above diagram can be used as a pin number. For example, if an LED was attached to “
GPIO18 ” you would specify the pin number as 18 rather than 12.