SlideShare a Scribd company logo
1 of 25
Download to read offline
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

More from 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 Pibennuttall
 
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 Technologistsbennuttall
 
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 workshopbennuttall
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developersbennuttall
 
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 Technologistsbennuttall
 
Ben Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha KuchaBen Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha Kuchabennuttall
 
Raspberry Pi for startups - Estonia
Raspberry Pi for startups - EstoniaRaspberry Pi for startups - Estonia
Raspberry Pi for startups - Estoniabennuttall
 
Raspberry Pi - Estonia
Raspberry Pi - EstoniaRaspberry Pi - Estonia
Raspberry Pi - Estoniabennuttall
 
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 technologistsbennuttall
 
Raspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp ManchesterRaspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp Manchesterbennuttall
 
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 NWbennuttall
 
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 Irelandbennuttall
 
Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14bennuttall
 
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 2014bennuttall
 
Raspberry Pi - Denver Hackspaces
Raspberry Pi - Denver HackspacesRaspberry Pi - Denver Hackspaces
Raspberry Pi - Denver Hackspacesbennuttall
 
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 Pibennuttall
 
Arch Reactor - Raspberry Pi
Arch Reactor - Raspberry PiArch Reactor - Raspberry Pi
Arch Reactor - Raspberry Pibennuttall
 
LVL1 - Raspberry Pi
LVL1 - Raspberry PiLVL1 - Raspberry Pi
LVL1 - Raspberry Pibennuttall
 

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
 
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
 
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
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
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...
 
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
 
Ben Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha KuchaBen Nuttall - Creative Technologists Pecha Kucha
Ben Nuttall - Creative Technologists Pecha Kucha
 
Raspberry Pi for startups - Estonia
Raspberry Pi for startups - EstoniaRaspberry Pi for startups - Estonia
Raspberry Pi for startups - Estonia
 
Raspberry Pi - Estonia
Raspberry Pi - EstoniaRaspberry Pi - Estonia
Raspberry Pi - Estonia
 
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...
 
Creative technologists
Creative technologistsCreative technologists
Creative technologists
 
Raspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp ManchesterRaspberry Pi in education - Barcamp Manchester
Raspberry Pi in education - Barcamp Manchester
 
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
 
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
 
Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14Python on Pi - Keynote at PySS14
Python on Pi - Keynote at PySS14
 
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
 
Raspberry Pi - Denver Hackspaces
Raspberry Pi - Denver HackspacesRaspberry Pi - Denver Hackspaces
Raspberry Pi - Denver Hackspaces
 
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
 
Arch Reactor - Raspberry Pi
Arch Reactor - Raspberry PiArch Reactor - Raspberry Pi
Arch Reactor - Raspberry Pi
 
LVL1 - Raspberry Pi
LVL1 - Raspberry PiLVL1 - Raspberry Pi
LVL1 - Raspberry Pi
 

Recently uploaded

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Getting started with Python picamera: 40 steps to capture photos

  • 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