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”
image.jpg is the chosen filename
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 process
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_preview()
sleep(5)
camera.capture('/home/pi/image2.jpg')
camera.stop_preview()
Press F5 to run
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
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.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()
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):
sleep(3)
camera.capture('/home/pi/picture%s.jpg' % i)
camera.stop_preview()
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()
What can you do?
Raspberry Pi Camera Resources
Raspberry Pi Resources

More Related Content

PDF
Picademy 5 Picamera Intro Workshop
ODT
Suji May12
PDF
Project humix overview - For Raspberry pi community meetup
PDF
Hands on Raspberry Pi - Creative Technologists
PPTX
New Microsoft PowerPoint Presentation (2).pptx
PDF
05-Pi-Camera.pdf
PPTX
05-Pi-Camera.pptx
PPT
Smart Wireless Surveillance Monitoring using RASPBERRY PI
Picademy 5 Picamera Intro Workshop
Suji May12
Project humix overview - For Raspberry pi community meetup
Hands on Raspberry Pi - Creative Technologists
New Microsoft PowerPoint Presentation (2).pptx
05-Pi-Camera.pdf
05-Pi-Camera.pptx
Smart Wireless Surveillance Monitoring using RASPBERRY PI

Similar to Picademy - Python picamera workshop (20)

PDF
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
PDF
Picademy #3 Python Picamera GPIO Workshop
PPTX
Coffee & Pi - Getting Started with Python
PDF
Picamera, Flask and the Twitter API Raspberry Pi workshop
PDF
20 easy Raspberry Pi projects
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
DOCX
Automation of pheromone traps
PPTX
projectppt-141127001908-conversion-gate02.pptx
PDF
Ijaems apr-2016-17 Raspberry PI Based Artificial Vision Assisting System for ...
PDF
Raspberry JAM 1 - Setup Raspberry Pi with Raspbian -Vick Nesh
PPTX
Coffee & Pi - Fall into Pi
PDF
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
PPTX
Coffee & Pi - Intro to Pi Workshop
PDF
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
PPSX
Low Cost HD Surveillance Camera using Raspberry PI
PPTX
Raspberry Pi ppt.pptx
PPTX
Raspberry Pi ppt.pptx
PPTX
Capstone_Project.ppt
PPTX
Raspberry pi
PPTX
Coffee & Pi - intro to Pi Workshop
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Picademy #3 Python Picamera GPIO Workshop
Coffee & Pi - Getting Started with Python
Picamera, Flask and the Twitter API Raspberry Pi workshop
20 easy Raspberry Pi projects
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
Automation of pheromone traps
projectppt-141127001908-conversion-gate02.pptx
Ijaems apr-2016-17 Raspberry PI Based Artificial Vision Assisting System for ...
Raspberry JAM 1 - Setup Raspberry Pi with Raspbian -Vick Nesh
Coffee & Pi - Fall into Pi
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
Coffee & Pi - Intro to Pi Workshop
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
Low Cost HD Surveillance Camera using Raspberry PI
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
Capstone_Project.ppt
Raspberry pi
Coffee & Pi - intro to Pi Workshop
Ad

More from bennuttall (20)

PDF
Physical computing with Python and Raspberry Pi
PDF
Raspberry Pi Foundation - Intro for Creative Technologists
PDF
Python for PHP developers
PDF
Build your product around the best supported mini computer in the world - Ras...
PDF
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
PDF
Ben Nuttall - Creative Technologists Pecha Kucha
PDF
Raspberry Pi for startups - Estonia
PDF
Raspberry Pi - Estonia
PDF
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
PDF
Creative technologists
PDF
Raspberry Pi in education - Barcamp Manchester
PDF
Raspberry Pi in science education - IMA NW
PDF
Pioneering the future of computing education - PyCon Ireland
PDF
Python on Pi - Keynote at PySS14
PDF
PyPi (not that one) [Python on Pi] - PyConUK 2014
PDF
Raspberry Pi - Denver Hackspaces
PDF
St Louis St. John Vianney High School - Raspberry Pi
PDF
Arch Reactor - Raspberry Pi
PDF
LVL1 - Raspberry Pi
PDF
Fayette Academy - Raspberry Pi
Physical computing with Python and Raspberry Pi
Raspberry Pi Foundation - Intro for Creative Technologists
Python for PHP developers
Build your product around the best supported mini computer in the world - Ras...
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
Ben Nuttall - Creative Technologists Pecha Kucha
Raspberry Pi for startups - Estonia
Raspberry Pi - Estonia
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
Creative technologists
Raspberry Pi in education - Barcamp Manchester
Raspberry Pi in science education - IMA NW
Pioneering the future of computing education - PyCon Ireland
Python on Pi - Keynote at PySS14
PyPi (not that one) [Python on Pi] - PyConUK 2014
Raspberry Pi - Denver Hackspaces
St Louis St. John Vianney High School - Raspberry Pi
Arch Reactor - Raspberry Pi
LVL1 - Raspberry Pi
Fayette Academy - Raspberry Pi
Ad

Recently uploaded (20)

PDF
English Textual Question & Ans (12th Class).pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
HVAC Specification 2024 according to central public works department
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
PDF
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
PDF
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf
English Textual Question & Ans (12th Class).pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
AI-driven educational solutions for real-life interventions in the Philippine...
Environmental Education MCQ BD2EE - Share Source.pdf
Core Concepts of Personalized Learning and Virtual Learning Environments
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
HVAC Specification 2024 according to central public works department
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Skin Care and Cosmetic Ingredients Dictionary ( PDFDrive ).pdf
Mucosal Drug Delivery system_NDDS_BPHARMACY__SEM VII_PCI.pdf
LIFE & LIVING TRILOGY- PART (1) WHO ARE WE.pdf
Empowerment Technology for Senior High School Guide
Share_Module_2_Power_conflict_and_negotiation.pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Unit 4 Computer Architecture Multicore Processor.pptx
Introduction to pro and eukaryotes and differences.pptx
MICROENCAPSULATION_NDDS_BPHARMACY__SEM VII_PCI .pdf

Picademy - Python picamera workshop

  • 1. Getting started with Python picamera @ben_nuttall
  • 3. Boot the Pi and log in
  • 4. Test the camera Type raspistill -k and hit Enter This starts the camera preview Hit Ctrl + C to stop
  • 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. Check the photo is there Run ls to see the photo is there Run startx to boot to Desktop
  • 8. Open image Double click image.jpg to view it
  • 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. New file Go to File > New window Save as camera.py
  • 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. 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
  • 17. Connect a GPIO push button
  • 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. 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. View the photo from File Manager
  • 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. 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()
  • 24. Raspberry Pi Camera Resources