Somewhat over-engineered blinking LEDs

Posted on

My Raspberry Pi arrived a couple of weeks ago and I've been working on turning it into a mini-audio server to connect to the home stereo in the living room.

As part of the project I'd like to drive an analog VU meter from the sound signal.

This week my (enthusiastic!) wife and I played around with attaching some basic electronics to the GPIO ports so that we could get more comfortable the Raspberry Pi. Our electronics knowledge is more than a little rusty but surprisingly everything we tried worked first go.

On the first night we attached a LED in line with a resistor directly to a GPIO port and were able to programmatically turn it on and off. Easily done.

Then we took that a little further by using a transistor to switch the LED from the Pi's 5V power supply. This is a better option because the circuit can be arranged so that a minimal current is pulled from the GPIO pin but a higher current can be put through the LED to give a nice bright light. The amount of current you can put through the GPIO pins without damaging the Pi is limited so this is a safer option (although not strictly needed for a single LED). There's an excellent page on elinux.org which explains this arrangment.

Here's the result (sorry about the dodgy video quality):

The Python code driving the LED looks like:

import itertools
import time
import RPi.GPIO as GPIO

# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BCM)

# set up GPIO output channel
GPIO.setup(17, GPIO.OUT)

pin_values = itertools.cycle([GPIO.HIGH, GPIO.LOW])

for pin_value in pin_values:
    GPIO.output(17, pin_value)
    time.sleep(1)

On the second night we duplicated this circuit 5 times to drive 5 LEDs:

We were quite chuffed that we managed to pack everything neatly into one end of the breadboard so that all the LEDs were in a line.

The plan now is to get PulseAudio working. It provides a nice way to intercept the sound going to the audio output. It should be possible to use that to drive these LEDs like the lights on a retro 80's hi-fi system.

And after comes driving an analog meter which will require digital-to-analog conversion either by using the PWM channels or an external DAC chip. More on that to come.