Physical computing with Python and Raspberry Pi Ben Nuttall - - PowerPoint PPT Presentation

physical computing with python and raspberry pi ben
SMART_READER_LITE
LIVE PREVIEW

Physical computing with Python and Raspberry Pi Ben Nuttall - - PowerPoint PPT Presentation

Physical computing with Python and Raspberry Pi Ben Nuttall Raspberry Pi Foundation Ben Nuttall Education Developer Advocate at Raspberry Pi Foundation Software & project development Learning resources & teacher training


slide-1
SLIDE 1

Physical computing with Python and Raspberry Pi Ben Nuttall Raspberry Pi Foundation

slide-2
SLIDE 2
slide-3
SLIDE 3

Ben Nuttall

  • Education Developer Advocate at Raspberry Pi Foundation

– Software & project development – Learning resources & teacher training – Outreach

  • Based in Cambridge, UK
  • @ben_nuttall on Twitter
  • Speaker at EuroPython, PyConUK, PySS, PyCon Ireland & EuroSciPy

in 2014

slide-4
SLIDE 4

Raspberry Pi 2

  • 900MHz quad core ARM7
  • 1GB RAM
  • Backwards-compatible with Pi 1
  • Same form factor as B+
  • Still $35 (B+ now $25, A+ $20)
slide-5
SLIDE 5

All about Education

  • Raspberry Pi Foundation, registered UK charity 1129409
  • Founded in 2009 to aid computing education
  • On general sale since 2012, available to all worldwide

– Sold to education, industry and hobbyists – Sold 6 million to date

  • Free learning resources for makers and educators
  • Free teacher training - Picademy (currently UK, soon USA)
slide-6
SLIDE 6

Ben Croston – beer brewing

slide-7
SLIDE 7

Dave Jones - microscopy

picamera.readthedocs.org

slide-8
SLIDE 8

Raspbian

  • Foundation-issued Debian-based distribution

– Currently based on Wheezy – Jessie image coming soon

  • Image supports Pi 1 and Pi 2
  • Software pre-installed

– Python 3 (also Python 2), Ruby, Java, Mathematica, etc. – GPIO, Picamera, (soon pip too)

  • Alternative distributions are available, but not supported, e.g:

– Ubuntu MATE (Pi 2) – Ubuntu Snappy Core (Pi 2) – Arch Linux

www.raspberrypi.org/downloads

slide-9
SLIDE 9

GPIO Pins – General Purpose Input/Output

rasp.io

slide-10
SLIDE 10

Analogue?

  • No native analogue on Raspberry Pi
  • Options:

– Analogue inputs can be read via ADC – Various Arduino-compatible add-on boards available – Use PySerial to read Arduino inputs over USB

slide-11
SLIDE 11

Python library - RPi.GPIO

  • Included in Raspbian
  • Implemented in C
  • Features:

– Confjgure pins as input/output – Read inputs (high/low) – Set outputs (high low) – Wait for edge (wait for input to go high/low) – Pin event detection (callback on input pin change)

slide-12
SLIDE 12

3V3 = always on

slide-13
SLIDE 13

GPIO = user controllable

slide-14
SLIDE 14

Flash LED with RPi.GPIO

from RPi import GPIO from time import sleep GPIO.setmode(GPIO.BCM) led = 2 GPIO.setup(led, GPIO.OUT) while True: GPIO.output(led, True) sleep(1) GPIO.output(led, False) sleep(1)

slide-15
SLIDE 15

Push button stop motion

slide-16
SLIDE 16

Push button stop motion

from picamera import PiCamera from RPi import GPIO from time import sleep button = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(button, GPIO.IN, GPIO.PUD_UP)

slide-17
SLIDE 17

Push button stop motion

with PiCamera() as camera: camera.start_preview() frame = 1 while True: GPIO.wait_for_edge(button, GPIO.FALLING) camera.capture('/home/pi/animation/frame%03d.jpg' % frame) frame += 1 camera.stop_preview()

slide-18
SLIDE 18

GPIO Music Box

slide-19
SLIDE 19

GPIO Music Box – GPIO events

GPIO.add_event_detect( button, GPIO.FALLING, callback=play, bouncetime=1000 )

www.raspberrypi.org/learning/gpio-music-box/

slide-20
SLIDE 20

GPIO Music Box – GPIO events

sound_pins = { 2: drum, 3: cymbal, } def play(pin): sound = sound_pins[pin] sound.play()

www.raspberrypi.org/learning/gpio-music-box/

slide-21
SLIDE 21

CamJam EduKit

camjam.me/edukit

slide-22
SLIDE 22

The Gertboard

slide-23
SLIDE 23

Ryanteck RPi Motor Controller Board

slide-24
SLIDE 24

Pimoroni - Pibrella

slide-25
SLIDE 25

Pibrella – traffjc lights

import pibrella from time import sleep pibrella.light.green.on() sleep(1) pibrella.light.amber.on() sleep(1) pibrella.light.red.on()

slide-26
SLIDE 26

Pibrella – button press event

def flash(pin): pibrella.light.on() sleep(1) pibrella.light.off() pibrella.button.pressed(flash)

slide-27
SLIDE 27

Energenie – remote controlled power sockets

slide-28
SLIDE 28

Energenie – remote controlled power sockets

import energenie from time import sleep energenie.switch_on() sleep(5) energenie.switch_off() pythonhosted.org/energenie

slide-29
SLIDE 29

Energenie – web app

pythonhosted.org/energenie /examples/web/

slide-30
SLIDE 30

26->40 pin header

slide-31
SLIDE 31

Raspberry Pi HATs – Hardware Attached on Top

slide-32
SLIDE 32

Sous Vide cooking

slide-33
SLIDE 33

Chef HAT

WIP – github.com/bennuttall/chef-hat pypi.python.org/pypi/chef-hat

slide-34
SLIDE 34

Chef HAT – temperature moderation

if self.temperature < self.target_temperature: self.turn_cooker_on() else: self.turn_cooker_off()

slide-35
SLIDE 35

DOTS board

www.raspberrypi.org/dots

slide-36
SLIDE 36

DOTS board software

def get_selected_colors(): return [COLOR_PINS[pin] for pin in COLOR_PINS if pin_is_active(pin)] def enough_dots_connected(): active_pins = sum(pin_is_active(pin) for pin in DOT_PINS) return active_pins > MINIMUM_DOTS_REQUIRED def pin_is_active(pin): GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP) state = GPIO.input(pin) GPIO.setup(pin, GPIO.IN, GPIO.PUD_OFF) return state == 0

pypi.python.org/pypi/rpi-dots

slide-37
SLIDE 37

Plantpot Greenhouse

slide-38
SLIDE 38

Capacitive Touch HAT

slide-39
SLIDE 39

Pimoroni - HATs

http://shop.pimoroni.com/collections/hats

slide-40
SLIDE 40

Weather Station kit

slide-41
SLIDE 41

Astro Pi

slide-42
SLIDE 42

Astro Pi / Sense HAT

  • 8x8 RGB LED matrix
  • Temperature
  • Humidity
  • Pressure
  • Accelerometer
  • Gyroscope
  • Magnetometer
  • Mini joystick

pypi.python.org/pypi/astro-pi

slide-43
SLIDE 43
slide-44
SLIDE 44

Thank you - any questions?