際際滷

際際滷Share a Scribd company logo
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()
Whats 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

More from bennuttall (20)

Physical computing with Python and Raspberry Pi
Physical computing with Python and Raspberry PiPhysical computing with Python and Raspberry Pi
Physical computing with Python and Raspberry Pi
bennuttall
Raspberry Pi Foundation - Intro for Creative Technologists
Raspberry Pi Foundation - Intro for Creative TechnologistsRaspberry Pi Foundation - Intro for Creative Technologists
Raspberry Pi Foundation - Intro for Creative Technologists
bennuttall
Picamera, Flask and the Twitter API Raspberry Pi workshop
Picamera, Flask and the Twitter API Raspberry Pi workshopPicamera, Flask and the Twitter API Raspberry Pi workshop
Picamera, Flask and the Twitter API Raspberry Pi workshop
bennuttall
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
bennuttall
Build your product around the best supported mini computer in the world - Ras...
Build your product around the best supported mini computer in the world - Ras...Build your product around the best supported mini computer in the world - Ras...
Build your product around the best supported mini computer in the world - Ras...
bennuttall
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
Raspberry Pi - background of Raspberry Pi Foundation for Creative TechnologistsRaspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
bennuttall
Ben Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha KuchaBen Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha Kucha
bennuttall
Raspberry Pi for startups - Estonia
Raspberry Pi for startups - EstoniaRaspberry Pi for startups - Estonia
Raspberry Pi for startups - Estonia
bennuttall
Raspberry Pi - Estonia
Raspberry Pi - EstoniaRaspberry Pi - Estonia
Raspberry Pi - Estonia
bennuttall
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
bennuttall
Creative technologists
Creative technologistsCreative technologists
Creative technologists
bennuttall
Raspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp ManchesterRaspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp Manchester
bennuttall
Raspberry Pi in science education - IMA NW
Raspberry Pi in science education - IMA NWRaspberry Pi in science education - IMA NW
Raspberry Pi in science education - IMA NW
bennuttall
Pioneering the future of computing education - PyCon Ireland
Pioneering the future of computing education - PyCon IrelandPioneering the future of computing education - PyCon Ireland
Pioneering the future of computing education - PyCon Ireland
bennuttall
Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14
bennuttall
PyPi (not that one) [Python on Pi] - PyConUK 2014
PyPi (not that one) [Python on Pi] - PyConUK 2014PyPi (not that one) [Python on Pi] - PyConUK 2014
PyPi (not that one) [Python on Pi] - PyConUK 2014
bennuttall
Raspberry Pi - Denver Hackspaces
Raspberry Pi - Denver HackspacesRaspberry Pi - Denver Hackspaces
Raspberry Pi - Denver Hackspaces
bennuttall
St Louis St. John Vianney High School - Raspberry Pi
St Louis St. John Vianney High School - Raspberry PiSt Louis St. John Vianney High School - Raspberry Pi
St Louis St. John Vianney High School - Raspberry Pi
bennuttall
Arch Reactor - Raspberry Pi
Arch Reactor - Raspberry PiArch Reactor - Raspberry Pi
Arch Reactor - Raspberry Pi
bennuttall
LVL1 - Raspberry Pi
LVL1 - Raspberry PiLVL1 - Raspberry Pi
LVL1 - Raspberry Pi
bennuttall
Physical computing with Python and Raspberry Pi
Physical computing with Python and Raspberry PiPhysical computing with Python and Raspberry Pi
Physical computing with Python and Raspberry Pi
bennuttall
Raspberry Pi Foundation - Intro for Creative Technologists
Raspberry Pi Foundation - Intro for Creative TechnologistsRaspberry Pi Foundation - Intro for Creative Technologists
Raspberry Pi Foundation - Intro for Creative Technologists
bennuttall
Picamera, Flask and the Twitter API Raspberry Pi workshop
Picamera, Flask and the Twitter API Raspberry Pi workshopPicamera, Flask and the Twitter API Raspberry Pi workshop
Picamera, Flask and the Twitter API Raspberry Pi workshop
bennuttall
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
bennuttall
Build your product around the best supported mini computer in the world - Ras...
Build your product around the best supported mini computer in the world - Ras...Build your product around the best supported mini computer in the world - Ras...
Build your product around the best supported mini computer in the world - Ras...
bennuttall
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
Raspberry Pi - background of Raspberry Pi Foundation for Creative TechnologistsRaspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
Raspberry Pi - background of Raspberry Pi Foundation for Creative Technologists
bennuttall
Ben Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha KuchaBen Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha Kucha
bennuttall
Raspberry Pi for startups - Estonia
Raspberry Pi for startups - EstoniaRaspberry Pi for startups - Estonia
Raspberry Pi for startups - Estonia
bennuttall
Raspberry Pi - Estonia
Raspberry Pi - EstoniaRaspberry Pi - Estonia
Raspberry Pi - Estonia
bennuttall
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
How Raspberry Pi (an educational charity) funds itself without ratlling a tin...
bennuttall
Creative technologists
Creative technologistsCreative technologists
Creative technologists
bennuttall
Raspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp ManchesterRaspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp Manchester
bennuttall
Raspberry Pi in science education - IMA NW
Raspberry Pi in science education - IMA NWRaspberry Pi in science education - IMA NW
Raspberry Pi in science education - IMA NW
bennuttall
Pioneering the future of computing education - PyCon Ireland
Pioneering the future of computing education - PyCon IrelandPioneering the future of computing education - PyCon Ireland
Pioneering the future of computing education - PyCon Ireland
bennuttall
Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14
bennuttall
PyPi (not that one) [Python on Pi] - PyConUK 2014
PyPi (not that one) [Python on Pi] - PyConUK 2014PyPi (not that one) [Python on Pi] - PyConUK 2014
PyPi (not that one) [Python on Pi] - PyConUK 2014
bennuttall
Raspberry Pi - Denver Hackspaces
Raspberry Pi - Denver HackspacesRaspberry Pi - Denver Hackspaces
Raspberry Pi - Denver Hackspaces
bennuttall
St Louis St. John Vianney High School - Raspberry Pi
St Louis St. John Vianney High School - Raspberry PiSt Louis St. John Vianney High School - Raspberry Pi
St Louis St. John Vianney High School - Raspberry Pi
bennuttall
Arch Reactor - Raspberry Pi
Arch Reactor - Raspberry PiArch Reactor - Raspberry Pi
Arch Reactor - Raspberry Pi
bennuttall
LVL1 - Raspberry Pi
LVL1 - Raspberry PiLVL1 - Raspberry Pi
LVL1 - Raspberry Pi
bennuttall

