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
Ben Nuttall
September 09, 2017
Programming
0
150
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
Numeronyms are obnoxious
bennuttall
0
81
Live Highlights in BBC iPlayer
bennuttall
0
24
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
98
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
55
Running a Python Package Index for Raspberry Pi
bennuttall
0
66
From Acorns to Raspberries
bennuttall
0
45
Innovation in the newsroom
bennuttall
0
57
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
110
How to market your open source project
bennuttall
0
170
Other Decks in Programming
See All in Programming
企業向け生成AIアプリの 開発から得られた知見
takaakikakei
0
310
CSC307 Lecture 09
javiergs
PRO
1
500
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
GraphQL はいいぞ! ~Laravel で学ぶ GraphQL 入門~
azuki
1
160
MIERUNE BBQにおけるユーザー中心設計()
mierune
PRO
1
110
リハビリmruby
kishima
1
160
Polarsの成長: v0.14からv1.0までの変遷と今後の展望
zerebom
1
350
最近追加した型の紹介とその振り返り
aki19035vc
0
170
12年前の『型システム入門』翻訳の思い出話
mame
11
1.2k
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
260
AWS初心者ってどうやってAWSを学ぶ?〜アプリエンジニアがやってよかったアーキテクチャ学習方法〜
yamanashi_ren01
0
190
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
Featured
See All Featured
Design by the Numbers
sachag
277
18k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
Typedesign – Prime Four
hannesfritz
37
2.2k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
15
4.9k
Debugging Ruby Performance
tmm1
71
11k
Code Reviewing Like a Champion
maltzj
517
39k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Navigating Team Friction
lara
181
13k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
26
2.1k
Documentation Writing (for coders)
carmenintech
63
4.2k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
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