GPIO Zero
Programming
With
by Alex Eames
Introduction
Protected Ports Perfectly Positioned
The RasPiO
®1
Pro Hat was developed out of the perceived need for a
HAT which puts the
Raspberry Pi's GPIO ports in numerical order
and
clearly labelled. You don't have to count pins or wonder which port
you're connecting to. Each port has a female socket to plug your wires
or components into. The ports are arranged, along with plenty of
power and GND sockets, around a 72-point breadboard.
If you want to do some electronics, it's made a lot easier for you. LEDs
need no current-limiting resistors
because they are already built-in.
Pro Hat also has a
protection circuit on each GPIO port,
which means
you won't damage your Pi's ports by wiring something up incorrectly.
(But it is still possible to cause damage by directly shorting 3V3 or 5V
to GND.)
Additionally, if you want to bypass the 330 Ohm resistor on a GPIO
port, you can connect directly to the unprotected side where all the
ports
2
are broken out as through-holes. This is particularly useful for
buzzers, which usually require slightly over the 10mA limit imposed by
the resistors.
Ben Nuttall and Dave Jones have created GPIO Zero as the ideal way
into Python GPIO programming. Using it with the Pro HAT means there
is
nothing to install
before you can start playing.
Also, by keeping the board inexpensive, I hope it's realistic for
individuals, schools and jams to be able to get hold of some and
discover the joys of controlling the world with the Raspberry Pi and
GPIO Zero.
1
2
RasPiO is a trademark of Alex Eames. Raspberry Pi is a trademark of the Raspberry Pi Foundation
Apart from GPIO26, which is used for the HAT EEPROM
v0.1
© Alex Eames 2016
GPIO Zero Programming With
RasPiO Pro Hat
2 of 24
Pro Hat Instructions
The RasPiO Pro Hat uses the BCM GPIO port numbering scheme. This
is a perfect match for GPIO Zero.
Hardware Technical Overview
This page is mainly for the technically minded. If you just want to get on
with experimenting, you can skip to the next section.
Port Protection
The port protection is via a 3V3 Zener diode and 330 Ohm resistor on
each port. The Zener diode clips over-voltage down to a safe 3V3. The
330 Ohm resistor limits the current into or out of a port to 10 mA. This
is enough to prevent port damage in most situations.
Schematic of port protection circuit
Hardware Pull-ups
GPIOs 2, 3 and 26 all have hardware pull-ups. GPIOs 2 & 3 (the i
2
c
ports) have 2k pull-up resistors on them. GPIO 26 on the Pro Hat is also
connected to the EEPROM write-protect pin, which has a 1k pull-up.
This means that the default state for these pins is HIGH unless brought
LOW in software. So if you connect an LED to any of these ports it will
GPIO Zero Programming With
RasPiO Pro Hat
v0.1
© Alex Eames 2016
3 of 24
be (dimly) lit by default.
SPI Limitations
I've found that SPI devices (e.g. MCP3008) work fine, even through the
protected ports. In Beta-testing, it was discovered that some high-
speed SPI devices, like the PiTFT and other small SPI LCD colour
screens do not play nicely with the protection circuitry. This is not seen
as much of a problem as it falls outside the expected use of the Pro
Hat. But that's what Beta testing is for. Thanks
Ton van Overbeek
for
discovering that one.
If SPI is enabled on the Pi, the default state is HIGH for GPIOs 7 & 8
(CE0 & CE1). LEDs connected to these ports will be lit unless brought
LOW in software.
GPIO Zero Programming With
RasPiO Pro Hat
v0.1
© Alex Eames 2016
4 of 24
Know Your RasPiO Pro Hat
The RasPiO Pro Hat has been designed to fit any 40-pin consumer
model of Raspberry Pi and make it as easy as possible for people to get
into GPIO Zero programming on the Pi.
Anatomy of RasPiO Pro Hat
The RasPiO Pro Hat has female header sockets to plug in wires and
components. In the wiring diagrams we'll remove these to make things
clearer.
Breadboards give an easy
way to make connections.
The five points in each row
are connected to each other.
But each of the rows
(a, b, c) are completely
separate from each other.
GPIO Zero Programming With
RasPiO Pro Hat
v0.1
© Alex Eames 2016
5 of 24