Knight Rider & Cylon Lights for the Raspberry Pi




The most obvious application for a Raspberry Pi is re-creating the sliding red lights found on “KITT” from Knight Rider or the Cylons in Battestar Galactica. This can all be done with pure electronics but that doesn’t involve any programming and therefore isn’t as cool.

So here is a brief description of my “running lights” project. It may be overkill to throw an entire computer at such a task but it served a number of purposes :

  • good introduction to Python GPIO programming
  • good introduction to Raspberry Pi GPIO interfacing
  • good practice at soldering, wiring, testing and constructing an electronic circuit

It isn’t my intention to show you how to create the circuit board but hopefully there is enough information on this page to help you get started.

Knight Rider & Cylon Lights for the Raspberry Pi

Raspberry Pi Parts

Components

  • 10 5mm Red LEDs (£1.50)
  • 10 560ohm resistors (£0.10)
  • 10 27Kohm resistors (£0.10)
  • 10 BC548 NPN transistors (£1.00)
  • 1 Stripboard (£3.50)
  • 12 lengths of wire
  • 1 0.1″ Crimp connector housing 1×3 pin (£0.05)
  • 2 0.1″ Crimp connector housing 1×10 pin (£0.40)
  • 12+ Female crimp pins for 0.1″ housings (£0.60)

Tools

  • Wirecutters/stripers
  • Soldering iron + solder
  • 1 Stripboard cutter Tool (Spot Face Cutter)

In total the board cost me approximately £10 in bits but it really depends on what components and tools you already have. I didn’t need to buy solder or a stripboard cutter but I did spend £12 on a new wire stripper. If you plan on doing any work with stripboard a “stripboard cutter” or “spot cutter” is well worth a few pounds/dollars.

The photos below show my scripboard with the 10 LEDs, resistors and transistors soldered in place. Each LED requires 1 560ohm resistor, 1 27Kohm resistor and 1 BC548 transistor.

Knight Rider & Cylon Lights for the Raspberry Pi Schemetic

Given the low current required the transistor can replaced with any device that can supply the LED with 5mA. So BC547 or BC548 devices are perfect.

I didn’t worry which LED I connected to which GPIO pin. Once the circuit was working I corrected the light sequence in the Python code to put them in the correct order.

Python Program

This is the Python program I used to sequentially turn the LEDs on an off. It uses the RPi.GPIO library so that must installed already.

#------------------------------------------------
# Name: Running Lights
# Author    : matt.hawkins
# Created   : 21/06/2012
# Python    : 2.7
# Copyright : (c) matt.hawkins 2012
#------------------------------------------------
#!/usr/bin/env python

# Import required libraries
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define GPIO signals to use
# that are connected to 10 LEDs
# Pins 7,11,13,15,19,24,23,16,18,22
# GPIO4,GPIO17,GPIO21,GPIO22,GPIO10,
# GPIO8,GPIO11,GPIO23,GPIO24,GPIO25
RpiGPIO = [4,17,21,22,10,8,11,23,24,25]

# Set all pins as output
for pin in RpiGPIO:
  print "Setup pins"
  GPIO.setup(pin,GPIO.OUT)

# Define some settings
StepCounter = 0
StepDir = 1
WaitTime = 0.2

# Define some sequences

# One LED
StepCount1 = 10
Seq1 = []
Seq1 = range(0,StepCount1)
Seq1[0] =[1,0,0,0,0,0,0,0,0,0]
Seq1[1] =[0,1,0,0,0,0,0,0,0,0]
Seq1[2] =[0,0,1,0,0,0,0,0,0,0]
Seq1[3] =[0,0,0,1,0,0,0,0,0,0]
Seq1[4] =[0,0,0,0,1,0,0,0,0,0]
Seq1[5] =[0,0,0,0,0,1,0,0,0,0]
Seq1[6] =[0,0,0,0,0,0,1,0,0,0]
Seq1[7] =[0,0,0,0,0,0,0,1,0,0]
Seq1[8] =[0,0,0,0,0,0,0,0,1,0]
Seq1[9] =[0,0,0,0,0,0,0,0,0,1]

For more detail: Knight Rider & Cylon Lights for the Raspberry Pi




© 2015 Powered By Engineering Projects Team, Raspberry Pi Projects

Scroll to top