Introduction to Raspberry Pi through Making


Objectives

The students will be able to:

  • Explain that Linux is an operating system like Windows or MacOS
  • Navigate to files in Linux
  • Access the internet using the built in browser 
  • Modify and run a pre-written Python program 
  • Make an LED Blink on the Raspberry Pi
  • Wire an LED to connect to the Raspberry Pi

Outline of Lesson

  • Introduction to Raspberry Pi and Linux
  • Writing your first python program
  • Modifying the code
  • Description of the wiring required for LED’s
  • Students wire a 3rd LED to their breadboard
  • Students program 3rd LED
  • Journal Reflection

Teaching/Learning Activities

  • Teacher demo of the Raspbian version of Linux installed on Raspberry Pi
  • Make sure to demonstrate how to:
    • Navigate to files using the file system GUI
    • Navigate to websites using the built in web browser
    • Open up an idle editor window in python
    • Run a python file as super user
      • sudo python <python file>
      • the default root user is username: pi and password: raspberry
  • Give students access to the starter python file (attached) and pre-built breadboards.
  • Walk them through running the starter program (led_test_starter.py)
    • Point out that lines that begin with a # are called comments and are there as notes left by the person who wrote the program.  Students will probably know this symbol as a hashtag.
    • Start by describing the import lines:
      • import RPi.GPIO as GPIO
        • Tell students this is required to use code that works with the raspberry pi General Purpose Input/Output pins.  The as GPIO is just telling the computer that when you type GPIO you mean RPi.GPIO.  It’s a shortcut.
    • Describe that you are defining the variable GREEN to the number 18, and point out how the LED is wired to port 18 on the raspberry pi
    • Describe that the GPIO.setmode line is required for all of your RPi projects
    • The GPIO.setup(GREEN, GPIO.OUT) sets up pin 18 as output.
      • Two possible followup questions:
        • Why is it pin 18?
          • Because the variable GREEN is equal to 18
        • What is a type of output for a computer?
          • Picture, sound, printing… guide students to light!  An LED!
    • while(True) means that everything indented will happen over and over again.  This will be a common structure in our RPi programs: some setup at the start and a while true loop that repeats until we manually end the program.
    • print ‘green on’ prints something to the console
    • GPIO.output(GREEN,True) sets the light to on
      • Students will struggle with this and think it just makes the light flash.  It is important to let them struggle with this on their own, but if by the end of the lesson it is still confusing it can be helpful to relate it to a light switch.  This line of code turns the switch on and the light will stay on until you switch it off.
    • GPIO.output(Green, False) turns the light off
    • time.sleep(.5) makes the program pause for half a second.
  • Challenge students to build on the code
    • Ask a student what pin the red LED is connected to?
      • Depends on how you wired the boards, but probably 23
    • Challenge them to make both LEDs turn on and off together.
    • For students who finish early, challenge them to make different patterns, alternating, a longer time on than off, etc.
  • Explain the wiring to the students
  • Challenge students to wire in a third LED and then program it to blink along with the other two.
  • Journal reflection to end the day (make sure to leave a good 15 minutes for cleanup before reflection or your room will be covered in wires and parts)
    • What did you learn today?
    • What is something you enjoyed about today?
    • What is something that did not work well?
    • Do you have any suggestions for me about how you work best for the rest of the week?
  • Do not share out these journal entries, but make sure to read them before the next session.

Resources


Download: led_test_starter.py


Return to top