Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python Picamera with GPIO Zero

Python Picamera with GPIO Zero

Picamera workshop given at Pi Towers Raspberry Jam, October 2016

Ben Nuttall

October 15, 2016
Tweet

More Decks by Ben Nuttall

Other Decks in Programming

Transcript

  1. Raspberry Pi camera module - 5Mpx / 8Mpx - Full

    HD - Photo & video - Command line - Python module - Infra-red camera
  2. 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
  3. Open a new file • File > New File •

    File > Save • Save as camera.py
  4. 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
  5. 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()
  6. 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()
  7. 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