Recently uploaded (20)

U.S. Department of Education certification
U.S. Department of Education certificationU.S. Department of Education certification
U.S. Department of Education certification
Mebane Rash
Sulfonamides by Mrs. Manjushri P. Dabhade
Sulfonamides by Mrs. Manjushri P. DabhadeSulfonamides by Mrs. Manjushri P. Dabhade
Sulfonamides by Mrs. Manjushri P. Dabhade
Dabhade madam Dabhade
UTI Quinolones by Mrs. Manjushri Dabhade
UTI Quinolones by Mrs. Manjushri DabhadeUTI Quinolones by Mrs. Manjushri Dabhade
UTI Quinolones by Mrs. Manjushri Dabhade
Dabhade madam Dabhade
EDL 290F Week 5 - Facing Headwinds and Hairpin Turns (2025).pdf
EDL 290F Week 5  - Facing Headwinds and Hairpin Turns (2025).pdfEDL 290F Week 5  - Facing Headwinds and Hairpin Turns (2025).pdf
EDL 290F Week 5 - Facing Headwinds and Hairpin Turns (2025).pdf
Liz Walsh-Trevino
MICROECONOMICS: RENT AND THEORIES OF RENT
MICROECONOMICS: RENT AND THEORIES OF RENTMICROECONOMICS: RENT AND THEORIES OF RENT
MICROECONOMICS: RENT AND THEORIES OF RENT
DrSundariD
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
heathfieldcps1
How to Setup Company Data in Odoo 17 Accounting App
How to Setup Company Data in Odoo 17 Accounting AppHow to Setup Company Data in Odoo 17 Accounting App
How to Setup Company Data in Odoo 17 Accounting App
Celine George
Different perspectives on dugout canoe heritage of Soomaa.pdf
Different perspectives on dugout canoe heritage of Soomaa.pdfDifferent perspectives on dugout canoe heritage of Soomaa.pdf
Different perspectives on dugout canoe heritage of Soomaa.pdf
Aivar Ruukel
Unit1 Inroduction to Internal Combustion Engines
Unit1  Inroduction to Internal Combustion EnginesUnit1  Inroduction to Internal Combustion Engines
Unit1 Inroduction to Internal Combustion Engines
NileshKumbhar21
MIPLM subject matter expert Nicos Raftis
MIPLM subject matter expert Nicos RaftisMIPLM subject matter expert Nicos Raftis
MIPLM subject matter expert Nicos Raftis
MIPLM
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
home
EDL 290F Week 4 - Group Ride (2025).pdf
EDL 290F Week 4  - Group Ride (2025).pdfEDL 290F Week 4  - Group Ride (2025).pdf
EDL 290F Week 4 - Group Ride (2025).pdf
Liz Walsh-Trevino
Knownsense 2025 prelims- U-25 General Quiz.pdf
Knownsense 2025 prelims- U-25 General Quiz.pdfKnownsense 2025 prelims- U-25 General Quiz.pdf
Knownsense 2025 prelims- U-25 General Quiz.pdf
Pragya - UEM Kolkata Quiz Club
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study MaterialPass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Jenny408767
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VIAnti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Samruddhi Khonde
Introduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz KhanIntroduction to Systematic Reviews - Prof Ejaz Khan
Introduction to Systematic Reviews - Prof Ejaz Khan
Systematic Reviews Network (SRN)
Early 20th Century Modern Art: Movements and Artists
Early 20th Century Modern Art: Movements and ArtistsEarly 20th Century Modern Art: Movements and Artists
Early 20th Century Modern Art: Movements and Artists
Damian T. Gordon
ANTIVIRAL agent by Mrs. Manjushri Dabhade
ANTIVIRAL agent by Mrs. Manjushri DabhadeANTIVIRAL agent by Mrs. Manjushri Dabhade
ANTIVIRAL agent by Mrs. Manjushri Dabhade
Dabhade madam Dabhade
How to Manage Purchase Order Approval in Odoo 18
How to Manage Purchase Order Approval in Odoo 18How to Manage Purchase Order Approval in Odoo 18
How to Manage Purchase Order Approval in Odoo 18
Celine George
MIPLM subject matter expert Dr Alihan Kaya
MIPLM subject matter expert Dr Alihan KayaMIPLM subject matter expert Dr Alihan Kaya
MIPLM subject matter expert Dr Alihan Kaya
MIPLM
U.S. Department of Education certification
U.S. Department of Education certificationU.S. Department of Education certification
U.S. Department of Education certification
Mebane Rash
Sulfonamides by Mrs. Manjushri P. Dabhade
Sulfonamides by Mrs. Manjushri P. DabhadeSulfonamides by Mrs. Manjushri P. Dabhade
Sulfonamides by Mrs. Manjushri P. Dabhade
Dabhade madam Dabhade
UTI Quinolones by Mrs. Manjushri Dabhade
UTI Quinolones by Mrs. Manjushri DabhadeUTI Quinolones by Mrs. Manjushri Dabhade
UTI Quinolones by Mrs. Manjushri Dabhade
Dabhade madam Dabhade
EDL 290F Week 5 - Facing Headwinds and Hairpin Turns (2025).pdf
EDL 290F Week 5  - Facing Headwinds and Hairpin Turns (2025).pdfEDL 290F Week 5  - Facing Headwinds and Hairpin Turns (2025).pdf
EDL 290F Week 5 - Facing Headwinds and Hairpin Turns (2025).pdf
Liz Walsh-Trevino
MICROECONOMICS: RENT AND THEORIES OF RENT
MICROECONOMICS: RENT AND THEORIES OF RENTMICROECONOMICS: RENT AND THEORIES OF RENT
MICROECONOMICS: RENT AND THEORIES OF RENT
DrSundariD
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
heathfieldcps1
How to Setup Company Data in Odoo 17 Accounting App
How to Setup Company Data in Odoo 17 Accounting AppHow to Setup Company Data in Odoo 17 Accounting App
How to Setup Company Data in Odoo 17 Accounting App
Celine George
Different perspectives on dugout canoe heritage of Soomaa.pdf
Different perspectives on dugout canoe heritage of Soomaa.pdfDifferent perspectives on dugout canoe heritage of Soomaa.pdf
Different perspectives on dugout canoe heritage of Soomaa.pdf
Aivar Ruukel
Unit1 Inroduction to Internal Combustion Engines
Unit1  Inroduction to Internal Combustion EnginesUnit1  Inroduction to Internal Combustion Engines
Unit1 Inroduction to Internal Combustion Engines
NileshKumbhar21
MIPLM subject matter expert Nicos Raftis
MIPLM subject matter expert Nicos RaftisMIPLM subject matter expert Nicos Raftis
MIPLM subject matter expert Nicos Raftis
MIPLM
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
20250402 ACCA TeamScienceAIEra 20250402 v10.pptx
home
EDL 290F Week 4 - Group Ride (2025).pdf
EDL 290F Week 4  - Group Ride (2025).pdfEDL 290F Week 4  - Group Ride (2025).pdf
EDL 290F Week 4 - Group Ride (2025).pdf
Liz Walsh-Trevino
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study MaterialPass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study Material
Jenny408767
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VIAnti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Anti-Viral Agents.pptx Medicinal Chemistry III, B Pharm SEM VI
Samruddhi Khonde
Early 20th Century Modern Art: Movements and Artists
Early 20th Century Modern Art: Movements and ArtistsEarly 20th Century Modern Art: Movements and Artists
Early 20th Century Modern Art: Movements and Artists
Damian T. Gordon
ANTIVIRAL agent by Mrs. Manjushri Dabhade
ANTIVIRAL agent by Mrs. Manjushri DabhadeANTIVIRAL agent by Mrs. Manjushri Dabhade
ANTIVIRAL agent by Mrs. Manjushri Dabhade
Dabhade madam Dabhade
How to Manage Purchase Order Approval in Odoo 18
How to Manage Purchase Order Approval in Odoo 18How to Manage Purchase Order Approval in Odoo 18
How to Manage Purchase Order Approval in Odoo 18
Celine George
MIPLM subject matter expert Dr Alihan Kaya
MIPLM subject matter expert Dr Alihan KayaMIPLM subject matter expert Dr Alihan Kaya
MIPLM subject matter expert Dr Alihan Kaya
MIPLM

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. Whats 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