Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

25
Intro to Raspberry Pi Brad Luyster BradLuyster@gmai l.com

description

Intro to Raspberry Pi Brad Luyster [email protected]. Before We Start. Windows Users Go to http://files.lvl1.org from your web browser Navigate to “Raspberry Pi Boot Camp” Download all the files, then Install RealTerm, Win32DiskImager and Putty (Keep the .img file for later) - PowerPoint PPT Presentation

Transcript of Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Page 1: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Intro to Raspberry Pi

Brad LuysterBradLuyster@gm

ail.com

Page 2: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Before We Start● Windows Users

– Go to http://files.lvl1.org from your web browser– Navigate to “Raspberry Pi Boot Camp”– Download all the files, then Install RealTerm,

Win32DiskImager and Putty (Keep the .img file for later)● Linux/Mac Users

– Go to http://files.lvl1.org from your web browser– Download “2013-07-26-wheezy-raspbian.img”– Install Picocom (Or know how to use screen to open a

serial port)– Know how to use “dd” and “ssh”

Page 3: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

What is the Raspberry Pi?

$35!

Wow!

Page 4: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Raspberry Pi I/O

Page 5: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Raspberry Pi I/O

http://elinux.org/RPi_Hardwarehttp://elinux.org/RPi_VerifiedPeripheralshttp://elinux.org/Rpi_Low-level_peripherals

Page 6: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Raspberry Pi I/O

Page 7: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Raspberry Pi OS

● Raspberry Pi is a full blown computer● Runs Linux

– Windows Licensing restrictions make that a non-starter

● You're going to learn how to use Linux, yay!

Page 8: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Pi Project Inspiration

Page 9: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Running your Pi

● Software– Windows

● Win32DiskImager● RealTerm

– Linux/Mac● Picocom

● Hardware– SD Card– USB Cable– Serial Adapter

Page 10: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Pi OS Choices

● Raspbian● ArchArm● PiDora

Page 11: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Installing the Image

● Windows– Extract Image file to SD Card using

Win32DiskImager (Select Image file and SD Drive)● Linux

– Use “dd bs=4M if=[IMAGE FILE] of=/dev/sd[DRIVE]”– Be very careful to select the correct “of” drive.

Page 12: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Connect the Serial

● Black to GND● White to TXD● Green to RXD● RED IS DISCONNECTED

Page 13: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Logging in to Pi

● Username is “pi”● Password is “raspberry”● You are now at a Linux Console

Page 14: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Linux Console Basics

● “ls”: List files in the current directory● “cd”: Change Directory● “cp”: Copy File● “mkdir”: Make Directory● “nano”: Open Text File Editor

Page 15: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Config

● On first boot, run “sudo raspi-config”● Sudo – Super User Do

– Needed to do risky things on Linux● Expand Filesystem is the most important thing

to do here● Reboot Afterward

Page 16: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Hello World!

● Grab and LED, and and a 560 ohm Resistor (Green, Blue, Brown)

● Resistor to GND● Short LED leg to resistor● Long LED leg to #4

Page 17: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Hello World● At the console, type “sudo python” and press

enter to open python● “import RPi.GPIO as GPIO” to import the GPIO

module● “GPIO.setmode(GPIO.BCM)” to set board pin

numbering● “GPIO.setup(4, GPIO.OUT)”● “GPIO.output(4, GPIO.HIGH)” to turn LED on● “GPIO.output(4, GPIO.LOW)” to turn LED off

Page 18: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

More Advanced “Hello World”

import RPi.GPIO as GPIOimport time

GPIO.setmode(GPIO.BCM)GPIO.setup(4, GPIO.OUT)

while(1): GPIO.output(4, GPIO.HIGH) time.sleep(1) GPIO.output(4, GPIO.LOW) time.sleep(1)

Page 19: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Inputs

● Put switch in breadboard.● Connect 10k resistor (Brown Black Red)

between 3.3v and switch● Connect other side of switch to GND● Connect side with resistor to #17

Page 20: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Polled Inputs

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)GPIO.setup(4, GPIO.OUT)GPIO.setup(17, GPIO.IN)

while(1): if GPIO.input(17) == GPIO.LOW: GPIO.output(4, GPIO.HIGH) else: GPIO.output(4, GPIO.LOW)

Page 21: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Interrupt Inputsimport RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)GPIO.setup(4, GPIO.OUT)GPIO.setup(17, GPIO.IN)

def my_callback(channel): print("Switch Pressed!")

GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback)

while(1): pass

Page 22: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Debounced Interruptsimport RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)GPIO.setup(4, GPIO.OUT)GPIO.setup(17, GPIO.IN)

def my_callback(channel): print("Switch Pressed!")

GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=200)

while(1): pass

Page 23: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Networked Pi

● Plug in your network cable● Type “ifconfig” to get network interface config● Note the “inet addr” for “eth0”

Page 24: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Networked Pi

● “sudo apt-get update”● “sudo apt-get upgrade”● Upgrades all software packages● “sudo apt-get install [package]” to install new

– Try it now! “sudo apt-get install sl”

Page 25: Intro to Raspberry Pi Brad Luyster BradLuyster@gmail

Resources● Buy a Pi

– Element14– RS Electronics– *** MCM Electronics ***

● Buy Pi Stuff– *** MCM Electronics ***– Adafruit

● Learn– Learn.adafruit.com– Raspberrypi.org– Elinux.org– LVL1!