RPiWorkshop



RPiWorkshop

0 0


RPiWorkshop

Raspberry Pi Workshop for Hong Kong Mini Maker Faire

On Github nodu / RPiWorkshop

Introduction to Raspberry Pi

Matt Nodurfth

Raspberry Pi Computer

  • Cheap, $35 USD
  • Powerful
  • Linux
  • Easy to use with existing parts
  • GPIO Pins

What can be done with a Raspberry Pi?

Home Automation

Dynamic Bike Headlight

Raspbmc

Games

Education!

Let's build this simple circuit

  • Connect:
    • Vcc to pin 3.3V
    • Ground to GND
    • Input Pin to pin 25

Linux

We're using Raspbian, but there are many flavors!

OK, Let's start!

  • User: pi
  • Password: raspberry

What can you see?

Let's ...

See where we are:

pwd

Look at current directory

ls

Make a directory

mkdir  MakerFaire

Move around

cd MakerFaire

Make a file

touch game.py

Ok, time for the safety of the GUI

startx

Let's Code!

  • Python
  • Ben Croston's RPi.GPIO and John Paulett's stopwatch modules
  • Five Second Stadium
  • IDLE, Your python environment
import stopwatch
import RPi.GPIO as GPIO
    
pin = 25
    
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN)
    
print "\n***************************************"
print "*** Welcome to Five Second Stadium! ***"
print "***************************************\n"
print "Press the BUTTON to start and press again to stop after 5 sec!"
print "Press ctrl + c to quit"
print "--------------------------------------------------------------\n"
    
OK Let's run this code
sudo python game.py
while True:
    print "Start?"
    GPIO.wait_for_edge(pin, GPIO.FALLING)
    t = stopwatch.Timer()
    print "***Started!***\n\n"
    print "Stop?"
    GPIO.wait_for_edge(pin, GPIO.FALLING)
    t.stop()
    rounded = "%.2f" % t.elapsed
    print rounded, " seconds!"
    
    if float(rounded) == 5:
        print "*** Congratulations Champion! ***"
    else:
        print "So Close!"
    
    print "Would you like to play again?"
    GPIO.wait_for_edge(pin, GPIO.FALLING)

Let's Play!

sudo python ffs.py

What's the problem with our current design?

Switch Bounce

  • Connect:
    • 10uF Capacitor between GND and input rows

Let's try that again!

 sudo python ffs.py

Finished!