Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
@KSUiTeach
Visit: ksuiteach.org Visit: seeedudifferently.com Presentation is at: bigguyinabowtie.com/Google Check out my Youtube Channel! http://bit.ly/bigguybowtievideo Follow me on Twitter, Instagram, and Snapchat @bigguyinabowtie big
guyin
abow
tie.co
m
@KSUiTeach
Idea Share!
How would you use Raspberry Pi? Share Your thoughts here
Prize at the end for a favorite and random
monthly prizes
http://bit.ly/raspberrypiideashare
biggu
yinab
owtie
.com
@KSUiTeach
It can do everything! Creating with
Raspberry Pi and Components
Presented by David Lockhart biggu
yinab
owtie
.com
@KSUiTeach
About Me
biggu
yinab
owtie
.com
@KSUiTeach
biggu
yinab
owtie
.com
@KSUiTeach
Our AgendaAbout The Big Guy in the Bow Tie Circuit TimeChallenge 1: Building an LED CircuitChallenge 2: Traffic LightPi CameraChallenge 3: SelfieChallenge 4: Add a ButtonChallenge 5: Use FiltersChallenge 6: Video
Challenge 7: Motion Sensor
Challenge 8: Time LapseChallenge 9: Create Your
Ownbig
guyin
abow
tie.co
m
@KSUiTeach
Circuit TimeScratch & Python & Circuits
© CC BY-SA 4.0
biggu
yinab
owtie
.com
@KSUiTeach
Things You Will Need
2X Male/Female Jumper WiresLED
Resistor
BreadboardGPIO Reference Boardbig
guyin
abow
tie.co
m
@KSUiTeach
Simple CircuitYour Raspberry Pi can act as the power supply for simple circuits.
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 1: Building and
Coding an LED Circuitbiggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides build an LED circuit, and code it in both Scratch and Python
•See if you can Flash the LED at Different Speeds •See if you can make an SOS signal
biggu
yinab
owtie
.com
@KSUiTeach
Simple CircuitLet’s build a simple circuit now using our Raspberry Pi.
• Connect the Female End to the 3v3 pin and the male end to a row in the breadboard
• Put the LED in the same row splitting both sides of the bread board
• Put one end to the Resistor to the same row as the LED and connect the other end further down the breadboard
biggu
yinab
owtie
.com
@KSUiTeach
Switching CircuitYour Raspberry Pi can act as a switch in the circuit, which can be controlled in software.
• Go through same steps as previous slide EXCEPT:
• Connect the wire in the LED row to a numbered pin
• Take another wire and connect a ground connector with the other end of the resistor
biggu
yinab
owtie
.com
@KSUiTeach
Now to Program with Scratch on the Raspberry Pi
Open Scratch 1.4 and activate the GPIO server.
gpioserveronbig
guyin
abow
tie.co
m
@KSUiTeach
Creating a Blinking LED with Scratch!Setup your pin as an output.
config17out
Switch pin 17 on
gpio17onSwitch pin 17 off
gpio17off
Pause
Loop forever
Always start with:
biggu
yinab
owtie
.com
@KSUiTeach
Python Coding Your LED
#FlashingLED
fromgpiozeroimportLEDfromtimeimportsleep
myled=LED(17)
whileTrue:myled.on()sleep(1)myled.off()sleep(1)
The Code
After coding your LED in Scratch, Code it in Python using the Code below!
biggu
yinab
owtie
.com
@KSUiTeach
Coding Your LED Light Code the Light to Blink. Try some different values!
Try other values in ld.blink(): led.blink(5) led.blink(2, 0.5) led.blink(0.1, 10) led.blink(0.5, 0.5, 5, False)
# Flashing LED
from gpiozero import LED
led = LED(17)
led.blink()
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Other Commands You Can Use
led.on()-SwitchesthePinhigh
led.off()-SwitchesthePinlow
led.blink()-MakestheLEDblink
led.toggle()-ChangethestateoftheLED
led.pin.number-Returnsthepinnumber
led.is_lit-Returnsthecurrentstate
https://gpiozero.readthedocs.org
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 2: Traffic Light
biggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides build a Traffic Light, and code it in Python
biggu
yinab
owtie
.com
@KSUiTeach
Hardware ApplicationThere are two ways to build a traffic light
You can get a traffic light add on
You can do it via the Bread Board
biggu
yinab
owtie
.com
@KSUiTeach
Traffic Light Coding
# Traffic Lights 1
from gpiozero import LED
from time import sleep
red = LED(21)
amber = LED(20)
green = LED(16)
red.on()
sleep(3)
red.off()
amber.on()
…
•Use the Code below in order to code the traffic light •Pay special attention to the pins the LED’s are connected to •The Code is not finished, can you finish it The Code
biggu
yinab
owtie
.com
@KSUiTeach
AbstractionYou can removing complexity to make a task more accessible. Give it a TRY!
#TrafficLights1
fromgpiozeroimportLEDfromtimeimportsleep
red=LED(21)amber=LED(20)green=LED(16)
red.on()sleep(3)red.off()amber.on()…
#TrafficLights2
fromgpiozeroimportTrafficLights
fromtimeimportsleep
lights=TrafficLights(21,20,16)
lights.red.on()
sleep(3)
lights.red.off()
lights.amber.on()
…
The Original Code The Less Complex Code
biggu
yinab
owtie
.com
@KSUiTeach
Where next?There are a WHOLE bunch of add ons you can use with the BreadBoard
LED Motion Sensor Buttons
Temp Sensor Motors
Lots More!big
guyin
abow
tie.co
m
@KSUiTeach
Pi Camera Taking Photos
© CC BY-SA 4.0
biggu
yinab
owtie
.com
@KSUiTeach
- 5Mpx / 8Mpx - Full HD - Photo & video - Command line - Python module - Infra-red camera
Raspberry Pi camera module
biggu
yinab
owtie
.com
@KSUiTeach
MaterialsYou will need:
Camera
Female / Female Jumper Wire
BreadBoard
Motion Sensor
Male / Female Jumper Wire
Button
biggu
yinab
owtie
.com
@KSUiTeach
Connect the camera
•Find the Camera Connector
•Pull Up on the Black Tabs
•Push opposite end of Camera Module into connector snuggly and evenly
•Push Down on Black Tabsbiggu
yinab
owtie
.com
@KSUiTeach
Camera CapabilitiesTimelapse High Speed Recording
Sensor & Images Infrared photography
biggu
yinab
owtie
.com
@KSUiTeach
Test your camera•It’s important to test the Camera
to insure you have installed it correctly
•Go to the command line on your Raspberry Pi and type in the commands you have below
pi@raspberrypi:~$raspistill-oimage.jpg
pi@raspberrypi:~$raspistill-k
Ctrl + C to close preview
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 3: Take a Selfie
biggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides build a selfie camera, and code it in Python
biggu
yinab
owtie
.com
@KSUiTeach
Take a selfie
##selfie.pyfrompicameraimportPiCamerafromtimeimportsleep
camera=PiCamera()
camera.start_preview(alpha=192)sleep(3)camera.capture("/home/pi/image.jpg")camera.stop_preview()
•Go to Python 3 and enter in the selfie code •Find the Selfie in the File Manager
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 4: Add a Button
biggu
yinab
owtie
.com
@KSUiTeach
Add a Button•Use your BreadBoard to build a Button for your
Camera
biggu
yinab
owtie
.com
@KSUiTeach
Add Button code
##button.pyfrompicameraimportPiCamerafromgpiozeroimportButtonfromtimeimportsleep
camera=PiCamera()button=Button(17)
camera.start_preview(alpha=192)button.wait_for_press()sleep(3)camera.capture("/home/pi/button.jpg")camera.stop_preview()
Use Python Code to code your camera to take a picture every time you press the button
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Take Multiple Pictures with a Loop
##loop.pyfrompicameraimportPiCamerafromgpiozeroimportButtonfromtimeimportsleep
camera=PiCamera()button=Button(17)
camera.start_preview(alpha=192)foriinrange(5):button.wait_for_press()sleep(1)camera.capture("/home/pi/button{0}.jpg".format(i))camera.stop_preview()
Try out this code as an avenue to take multiple pictures!
The Code
biggu
yinab
owtie
.com
@KSUiTeach
What's the difference?
…
button.wait_for_press()
for i in range(5):
sleep(3)
camera.capture("/home/pi/button{0}.jpg".format(i))
Change your multiple picture code to reflect the code below. What’s the difference?
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 5: Use Filters
biggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides code to take pictures with Filters!
biggu
yinab
owtie
.com
@KSUiTeach
Picamera effectsColor Swap Sketch
Negative Embossbiggu
yinab
owtie
.com
@KSUiTeach
Picamera Effects•Start with the same code from your Selfie
•Use the code below to adjust
•Make sure you save it as an effect
…
camera.start_preview(alpha=192)
button.wait_for_press()
camera.image_effect = 'negative'
sleep(5)
camera.capture("/home/pi/negative.jpg")
camera.stop_preview()
• Try more effects: • negative • colorswap • sketch • emboss
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 6: Video
biggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides code to take Video!
biggu
yinab
owtie
.com
@KSUiTeach
Capturing video
##video.pyfrompicameraimportPiCamera
camera=PiCamera()camera.start_preview(alpha=192)camera.framerate=24camera.start_recording('my_video.h264')camera.wait_recording(15)camera.stop_recording()camera.stop_preview()
pi@raspberrypi:~ $ omxplayer my_video.h264
•Use the code on the left to capture video with the Raspberry Pi •Input the Command Line Code on the Right to Play Your Video The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 7: Add a Motion
Sensorbiggu
yinab
owtie
.com
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides code to take Video!
biggu
yinab
owtie
.com
@KSUiTeach
Add a Motion Sensor• First thing is first. Hook that Bad Boy Up with your
pins!
• The top of the motion sensor can come off to make it easier to see which cord goes where
biggu
yinab
owtie
.com
@KSUiTeach
Add Motion Sensor Code
##motion.pyfrompicameraimportPiCamerafromgpiozeroimportMotionSensorfromtimeimportsleep
camera=PiCamera()sensor=MotionSensor(4)
camera.start_preview(alpha=192)sensor.wait_for_motion()sleep(3)camera.capture("/home/pi/pir.jpg")camera.stop_preview()
•After connecting the sensor, use the code below to take pictures with motion
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 8: Time Lapsebig
guyin
abow
tie.co
m
@KSUiTeach
Code Your Raspberry Pi•Find this Slide Deck on the Raspberry Pi Playground at https://
goo.gl/XhMwdC
•Using the next few slides code to create a time lapse!
biggu
yinab
owtie
.com
@KSUiTeach
Capturing a time lapse
##timelapse.pyfrompicameraimportPiCamerafromtimeimportsleep
camera=PiCamera()fornuminrange(1440):
sleep(60)camera.start_preview(alpha=
192)camera.capture("/home/pi/
timelapse{0}.jpg".format(num))camera.stop_preview()
•Use the code below to create a time lapse
The Code
biggu
yinab
owtie
.com
@KSUiTeach
Challenge 9: Create Your Own Projectbig
guyin
abow
tie.co
m
@KSUiTeach
Code Your Raspberry Pi
•Find this Slide Deck on the Raspberry Pi Playground at https://goo.gl/XhMwdC
•Using the next slide to create your own project!
biggu
yinab
owtie
.com
@KSUiTeach
Documentation and help guides
picamera.readthedocs.io
gpiozero.readthedocs.io
raspberrypi.org/resources
raspberrypi.org/education/downloads
biggu
yinab
owtie
.com
@KSUiTeach
Visit: ksuiteach.org Visit: seeedudifferently.com Presentation is at: bigguyinabowtie.com/Google Check out my Youtube Channel! http://bit.ly/bigguybowtievideo Follow me on Twitter, Instagram, and Snapchat @bigguyinabowtie big
guyin
abow
tie.co
m
@KSUiTeach
biggu
yinab
owtie
.com