Python and Raspberry Pi - FOSDEM 2017

A1995c9abe48450ce2f82d93ca0b863f?s=47 Ben Nuttall
February 05, 2017

Python and Raspberry Pi - FOSDEM 2017

Talk on Python and Raspberry Pi at FOSDEM 2017

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

February 05, 2017
Tweet

Transcript

  1. 2.

    Ben Nuttall • Raspberry Pi Community Manager • Based in

    Cambridge, UK • Creator of gpiozero python library • Columnist on opensource.com • github.com/bennuttall • twitter.com/ben_nuttall • ben@raspberrypi.org
  2. 4.

    Raspberry Pi Foundation • Educational charity founded in 2009 •

    Owns trading subsidiary Raspberry Pi Trading Ltd • Trading profits fund educational programmes
  3. 5.

    Our mission “Putting the power of digital making into the

    hands of people all over the world” So that people are: • Capable of understanding and shaping an increasingly digital world • Able to solve the problems that matter to them, both as makers and entrepreneurs • Equipped for the jobs of the future
  4. 6.

    We do this by providing... • Low-cost, high-performance computers •

    Outreach and education programmes • Free resources and teacher training p
  5. 7.

    Current models • Raspberry Pi 3 • 64-bit quad-core ARMv8

    @ 1.2GHz • 1GB RAM • $35 • Raspberry Pi Zero • 32-bit single-core ARMv6 @ 1GHz • 512MB RAM • $5
  6. 11.

    Physical computing • Flashy lights • Motors & robots •

    Photo & video • Sensors • Internet of Things • Engaging and empowering
  7. 15.

    Python - RPi.GPIO import RPi.GPIO as GPIO from time import

    sleep GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(17, GPIO.OUT) while True: GPIO.output(17, GPIO.HIGH) sleep(1) GPIO.output(17, GPIO.LOW) sleep(1)
  8. 16.

    Python - GPIO Zero from gpiozero import LED from time

    import sleep led = LED(17) while True: led.on() sleep(1) led.off() sleep(1)
  9. 18.

    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()
  10. 19.

    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
  11. 20.
  12. 23.

    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
  13. 25.

    pigpio - remote GPIO from Pi or PC from gpiozero

    import LED from gpiozero.pins.pigpiod import PiGPIOPin led = LED(PiGPIOPin(22, host='192.168.0.2')) led.blink()
  14. 26.

    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()
  15. 27.

    Picamera • 8 megapixels (v2) – v1 was 5mpx •

    Visible light & infra-red versions available • 1080p30, 720p60 and VGA90 video • Command line interface and Python library
  16. 28.

    Picamera - capture from picamera import PiCamera from time import

    sleep camera = PiCamera() camera.start_preview() sleep(3) camera.capture('/home/pi/Desktop/image.jpg') camera.stop_preview()
  17. 29.

    Picamera – record video from picamera import PiCamera from time

    import sleep camera = PiCamera() camera.start_preview() camera.start_recording('/home/pi/video.h264') sleep(10) camera.stop_recording() camera.stop_preview()
  18. 30.

    Picamera + GPIO push button from picamera import PiCamera from

    gpiozero import Button camera = PiCamera() button = Button(17) camera.start_preview() button.wait_for_press() camera.capture('/home/pi/Desktop/image.jpg') camera.stop_preview()
  19. 31.

    Picamera image effects from picamera import PiCamera from time import

    sleep camera = PiCamera() camera.start_preview() for effect in camera.IMAGE_EFFECTS: camera.image_effect = effect camera.annotate_text = "Effect: %s" % effect sleep(5) camera.stop_preview()
  20. 34.
  21. 35.

    Energenie tortoise lamp from gpiozero import Energenie, TimeOfDay from datetime

    import time lamp = Energenie(1) daytime = TimeOfDay(time(8), time(20)) lamp.source = daytime.values
  22. 36.

    Sense HAT • Special made for Tim Peake's Astro Pi

    mission • Sensors, LED display & joystick • Great for science, games and creativity • Works on any Pi model • Emulators also available
  23. 37.
  24. 38.

    Sense HAT >>> from sense_hat import SenseHat >>> sense =

    SenseHat() >>> sense.show_message(“Hello world”) >>> sense.temperature >>> sense.humidity >>> sense.accelerometer >>> sense.gyroscope >>> sense.orientation
  25. 39.

    Sense HAT from sense_hat import SenseHat sense = SenseHat() while

    True: r = 255 * sense.humidity / 100 sense.clear(r, 0, 0)
  26. 45.

    Python libraries • Contribute to: – gpiozero – picamera –

    sense hat – more! • Help maintainers upgrade modules to Python 3 • Create your own Python libraries for Raspberry Pi things
  27. 46.

    The MagPi • Community magazine established in 2012 (as free

    PDF download) • Now the official Raspberry Pi magazine • Paper copies on sale in UK/US shops and online • Still a free PDF download • Occasionally comes with a free computer • Book series (also available for free) • raspberrypi.org/magpi
  28. 47.

    Raspberry Jam • Independently organised community events • Family-friendly •

    Mix of meetup / conference / workshop styles • Contact me about setting one up! • raspberrypi.org/jam
  29. 48.

    Code Club • Free volunteer-led after school clubs for children

    • Projects provided using Scratch, HTML and Python • Training and support provided for volunteers • Help translating materials • codeclubworld.org