SlideShare a Scribd company logo
Hands on Raspberry Pi
Connect your Pi
- Raspberry Pi 2
- Micro SD card
- HDMI cable
- HDMIPi screen & power cable
- Mouse
- Keyboard
- WiFi dongle
- Raspberry Pi power cable (last)
Log in
Username: pi
Password: raspberry
Note: Password will not show while typing
Try the command line
Type the commands:
- ls
- ls -l
- pwd
- cd python_games
- ls
- cd
Boot to desktop
- Run the command startx
- Hit Enter
Open Python 3
Python is a programming language
IDLE is a Python application
Hello world
In the IDLE Python window, enter:
print(“Hello world”)
and hit Enter
Calculator
Try:
2 + 2
10 * 5
123 + 456
Variables
Try:
a = 1
b = 2
c = a + b
print(c)
Strings
Try:
name = “Ben”
print(“Hello ” + name)
Syntax errors
Try:
print(Hello)
print(“Hello)
print(“Hello’)
Types
Try:
age = 26
“My age is ” + age
Type casting
Try:
“My age is ” + str(age)
Loops
Try:
for i in range(10):
print(“Hello”)
Loops
Try:
for i in range(10):
print(i)
Exit IDLE
Close the IDLE window
GPIO pins
GPIO pins
Breadboard
Connect ground rail
Wire up LED to 3V3
Open Terminal
Create new folder
Type mkdir intro and hit Enter
This creates a new directory (folder) called
intro
Enter the folder
Type cd intro and hit Enter
“Change directory intro”
This enters the directory intro
Open IDLE as super user
In the Terminal window, run:
sudo idle3 &
This will open IDLE with super user permissions
- we need this to access GPIO pins
The ampersand (&) opens it in a new process
Open a new window
Go to File > New window
Save file
Go to File > Save
Save as led.py in your intro folder
Flashing LED program
from RPi import GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2, GPIO.OUT, False)
for i in range(10):
GPIO.output(2, True)
sleep(0.1)
GPIO.output(2, False)
sleep(0.1)
Move from 3V3 to GPIO 2
Run the script!
Press F5 to run the program
Add second LED
New file
Go to File > New window
Save as led2.py
Code for 2 LEDs
from RPi import GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
red = 2
blue = 3
GPIO.setup(red, GPIO.OUT, False)
GPIO.setup(blue, GPIO.OUT, False)
Flash continuously
while True:
GPIO.output(red, True)
sleep(0.1)
GPIO.output(blue, True)
sleep(0.1)
GPIO.output(red, False)
sleep(0.1)
GPIO.output(blue, False)
sleep(0.1)
Make it stop!
Press Ctrl + C to force quit (it won’t ever end)
Shut down your Pi
Enter sudo halt in the Terminal
OR
Shut down from the main Menu
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 IDLE as root
Open Terminal
Open IDLE as root user
sudo idle3 &
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()
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
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/image%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/image%s.jpg' % i)
camera.stop_preview()
for i in range(5):
GPIO.wait_for_edge(button, GPIO.FALLING)
sleep(3)
camera.capture('/home/pi/image%s.jpg' % i)
camera.stop_preview()
What can you do?
Raspberry Pi Resources
Raspberry Pi Camera Resources
Experiment time!
- Try combining buttons, LEDs, camera
- Different buttons for different actions
- 2 buttons to start/stop preview
- LED status
- What else is in your CamJam kit?
- Use your imagination!
Updating your SD Card
(you must be online)
sudo apt-get update
sudo apt-get upgrade
Installing software
sudo apt-get install tree
sudo pip install twython
sudo pip-3.2 install twython

More Related Content

ODP
Enhancing Free PBX with Adhearsion at Fosdem 2012
PDF
BT-led점등
PPTX
Custard pi 7 user information
TXT
Script
PDF
Concurrency in Python4k
TXT
Streaming status
PDF
Introduction to nand2 tetris
PDF
Coding in GO - GDG SL - NSBM
Enhancing Free PBX with Adhearsion at Fosdem 2012
BT-led점등
Custard pi 7 user information
Script
Concurrency in Python4k
Streaming status
Introduction to nand2 tetris
Coding in GO - GDG SL - NSBM

What's hot (8)

