Star-Trek-like LED lights

Star-Trek-like LED lights

posted in: Uncategorized | 0
[ Grace Hopper Conference India Nov. 14, 2013 – Getting your Hands Dirty with the RaspberryPi ]

Notes for replicating the project for Blinking LED’s in a sequence (like Star Trek main bridge)

Hardware

Rpi Model B
Rpi power adapter
Connection to laptop so that you can ssh to the Rpi (wired or wireless)
Breadboard (medium size)
3 LEDs (see picture)
3 1K resistors
4 Female to Male Jumper wires (get some extra if you can)
4 Male to Male Jumper wires (get some extra if you can)

Step-by-Step setup

IMPORTANT: Make sure you COUNT the pins correctly. Also, make sure you are careful with where the pins go on the breadboard. It’s hard to see sometimes and you might be off by one if you’re not careful. So, it’s always good to double check.

On the Rpi, do “pip install RPi.GPIO” – you need this library to make life easier
On the breadboard, on either side, you will see 2 long, marked lines of holes that go down the entire board. One line of holes is marked with “+” and the one next to it is marked with “-”. The “+” is for power and the “-” is for ground.
Take a Black female-male jumper and connect the pointy end to the first hole on the breadboard where you see “-”. What this does is make that particular series of holes “-”, i.e., ground. So, you can tap off of any of these holes to get access to ground without having to put a whole bunch of jumpers directly on the Rpi.
Now that we have a set of holes which are grounded on the breadboard, take a male-male jumper and connect one of the grounded holes to a different hole on one of teh regular breadboard holes. Best to see the pictures below.
When connecting the LED’s, the “longer” pin on the LED goes to power. The “shorter” pin goes to ground.
For the 3 LEDs I used, I used the following pins: 7, 11 and 15. See image below for counting the pins so you can connect to the correct ones.
If things don’t work, it’s almost always the wiring. Re-check all your connections.
GPIO pin layout for Rpi Model B

Connecting the GPIO pins to the LED with resistors in series
Connections on the Rpi (right to left) – Red (Pin 7), Orange (Pin 11), Yellow (Pin 15), Black (last Pin on that side which is ground)

Black wires are ground wires.

Make sure the two legs of the resistors are on different lines

Additional notes:
1. Get the RPi board revision: GPIO.RPI_REVISION
2. Get the Rpi.GPIO version: GPIO.VERSION

Basic (rough) code to test out your Star Trek-like LED Blinking lights (sequential)

#!/bin/python

import RPi.GPIO as GPIO
import time

PIN_1 = 7
PIN_2 = 11
PIN_3 = 15

# setup GPIO pin reference model. We use the BOARD method so we can access the pins on the P1 header.
GPIO.setmode(GPIO.BOARD)

def star_trek(pin1, pin2, pin3):

# setup the GPIO pin as an Input or Output
# for the purposes of this workshop, all the pins are setup as Output
GPIO.setup(pin1,GPIO.OUT)
GPIO.setup(pin2,GPIO.OUT)
GPIO.setup(pin3,GPIO.OUT)

#write to the GPIO pins to indicate when to turn
#which pin on (high) or off (low)
GPIO.output(pin1,GPIO.HIGH)
GPIO.output(pin2,GPIO.LOW)
GPIO.output(pin3,GPIO.LOW)

time.sleep(.5)
GPIO.output(pin1,GPIO.LOW)
GPIO.output(pin2,GPIO.HIGH)
GPIO.output(pin3,GPIO.LOW)

time.sleep(.5)
GPIO.output(pin1,GPIO.LOW)
GPIO.output(pin2,GPIO.LOW)
GPIO.output(pin3,GPIO.HIGH)

time.sleep(.5)

#cleanup all channels and reset
GPIO.cleanup()

#light up the LED’s in a sequence for 50 interations
for i in range(50):
star_trek(PIN_1, PIN_2, PIN_3)

”’
GPIO.setup(PIN_1,GPIO.OUT)
GPIO.setup(PIN_2,GPIO.OUT)
GPIO.setup(PIN_3,GPIO.OUT)

for i in range (100):
if (i % 2):
GPIO.output(PIN_1, GPIO.HIGH)
GPIO.output(PIN_2, GPIO.LOW)
GPIO.output(PIN_3, GPIO.LOW)

else:
GPIO.output(PIN_1, GPIO.LOW)
GPIO.output(PIN_2, GPIO.HIGH)
GPIO.output(PIN_3, GPIO.HIGH)

time.sleep(.2)

GPIO.cleanup()
”’

Leave a Reply