Blinking Light(s) with the Raspberry Pi!

Welcome to the wonderful world of controlling physical objects with software! This tutorial is a complete beginners introduction to the Raspberry Pi computer, covering the basic features and functions to help you bring your ideas to life!

IMG_4140

Blinking a light using the Raspberry Pi’s General Purpose Input and Output (“GPIO”) pins is the hardware equivalent of a “Hello World” software program.

  1. First, gather the following materials:
    Breadboard (or wires/alligator clips)
    Two (2) Breadboard wires (Male-to-female are ideal)
    One (1) (or more!) LED (Light Emitting Diode)
    One (1) 330 Ohm resistor
    And the rest of the normal stuff to set up the RPi (SD card, power cord, keyboard + mouse (or just keyboard), HDMI cable and monitor.)
  2. Wire up the breadboard!IMG_4146
    Pick a GPIO pin. Attach the female end of one breadboard wire to the GPIO pin, and the male end
    Connect the other breadboard wire from ground on the RPi (third down on exterior side) to negative slot on the breadboard.
    Connect the resistor from the positive series of holes to an open row on the breadboard (I picked row 10).Connect the long side of the LED to the same row the resistor is in. Connect the short side to the negative slot.
    Make sure nothing explodes (just kidding that probably won’t happen 🙂 )
  3. Write a quick Python program.
    The program switches the GPIO pin between on and off, turning the LED on/off as it switches. Save the program somewhere easy, like the Desktop.
    Here’s my code if you need some assistance:

    import RPi.GPIO as gpio
    import time

    #SEtup pin 18 as an output
    gpio.setmode(gpio.BCM)
    gpio.setup(18, gpio.OUT),/span>

    #define data to be the value of pin 18
    #data = GPIO.IN0(18)

    #Make an LED flash on and off
    while True:
    gpio.output(18, gpio.HIGH)
    print(‘Light is on.’) #Optional printout of status
    time.sleep(1) #changing the number increases/decreases length of signal
    #print(data)
    gpio.output(18, gpio.LOW)
    print(‘Light is off.’) #Optional printout of status
    time.sleep(1)
    #print(data)

  4. Run the program!

IMG_4144In the terminal window, go to the folder where you saved your program. The command cd + the directory name (ex. /home/pi/Desktop) will take you there.
Run the program by typing sudo python “ProgramTitle”.py
As long as everything is connected and the program does what you think it does, the LED will flash.
That’s it! Super simple, and it means that this little RPi computer just controlled a physical object wooooo!!!
Optional fun:
– Change the timing of the blink.
– Connect a couple more LEDs the same way you connected the first (these will be in parallel with each other).
– Connect additional GPIO pins to more LEDs and change the timing (remember to also add in the appropriate code).

Helpful info:

www.atariarchives.org
www.atariarchives.org


As shown in the photo to the right, breadboards usually have columns for positive and negative (red and black, respectively) that are connected electrically all the way down the board.  Each row contains 5 holes that are also connected.

The resistor needs to go in between the LED and the power source to limit the amount of current, or electricity, flowing through the LED. The LED would be brighter w/out the resistor, but it will probably burn up super quick.

Happy building!

IMG_4150

Setting up a Raspberry Pi to Control Physical Objects, Pt. 2

What cool things can you do with the Raspberry Pi?

Source: http://www.aoakley.com
Source: http://www.aoakley.com

Welcome back to exploring the Raspberry Pi! There are tons of awesome things you can do with the Raspberry Pi — (pretty much) everything that you would do on a normal computer, like word processing, surfing the internet, streaming videos, etc.

You can write programs on it using the Idle software (Python language), Scratch, or Linux. This might seem mundane, but keep in mind that you bought this lil’ computer for only $30 dollars (+shipping and handling). If you have kids, this is a fantastic option for a first computer! The RPi naturally teaches and encourages hardware and software programming. Plus, you won’t mind as much when the kids spill apple juice all over it (or if you’re like me and still spill apple juice on computers, this is a great option for a backup computer..).

 

You can print this GPIO Leaf and stick in on the board!
You can print this GPIO Leaf and stick in on the board!

GPIO Pins!
By far the coolest way to use the Pi is to interface w/ the real world using the GPIO pins (that row of 26 pins adjacent to the RCA video port, or the yellow port). The GPIO pins have different functions as shown in the photo below: 17 of the 26 total pins are actual GPIO pins, while the rest are either ground, a power source (5 VDC or 3.3 VDC) or labeled “DNC” for “Do Not Connect”/”N/C” for “Not Connected” (connecting to these pins may short the Pi, so it is recommended to avoid these).

GPIO pins can be used as an input or an output. As an input, the pin can distinguish between two values: HIGH*  and LOW. As an output, you can send an ON, or HIGH signal (3.3 VDC), or an OFF, or LOW signal (0 VDC). These pins can be used for tons of physical tasks, like turning on/off lights (Christmas light choreography, anyone??), controlling motors, reading sensors, and honestly pretty much anything you can conceive, as long as you build a proper circuit.

Some of the GPIO pins also have more specific functions, such as SDA (data line), SCL (clock), etc.; if you’re reading this as a beginner don’t worry about these just yet. When you find a project you’re excited about you’ll naturally learn these functions as necessary.
*High input threshold is a signal of ~ 1.8 VDC, although it can vary between 0.8 – 2.0 VDC. This means that any signal coming in to your GPIO pin that is above 0.8 VDC may be read as “HIGH” by the RPi.

Advanced users will be happy to know that you can modify many of the GPIO characteristics from software (this link also has the robust GPIO electrical specifications).

For absolute beginners, here are some helpful things to know about the GPIO pins:
ac-dc-voltageGPIO pins operate on Direct Current (DC) voltage. Unless you want to see smoke come out of the RPi, do NOT input Alternating Current (AC) signals, like the one that comes out of the wall.
Be very careful about what you connect to the GPIO pins. You will not be able to control a motor directly from a GPIO pin; in this instance, the GPIO pin functions as a switch, rather than the actual power for the motor. Here’s a great tutorial on how to control a small motor.

Looking for more inspiration? Here’s a general list of 25 cool things to do w/ your RPi! You can also Google “Raspberry Pi projects” or browse the Instructables website for RPi projects.

The next post will cover a simple circuit you can build and control w/ the RPi.