Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Getting started with
Python picamera
@ben_nuttall
Connect your Camera
Boot the Pi and log in
Test the camera
Type raspistill -k and hit Enter
This starts the camera preview
Hit Ctrl + C to stop
Take a selfie!
Type raspistill -o image.jpg and hit Enter
raspistill is the command for using the camera
-o means “output”...
Check the photo is there
Run ls to see the photo is there
Run startx to boot to Desktop
Open File Manager
Open image
Double click image.jpg to view it
Open Terminal
Open IDLE as root
Type sudo idle3 & and hit Enter
sudo means super user do
IDLE is a Python application
& means open in a ...
New file
Go to File > New window
Save as camera.py
Take a selfie with Python
from picamera import PiCamera
from time import sleep
with PiCamera() as camera:
camera.start_pre...
View the photo from File Manager
Notice the difference in resolution between the file taken
from the command line and from...
GPIO pins
GPIO pins
Breadboard
Connect a GPIO push button
Add the button to the code
from picamera import PiCamera
from time import sleep
from RPi import GPIO
button = 17
GPIO.setm...
Press the button to take a picture
Run the script with F5
Wait for the preview
Press the push button to take a picture
View the photo from File Manager
Add a loop
with PiCamera() as camera:
camera.start_preview()
GPIO.wait_for_edge(button, GPIO.FALLING)
for i in range(5):
s...
What’s the difference?
GPIO.wait_for_edge(button, GPIO.FALLING)
for i in range(5):
sleep(3)
camera.capture('/home/pi/pictu...
What can you do?
Raspberry Pi Camera Resources
Raspberry Pi Resources
Upcoming SlideShare
Loading in …5
×

Picademy - Python picamera workshop

7,637 views

Published on

Getting started with the Python picamera library including wiring up a GPIO push button

Published in: Education
  • Be the first to comment

Picademy - Python picamera workshop

  1. 1. Getting started with Python picamera @ben_nuttall
  2. 2. Connect your Camera
  3. 3. Boot the Pi and log in
  4. 4. Test the camera Type raspistill -k and hit Enter This starts the camera preview Hit Ctrl + C to stop
  5. 5. Take a selfie! Type raspistill -o image.jpg and hit Enter raspistill is the command for using the camera -o means “output” image.jpg is the chosen filename
  6. 6. Check the photo is there Run ls to see the photo is there Run startx to boot to Desktop
  7. 7. Open File Manager
  8. 8. Open image Double click image.jpg to view it
  9. 9. Open Terminal
  10. 10. Open IDLE as root Type sudo idle3 & and hit Enter sudo means super user do IDLE is a Python application & means open in a new process
  11. 11. New file Go to File > New window Save as camera.py
  12. 12. Take a selfie with Python from picamera import PiCamera from time import sleep with PiCamera() as camera: camera.start_preview() sleep(5) camera.capture('/home/pi/image2.jpg') camera.stop_preview() Press F5 to run
  13. 13. View the photo from File Manager Notice the difference in resolution between the file taken from the command line and from Python This is due to default settings in raspistill and in Python picamera Resolution and other aspects are configurable
  14. 14. GPIO pins
  15. 15. GPIO pins
  16. 16. Breadboard
  17. 17. Connect a GPIO push button
  18. 18. Add the button to the code from picamera import PiCamera from time import sleep from RPi import GPIO button = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(button, GPIO.IN, GPIO.PUD_UP) with PiCamera() as camera: camera.start_preview() GPIO.wait_for_edge(button, GPIO.FALLING) camera.capture('/home/pi/image3.jpg') camera.stop_preview()
  19. 19. Press the button to take a picture Run the script with F5 Wait for the preview Press the push button to take a picture
  20. 20. View the photo from File Manager
  21. 21. Add a loop with PiCamera() as camera: camera.start_preview() GPIO.wait_for_edge(button, GPIO.FALLING) for i in range(5): sleep(3) camera.capture('/home/pi/picture%s.jpg' % i) camera.stop_preview()
  22. 22. What’s the difference? GPIO.wait_for_edge(button, GPIO.FALLING) for i in range(5): sleep(3) camera.capture('/home/pi/picture%s.jpg' % i) camera.stop_preview() for i in range(5): GPIO.wait_for_edge(button, GPIO.FALLING) sleep(3) camera.capture('/home/pi/picture%s.jpg' % i) camera.stop_preview()
  23. 23. What can you do?
  24. 24. Raspberry Pi Camera Resources
  25. 25. Raspberry Pi Resources

×