picademy - python picamera workshop
TRANSCRIPT
![Page 1: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/1.jpg)
Getting started withPython picamera
@ben_nuttall
![Page 2: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/2.jpg)
Connect your Camera
![Page 3: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/3.jpg)
Boot the Pi and log in
![Page 4: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/4.jpg)
Test the camera
Type raspistill -k and hit Enter
This starts the camera preview
Hit Ctrl + C to stop
![Page 5: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/5.jpg)
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
![Page 6: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/6.jpg)
Check the photo is there
Run ls to see the photo is thereRun startx to boot to Desktop
![Page 7: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/7.jpg)
Open File Manager
![Page 8: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/8.jpg)
Open image
Double click image.jpg to view it
![Page 9: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/9.jpg)
Open Terminal
![Page 10: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/10.jpg)
Open IDLE as root
Type sudo idle3 & and hit Enter
sudo means super user doIDLE is a Python application& means open in a new process
![Page 11: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/11.jpg)
New file
Go to File > New windowSave as camera.py
![Page 12: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/12.jpg)
Take a selfie with Pythonfrom 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
![Page 13: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/13.jpg)
View the photo from File ManagerNotice 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
![Page 14: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/14.jpg)
GPIO pins
![Page 15: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/15.jpg)
GPIO pins
![Page 16: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/16.jpg)
Breadboard
![Page 17: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/17.jpg)
Connect a GPIO push button
![Page 18: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/18.jpg)
Add the button to the codefrom 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()
![Page 19: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/19.jpg)
Press the button to take a picture
Run the script with F5Wait for the previewPress the push button to take a picture
![Page 20: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/20.jpg)
View the photo from File Manager
![Page 21: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/21.jpg)
Add a loopwith 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()
![Page 22: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/22.jpg)
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()
![Page 23: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/23.jpg)
What can you do?
![Page 24: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/24.jpg)
Raspberry Pi Camera Resources
![Page 25: Picademy - Python picamera workshop](https://reader030.vdocument.in/reader030/viewer/2022032420/55a5cde41a28ab611b8b45ff/html5/thumbnails/25.jpg)
Raspberry Pi Resources