Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GPIO Zero - AmsterJam
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ben Nuttall
September 09, 2017
Programming
250
0
Share
GPIO Zero - AmsterJam
GPIO Zero talk given at AmsterJam
Ben Nuttall
September 09, 2017
More Decks by Ben Nuttall
See All by Ben Nuttall
Numeronyms are obnoxious
bennuttall
0
490
Live Highlights in BBC iPlayer
bennuttall
0
160
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
220
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
160
Running a Python Package Index for Raspberry Pi
bennuttall
0
190
From Acorns to Raspberries
bennuttall
0
160
Innovation in the newsroom
bennuttall
0
220
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
240
How to market your open source project
bennuttall
0
280
Other Decks in Programming
See All in Programming
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
1k
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.4k
ふつうのFeature Flag実践入門
irof
7
3.4k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
0
110
自動レビューエンジンの実装と運用 ~レビューのない世界へ~
kurukuru1999
2
310
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
2
550
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
2
360
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
320
inferと仲良くなる10分間
ryokatsuse
1
330
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
150
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.2k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
WENDY [Excerpt]
tessaabrams
11
38k
Design in an AI World
tapps
1
220
YesSQL, Process and Tooling at Scale
rocio
174
15k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
200
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
Practical Orchestrator
shlominoach
191
11k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
540
Measuring & Analyzing Core Web Vitals
bluesmoon
9
850
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 •
[email protected]
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