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
Physical computing with GPIO Zero
Search
Ben Nuttall
October 15, 2015
Education
1
310
Physical computing with GPIO Zero
Short talk in my new GPIO Python library for Raspberry Pi, given at Coding Evening in London
Ben Nuttall
October 15, 2015
Tweet
Share
More Decks by Ben Nuttall
See All by Ben Nuttall
Numeronyms are obnoxious
bennuttall
0
150
Live Highlights in BBC iPlayer
bennuttall
0
42
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
110
Rapid prototyping in BBC News with Python and AWS
bennuttall
0
64
Running a Python Package Index for Raspberry Pi
bennuttall
0
69
From Acorns to Raspberries
bennuttall
0
53
Innovation in the newsroom
bennuttall
0
69
Innovation in the newsroom - MOS Running Order Manager
bennuttall
0
130
How to market your open source project
bennuttall
0
180
Other Decks in Education
See All in Education
脳卒中になってしまった さあ、どうする
japanstrokeassociation
0
630
ACT FAST 20240830
japanstrokeassociation
0
320
Qualtricsで相互作用実験する「SMARTRIQS」実践編
kscscr
0
290
Comezando coas redes
irocho
0
370
HCI Research Methods - Lecture 7 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
700
The Blockchain Game
jscottmo
0
3.7k
Library Prefects 2024-2025
cbtlibrary
0
110
アニメに学ぶチームの多様性とコンピテンシー
terahide
0
240
Introduction - Lecture 1 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.7k
セキュリティ・キャンプ全国大会2024 S17 探査機自作ゼミ 事前学習・当日資料
sksat
3
850
1106
cbtlibrary
0
410
小学生にスクラムを試してみた件~中学受検までの100週間の舞台裏~
ukky86
0
340
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
A better future with KSS
kneath
238
17k
Statistics for Hackers
jakevdp
796
220k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Thoughts on Productivity
jonyablonski
67
4.3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Git: the NoSQL Database
bkeepers
PRO
427
64k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Transcript
Physical computing with GPIO Zero Ben Nuttall Raspberry Pi Foundation
UK Charity 1129409
Ben Nuttall • Education Developer Advocate at the Raspberry Pi
Foundation – Software & project development – Learning resources & teacher training – Outreach • Hobbyist turned employee • Based in Cambridge • @ben_nuttall on Twitter
Python – RPi.GPIO import RPi.GPIO as GPIO from time import
sleep GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) led = 17 GPIO.setup(led, GPIO.OUT) while True: GPIO.output(led, True) sleep(1) GPIO.output(led, False) sleep(1)
Python – GPIO Zero from gpiozero import LED from time
import sleep led = LED(17) while True: led.on() sleep(1) led.off() sleep(1)
LED from gpiozero import LED from time import sleep led
= LED(17) led.on() # on led.off() # off led.toggle() # on>off or off>on led.blink() # flash on/off continuously
LED + Button from gpiozero import LED, Button led =
LED(17) button = Button(3) button.when_pressed = led.on button.when_released = led.off
Motion sensor from gpiozero import LED, MotionSensor led = LED(2)
sensor = MotionSensor(3) sensor.when_motion = led.on sensor.when_no_motion = led.off
Traffic Lights from gpiozero import TrafficLights lights = TrafficLights(9, 10,
11) lights.on() # all on lights.off() # all off lights.red.on() # red on lights.toggle() # swap state of all lights
Traffic Lights sequence lights.green.on() lights.amber.off() lights.red.off() while True: sleep(10) lights.green.off()
lights.amber.on() sleep(1) lights.amber.off() lights.red.on() sleep(10) lights.amber.on() sleep(1) lights.green.on() lights.amber.off() lights.red.off()
Full colour LED from gpiozero import RGBLED led = RGBLED(2,
3, 4) led.red.on() # full red led.color = (255, 0, 255) # purple led.blue = 100 # dim the blue value to 100 # now (255, 0, 100)
Motor from gpiozero import Motor from time import sleep motor
= Motor(forward=17, back=18) while True: motor.forward() sleep(5) motor.backward() sleep(5)
Robot from gpiozero import Robot from time import sleep robot
= Robot(left=(17, 18), right=(22, 23)) while True: robot.forward() sleep(10) robot.left() sleep(1)
Button controlled Robot from gpiozero import RyanteckRobot, Button robot =
RyanteckRobot() left = Button(26) right = Button(16) fw = Button(21) bw = Button(20) fw.when_pressed = robot.forward fw.when_released = robot.stop left.when_pressed = robot.left left.when_released = robot.stop right.when_pressed = robot.right right.when_released = robot.stop bw.when_pressed = robot.backward bw.when_released = robot.stop
Analogue - potentiometers from gpiozero import RGBLED, MCP3008 led =
RGBLED(2, 3, 4) pot = MCP3008() while True: red = pot.value led.color = (red, 0, 0) # set brightness of red
GPIO Zero - beta • www.pythonhosted.org/gpiozero – Installation instructions –
Documentation – Examples • Google Doc (linked from documentation) – Suggestions – Feedback • Contact me –
[email protected]
– @ben_nuttall on Twitter • #gpiozero on Twitter
CamJam EduKit • £5 starter kit (kit 1) • £7
sensors kit (kit 2) • £17 robotics kit (kit 3) • Free worksheets • Very reusable
Physical computing with GPIO Zero Ben Nuttall Raspberry Pi Foundation
UK Charity 1129409