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
170
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
180
Live Highlights in BBC iPlayer
bennuttall
0
51
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
120
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
70
Running a Python Package Index for Raspberry Pi
bennuttall
0
77
From Acorns to Raspberries
bennuttall
0
60
Innovation in the newsroom
bennuttall
0
77
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
140
How to market your open source project
bennuttall
0
190
Other Decks in Programming
See All in Programming
Security_for_introducing_eBPF
kentatada
0
110
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
1
770
快速入門可觀測性
blueswen
0
320
Discord Bot with AI -for English learners-
xin9le
1
120
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
740
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Refactor your code - refactor yourself
xosofox
1
260
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
命名をリントする
chiroruxx
1
380
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
For a Future-Friendly Web
brad_frost
175
9.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Git: the NoSQL Database
bkeepers
PRO
427
64k
What's in a price? How to price your products and services
michaelherold
243
12k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
How GitHub (no longer) Works
holman
311
140k
Producing Creativity
orderedlist
PRO
341
39k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.2k
RailsConf 2023
tenderlove
29
940
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
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