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

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

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