PDF
FPBrno 2018-05-22: Benchmarking in elixir
PPT
PDF
Gameboy emulator in rust and web assembly
PDF
Let's golang
PDF
mpi4py.pdf
PDF
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
PPTX
Guitar Tone Analyzer and Note Plotter Presentation
PDF
Make A Shoot ‘Em Up Game with Amethyst Framework
FPBrno 2018-05-22: Benchmarking in elixir
Gameboy emulator in rust and web assembly
Let's golang
mpi4py.pdf
[GSoC 2017] gopy: Updating gopy to support Python3 and PyPy
Guitar Tone Analyzer and Note Plotter Presentation
Make A Shoot ‘Em Up Game with Amethyst Framework
Ad

Viewers also liked (20)

PDF
The What If Technique presented by Motivate Design
PDF
Displaying Data
PDF
What Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
PDF
How Google Works
PDF
Introduction to Raspberrypi
PDF
Picademy 5 Picamera Intro Workshop
PDF
Picademy #3 Python Picamera GPIO Workshop
PPTX
Project-make a public website server using raspberry pi
PPTX
Web Design Of Education Consultancy
PDF
Physical computing with Python and Raspberry Pi
PPTX
Raspberry Pi
PPTX
Raspberry Pi (Introduction)
PPTX
Raspberry-PI introduction
PDF
Introduction to Windows IoT via Raspberry Pi 3
PDF
Exploring Raspberry Pi
PPT
Seminar Presentation on raspberry pi
PPT
Raspberry Pi Presentation
PPTX
Introduction to raspberry pi
DOCX
A seminar report on Raspberry Pi
PPTX
IOT Based Home Automation using Raspberry Pi-3
The What If Technique presented by Motivate Design
Displaying Data
What Would Steve Do? 10 Lessons from the World's Most Captivating Presenters
How Google Works
Introduction to Raspberrypi
Picademy 5 Picamera Intro Workshop
Picademy #3 Python Picamera GPIO Workshop
Project-make a public website server using raspberry pi
Web Design Of Education Consultancy
Physical computing with Python and Raspberry Pi
Raspberry Pi
Raspberry Pi (Introduction)
Raspberry-PI introduction
Introduction to Windows IoT via Raspberry Pi 3
Exploring Raspberry Pi
Seminar Presentation on raspberry pi
Raspberry Pi Presentation
Introduction to raspberry pi
A seminar report on Raspberry Pi
IOT Based Home Automation using Raspberry Pi-3
Ad

Similar to Hands on Raspberry Pi - Creative Technologists (20)

PPTX
Raspberry Pi ppt.pptx
PPTX
Raspberry Pi ppt.pptx
PPTX
Up and running with Raspberry Pi
PDF
Picademy - Python picamera workshop
PPTX
Raspberry pi
PDF
Raspberry Pi - Lecture 6 Working on Raspberry Pi
PPTX
Raspberry Pi Introductory Lecture
PPTX
Coffee & Pi - Getting Started with Python
PDF
Raspberry pi Board Hardware & Software Setup
PDF
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
PPTX
Raspberry pi
PDF
RaspberryPi_Workshop and Programming with python.
PDF
Amity Raspberry Jam
PPTX
Exploring the ABC's of Raspberry Pi with Python
PDF
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
PPTX
Raspberry Pi Using Python
PDF
Introduction to Raspberry Pi
PDF
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
PPTX
New Microsoft PowerPoint Presentation (2).pptx
PDF
manual_2020_Cyber Physical System.pdf
Raspberry Pi ppt.pptx
Raspberry Pi ppt.pptx
Up and running with Raspberry Pi
Picademy - Python picamera workshop
Raspberry pi
Raspberry Pi - Lecture 6 Working on Raspberry Pi
Raspberry Pi Introductory Lecture
Coffee & Pi - Getting Started with Python
Raspberry pi Board Hardware & Software Setup
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
Raspberry pi
RaspberryPi_Workshop and Programming with python.
Amity Raspberry Jam
Exploring the ABC's of Raspberry Pi with Python
PiFlash: Linux utility to flash SD cards for Raspberry Pi computers
Raspberry Pi Using Python
Introduction to Raspberry Pi
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
New Microsoft PowerPoint Presentation (2).pptx
manual_2020_Cyber Physical System.pdf

More from bennuttall (20)

PDF
Raspberry Pi Foundation - Intro for Creative Technologists
PDF
Picamera, Flask and the Twitter API Raspberry Pi workshop
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
Raspberry Pi Foundation - Intro for Creative Technologists
Picamera, Flask and the Twitter API Raspberry Pi workshop
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

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Pharma ospi slides which help in ospi learning
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Complications of Minimal Access Surgery at WLH
GDM (1) (1).pptx small presentation for students
human mycosis Human fungal infections are called human mycosis..pptx
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
Pharma ospi slides which help in ospi learning
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

Hands on Raspberry Pi - Creative Technologists