Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
GPIO Zero - AmsterJam
Ben Nuttall
September 09, 2017
Programming
0
95
GPIO Zero - AmsterJam
GPIO Zero talk given at AmsterJam
Ben Nuttall
September 09, 2017
Tweet
Share
More Decks by Ben Nuttall
See All by Ben Nuttall
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
6
Running a Python Package Index for Raspberry Pi
bennuttall
0
26
From Acorns to Raspberries
bennuttall
0
9
Innovation in the newsroom
bennuttall
0
16
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
44
How to market your open source project
bennuttall
0
79
Manage your own Pi Cloud with hostedpi
bennuttall
0
41
Tools for maintaining an open source project
bennuttall
0
39
Tools for maintaining an open source Python project
bennuttall
0
67
Other Decks in Programming
See All in Programming
Enzyme から React Native Testing Library に移行した経緯 / 2022-07-20
tamago3keran
1
160
フロントエンドエンジニアが変える現場のモデリング意識/modeling-awareness-changed-by-front-end-engineers
uggds
32
13k
Register-based calling convention for Go functions
cjamhe01385
0
410
ZOZOTOWNにおけるDatadogの活用と、それを支える全社管理者の取り組み / 2022-07-27
tippy
1
3.3k
Getting Started With Data Structures
adoranwodo
1
260
Regular expressions basics/正規表現の基本
kishikawakatsumi
6
260
kintone × LINE Bot で餃子検定Botを作った話
naberina
0
330
Better Angular Architectures: Architectures with Standalone Components @DWX2022
manfredsteyer
PRO
1
410
ベストプラクティス・ドリフト
sssssssssssshhhhhhhhhh
1
210
Rに管理されてみる
kazutan
0
260
回帰分析ではlm()ではなくestimatr::lm_robust()を使おう / TokyoR100
dropout009
0
4.5k
Untangling Coroutine Testing (Droidcon Berlin 2022)
zsmb
1
490
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
253
12k
Robots, Beer and Maslow
schacon
152
7.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
225
130k
Become a Pro
speakerdeck
PRO
3
910
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
119
28k
Building Flexible Design Systems
yeseniaperezcruz
310
34k
A designer walks into a library…
pauljervisheath
196
16k
KATA
mclloyd
7
8.8k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
10k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
181
15k
Raft: Consensus for Rubyists
vanstee
127
5.5k
Bash Introduction
62gerente
598
210k
Transcript
GPIO Zero Ben Nuttall Raspberry Pi Foundation UK Charity 1129409
Ben Nuttall • Raspberry Pi Community Manager • Based in
Cambridge • Creator of gpiozero python library • Columnist on opensource.com • github.com/bennuttall • twitter.com/ben_nuttall • ben@raspberrypi.org
GPIO Pins – General Purpose Input/Output
GPIO Zero: a friendly API for GPIO devices from gpiozero
import LED led = LED(17) led.on()
Multi-paradigm: procedural from gpiozero import LED, Button led = LED(17)
button = Button(4) while True: if button.is_pressed: led.on() else: led.off()
Multi-paradigm: event-driven from gpiozero import LED, Button led = LED(17)
button = Button(4) button.when_pressed = led.on button.when_released = led.off
Multi-paradigm: declarative from gpiozero import LED, Button led = LED(17)
button = Button(4) led.source = button.values
GPIO Zero supports...
GPIO Zero Device Hierarchy!
.value >>> led = PWMLED(17) >>> led.value 0.0 >>> led.on()
>>> led.value 1.0 >>> led.value = 0
.value >>> led = PWMLED(17) >>> pot = MCP3008() >>>
led.value = pot.value
.value >>> led = PWMLED(17) >>> pot = MCP3008() >>>
led.value = pot.value >>> while True: ... led.value = pot.value
Source / Values Output Device .value .values .source Input Device
.value .values
Source / Values Output Device .value .values .source Input Device
.value .values
Source / Values from gpiozero import LED, Button led =
LED(17) button = Button(2) led.source = button.values
Processing values Output Device .value .values .source Input Device .value
.values function
Source tools from gpiozero import Button, LED from gpiozero.tools import
negated led = LED(4) btn = Button(17) led.source = negated(btn.values)
Combining values Output Device .value .values .source Input Device .value
.values Source tool Input Device .value .values
Source tools from gpiozero import Button, LED from gpiozero.tools import
all_values button_a = Button(2) button_b = Button(3) led = LED(17) led.source = all_values(button_a.values, button_b.values)
Supporting multiple back-ends • RPi.GPIO • Implemented in C, current
default • RPIO • Implemented in C • pigpio • Python wrapper for C library, runs as daemon, remote pins • Native • Pure Python, limited functionality, experimental • MockPin & MockPWMPin • Pure Python, used in test suite
MockPin $ GPIOZERO_PIN_FACTORY=mock python3 >>> from gpiozero import LED >>>
led = LED(22) >>> led.blink() >>> led.value True >>> led.value False
MockPin >>> from gpiozero import LED >>> led = LED(22)
>>> button = Button(23) >>> led.source = button.values >>> led.value False >>> button.pin.drive_low() >>> led.value True
pigpio - remote GPIO from Pi or PC
pigpio - remote GPIO from Pi or PC from gpiozero
import LED from gpiozero.pins.pigpio import PiGPIOFactory factory = PiGPIOFactory('192.168.0.2') led = LED(22, pin_factory=factory) led.blink()
pigpio - remote GPIO from Pi or PC $ PIGPIO_ADDR=192.168.0.2
python3 led.py from gpiozero import LED led = LED(22) led.blink()
Internal devices • TimeOfDay • PingServer • CPUTemperature • More
coming soon • Make your own!
Energenie tortoise lamp from gpiozero import Energenie, TimeOfDay from datetime
import time lamp = Energenie(1) daytime = TimeOfDay(time(9), time(18)) lamp.source = daytime.values
Is the internet working? from gpiozero import LED, PingServer from
gpiozero.tools import negated green = LED(17) red = LED(18) google = PingServer('google.com') green.source = google.values green.source_delay = 60 red.source = negated(green.values)
CPU Temperature from gpiozero import LEDBarGraph, CPUTemperature cpu = CPUTemperature(min_temp=50,
max_temp=90) leds = LEDBarGraph(2, 3, 4, 5, 6, 7, 8, pwm=True) leds.source = cpu.values
guizero
Raspberry Pi Desktop x86
Raspberry Pi Desktop x86 – Remote GPIO
GitHub
pinout command line tool
Read the docs!
The MagPi
GPIO Zero Book
GPIO Zero Ben Nuttall Raspberry Pi Foundation UK Charity 1129409