GPIO Zero with CamJam Edu Kit 1

GPIO Zero with CamJam Edu Kit 1

Physical computing Raspberry Pi workshop using the CamJam Edu Kit 1 with Python and GPIO Zero. Workshop given at the Raspberry Pi Birthday Party.

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

March 06, 2016
Tweet

Transcript

  1. GPIO Zero with CamJam Edu Kit 1 Introducing the GPIO

    Zero library with simple components from the CamJam Edu Kit
  2. None
  3. Boot the Pi and open Python 3

  4. Open a new file • File > New File •

    File > Save • Save as camjam.py
  5. GPIO Button from gpiozero import Button button = Button(21) while

    True: print(button.is_pressed) Save and run: Ctrl + S F5
  6. GPIO Button from gpiozero import Button button = Button(21) while

    True: if button.is_pressed: print("Hello") else: print("Goodbye")
  7. GPIO Zero Button from gpiozero import Button button = Button(21)

    while True: button.wait_for_press() print("Pressed") button.wait_for_release() print("Released")
  8. GPIO Zero Button + LED from gpiozero import Button, LED

    button = Button(21) led = LED(25) while True: button.wait_for_press() led.on() button.wait_for_release() led.off()
  9. GPIO Zero Button + LED from gpiozero import Button, LED

    button = Button(21) led = LED(25) while True: button.wait_for_press() led.off() button.wait_for_release() led.on()
  10. GPIO Zero Button + LED from gpiozero import Button, LED

    button = Button(21) led = LED(25) while True: led.blink() button.wait_for_press() led.off() button.wait_for_release()
  11. Traffic Lights from gpiozero import Button, TrafficLights button = Button(21)

    lights = TrafficLights(25, 8, 7) while True: button.wait_for_press() lights.on() button.wait_for_release() lights.off()
  12. Traffic Lights from gpiozero import Button, TrafficLights button = Button(21)

    lights = TrafficLights(25, 8, 7) while True: lights.blink() button.wait_for_press() lights.on() button.wait_for_release()
  13. Traffic Lights from gpiozero import Button, TrafficLights, Buzzer from time

    import sleep button = Button(21) lights = TrafficLights(25, 8, 7) buzzer = Buzzer(15) while True: button.wait_for_press() lights.off() buzzer.on() button.wait_for_release() lights.on() buzzer.off()
  14. Traffic Lights while True: lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on() sleep(1)

    lights.off()
  15. Traffic Lights while True: button.wait_for_press() lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on()

    sleep(1) lights.off()
  16. Traffic Lights Sequence • Can you make a full traffic

    lights sequence? • Use the button for a pedestrian crossing • Use buzzer.beep() to indicate safe crossing
  17. Documentation and help guides • gpiozero.readthedocs.org • raspberrypi.org/resources • raspberrypi.org/education/downloads

  18. GPIO Zero with CamJam Edu Kit 1 Introducing the GPIO

    Zero library with simple components from the CamJam Edu Kit