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
Programming paradigms for physical computing an...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ben Nuttall
April 24, 2018
Programming
0
170
Programming paradigms for physical computing and IoT
Talk given at London Raspberry Pint April 2018 meetup
Ben Nuttall
April 24, 2018
Tweet
Share
More Decks by Ben Nuttall
See All by Ben Nuttall
Numeronyms are obnoxious
bennuttall
0
450
Live Highlights in BBC iPlayer
bennuttall
0
130
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
200
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
140
Running a Python Package Index for Raspberry Pi
bennuttall
0
170
From Acorns to Raspberries
bennuttall
0
150
Innovation in the newsroom
bennuttall
0
200
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
220
How to market your open source project
bennuttall
0
260
Other Decks in Programming
See All in Programming
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
200
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
190
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
1
400
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
290
Oxlint JS plugins
kazupon
1
1.2k
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1.1k
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
3
380
AI活用のコスパを最大化する方法
ochtum
0
120
JPUG勉強会 OSSデータベースの内部構造を理解しよう
oga5
2
230
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
200
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
240
並行開発のためのコードレビュー
miyukiw
2
2.2k
Featured
See All Featured
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
230
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
92
A Tale of Four Properties
chriscoyier
162
24k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
65
エンジニアに許された特別な時間の終わり
watany
106
240k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Utilizing Notion as your number one productivity tool
mfonobong
4
240
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
140
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
Crafting Experiences
bethany
1
75
Transcript
Programming paradigms for physical computing and IoT Ben Nuttall Raspberry
Pi Foundation UK Charity 1129409
Ben Nuttall • Raspberry Pi Community Manager • Based in
Cambridge • Creator of gpiozero python library and piwheels project • 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 (polling) from gpiozero import LED, Button led =
LED(17) button = Button(4) while True: if button.is_pressed: led.on() else: led.off()
Multi-paradigm: procedural (blocking) from gpiozero import LED, Button led =
LED(17) button = Button(4) while True: button.wait_for_press() led.on() button.wait_for_release() 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 0.0 >>> pot.value 0.510145879738202 >>> led.value = pot.value
.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)
Cross-platform • Raspbian (Raspberry Pi) • Raspberry Pi Desktop x86
(PC) • Linux (PC) • Windows (PC) • Mac OS (Mac)
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, Button >>> 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()
Raspberry Pi Desktop x86
Raspberry Pi Desktop x86 – Remote GPIO
Raspberry Pi Desktop x86 – GPIO expander
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
Custom internal devices from gpiozero import InternalDevice class FileReader(InternalDevice): @property
def value(self): with open('value.txt') as f: return int(f.read().strip())
Blue Dot
Multi-paradigm: procedural (polling) from gpiozero import LED from bluedot import
BlueDot led = LED(17) bd = BlueDot() while True: if bd.is_pressed: led.on() else: led.off()
Multi-paradigm: procedural (blocking) from gpiozero import LED from bluedot import
BlueDot led = LED(17) bd = BlueDot() while True: bd.wait_for_press() led.on() bd.wait_for_release() led.off()
Multi-paradigm: event-driven from gpiozero import LED from bluedot import BlueDot
led = LED(17) bd = BlueDot() bd.when_pressed = led.on bd.when_released = led.off
Multi-paradigm: declarative from gpiozero import LED from bluedot import BlueDot
led = LED(17) bd = BlueDot() led.source = bd.values
IoT devices? from somelib import GardenLight, LightSensor, MotionSensor from gpiozero.tools
import all_values, negated garden = GardenLight() light = LightSensor() motion = MotionSensor() garden.source = all_values(negated(light.values), motion.values)
guizero
GitHub
pinout command line tool
Read the docs!
The MagPi
Programming paradigms for physical computing and IoT Ben Nuttall Raspberry
Pi Foundation UK Charity 1129409