Using Your
To Have Fun With
GPIO Zero
by Alex Eames
Introduction
Adding 8 Channels of Analog Input
The RasPiO
®1
Analog Zero offers a compact, inexpensive, easy way to
add eight analog
2
channels to your Raspberry Pi.
This enables simultaneous reading of 8 input Voltages up to 3.3V (or
more with some tricks I'll show you later). This can be used to...
•
read sensors
•
use potentiometer dials for control or display
•
make a weather station
•
make a digital thermometer
•
make a multi-channel Voltmeter
GPIO Zero
Ben Nuttall and Dave Jones have created GPIO Zero as the ideal way
into Python GPIO programming. Using it with the RasPiO Analog Zero
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 measuring and controlling the world with the
RasPiO Analog Zero, Raspberry Pi and GPIO Zero.
All code in this guide and in the
analogzero Github repository
is in
Python 3.
1
2
RasPiO is a trademark of Alex Eames. Raspberry Pi is a trademark of the Raspberry Pi
Foundation
I use the US spelling for the word analog. In British English it's spelt analogue, but I got in the
habit of using analog when learning Arduino programming. Perhaps it's a silly reason, but
everyone has their quirks.
v0.32
© Alex Eames 2016
Using
RasPiO Analog Zero
with GPIO Zero
2 of 39
Analog Zero Instructions
The RasPiO Analog Zero 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.
MCP3008
RasPiO Analog Zero uses an MCP3008 analog to digital converter. It's
an SPI driven, 10-bit, 8-channel ADC. The
MCP3008 datasheet is here.
Ports Used by the Board
The MCP3008 analog to digital converter chip is connected to the SPI
ports MOSI, MISO, SCLK and CE0. All the Pi's GPIO ports
3
are broken
out to through-holes.
V
ref
is Tweakable
The MCP3008 is powered by the Pi's 3.3V (3V3) rail. This means that
the highest voltage the chip can measure directly is 3.3V.
If you are reading a sensor that outputs a lower voltage, you can tweak
V
ref
to a lower value in order to set the full-scale range of the 10-bit
(1023 steps) resolution.
e.g.
a TMP36 temperature sensor outputs 1V at
50°C. If you're going to be measuring temperatures below that,
tweaking V
ref
to 1.0V would get you 0.1°C resolution. If you used 3V3,
you'd have 0.33°C resolution.
3
Except GPIO26
v0.32
© Alex Eames 2016
Using
RasPiO Analog Zero
with GPIO Zero
3 of 39
By default V
ref
is set to 3V3 by placing the
jumper to connect V
ref
to 3V3 (as in the photo).
To set V
ref
to your own value (not greater than
3.3V) connect the V
ref
pin to your chosen
voltage source (it must have common GND
with the Pi).
V
ref
pin showing jumper
SPI Usage
The Pi's SPI can handle two devices natively. If you wish to add another
SPI device, ensure its chip-select pin is connected to CE1 or it will
interfere with the MCP3008 chip, which uses CE0.
SMT Pads On Rear
There are two surface mount pads on
the rear of the board.
These give an alternative location for
the bypass capacitors (for V
DD
and
V
ref
).
If you prefer to use these you can fit
your own 1µF 1206 capacitors (not
supplied).
SMT pads on reverse of board
If You Want More Than 10-bit Resolution...
The MCP3008 is a 10-bit ADC. 10-bit gives you 2
10
– 1 = 1023 steps of
resolution (values 0 to 1023).
If you have an application that requires greater resolution, the 12-bit
MCP3208 chip (not supplied) is a pin-compatible drop-in replacement.
It's also supported in GPIO Zero. 12-bit provides 4095 steps of
resolution.
Using
RasPiO Analog Zero
with GPIO Zero
v0.32
© Alex Eames 2016
4 of 39
Know Your RasPiO Analog Zero
The RasPiO Analog Zero has been designed to fit directly
4
on any 40-
pin consumer model of Raspberry Pi and make it as easy as possible
for people to get into analog sensing and control using GPIO Zero on
the Pi.
Anatomy of RasPiO Analog Zero
The RasPiO Analog Zero connects an MCP3008 ADC chip to your Pi,
breaks out the GPIO ports and provides a prototyping area with power
and ground rails, where you can add components of your choice.
There is also an 8-way female header for the analog inputs if you
choose to fit it.
4
It can fit on older 26-pin Pis with the use of a 26-pin stacking header. The MCP3008 will still
work, but some of the GPIO breakouts (the bottom 8) will not
v0.32
© Alex Eames 2016
Using
RasPiO Analog Zero
with GPIO Zero
5 of 39