Python Picamera with GPIO Zero

Python Picamera with GPIO Zero

Picamera workshop given at Pi Towers Raspberry Jam, October 2016

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

October 15, 2016
Tweet

Transcript

  1. Python Picamera with GPIO Zero Introducing the camera board and

    Python module
  2. Raspberry Pi camera module - 5Mpx / 8Mpx - Full

    HD - Photo & video - Command line - Python module - Infra-red camera
  3. Connect the camera

  4. Add a GPIO Button

  5. Boot the Pi and open Python 3

  6. IDLE Python Shell >>> from picamera import PiCamera >>> from

    gpiozero import Button >>> camera = PiCamera() >>> button = Button(17) >>> button.when_pressed = camera.start_preview >>> button.when_released = camera.stop_preview
  7. Open a new file • File > New File •

    File > Save • Save as camera.py
  8. Take a selfie from picamera import PiCamera from time import

    sleep camera = PiCamera() camera.start_preview() sleep(3) camera.capture("/home/pi/image.jpg") camera.stop_preview() Save and run: Ctrl + S F5
  9. Add GPIO Button code from picamera import PiCamera from gpiozero

    import Button from time import sleep camera = PiCamera() button = Button(17) camera.start_preview() button.wait_for_press() sleep(3) camera.capture("/home/pi/button.jpg") camera.stop_preview()
  10. Add a loop camera.start_preview() for i in range(5): button.wait_for_press() sleep(3)

    camera.capture("/home/pi/button%s.jpg" % i) camera.stop_preview()
  11. Picamera effects

  12. Picamera effects camera.start_preview() button.wait_for_press() camera.image_effect = 'negative' sleep(5) camera.capture("/home/pi/negative.jpg") camera.stop_preview()

    Try more effects: - negative - colorswap - sketch - emboss
  13. Picamera effects import random camera.start_preview() for i in range(5): button.wait_for_press()

    effect = random.choice(list(camera.IMAGE_EFFECTS)) camera.image_effect = effect camera.annotate_text = effect sleep(5) camera.capture("/home/pi/%s.jpg" % effect) camera.stop_preview() Try more effects: - negative - colorswap - sketch - emboss
  14. Documentation and help guides • picamera.readthedocs.io • gpiozero.readthedocs.io • raspberrypi.org/resources

    • raspberrypi.org/education/downloads
  15. What next? • Time-lapse • Stop motion animation • Wildlife

    camera
  16. What next? • Sensor trigger • Send to social media

    • Robotics