Introduction: Raspberry Pi 3x3 LED Cube

About a month ago my dad bought a soldering iron and we both learnt to solder by making an LED cube controlled by an Arduino. It was a cool project to show my friends and really easy to build so I have decided to make one for the Raspberry Pi and an Adafruit Cobbler because there are not many LED cubes for the Pi.

Bits needed

  • Breadboard
  • 27 LEDs
  • Soldering iron and solder
  • Wires
  • 3 transistors
  • Any Raspberry Pi
  • Adafruit Cobbler (optional)

Step 1: Building the LED Cube

Start by measuring the length of the shorter wire coming out of the LED. This gives you the maximum distance between the LEDs in the cube so that you can draw a 3x3 grid on a piece of plywood and drill 9 holes the same size as the LEDs e.g. 3mm or 5mm.

Test each LED works by running a wire from the Raspberry Pi’s 5v and ground pins and touching the LED wires.

Put a LED in each hole and bend the shorter wire flat as shown in the diagram. Each wire should touch the shorter wire of the next LED but should not touch the longer wire that points straight up.

Now solder the short wires together to create one layer of the cube. I then tested the layer by putting the ground wire against any of the shorter pins that were just soldered. By touching the longer vertical wires with the 5v wire then the LED should light up. Ease the LED layer out of the holes and create 2 more layers exactly the same.

The first time I made a cube I got my dad to cut me some wood the right thickness to hold one layer of LEDs above the other. The second cube I made at Coventry Makerspace so used some of their 3D printed pens and they were the perfect size. So one layer goes back into the plywood jig, the pens went down to support the next layer and I soldered the vertical wires to the layer above. I moved the pens up a layer and finished the soldering. Finally a test of the LEDs by putting the ground wire on a layer and completing the circuit by touching the other pins with the 5v wire. If everything is working then the corresponding LED should light up.

The final bit of soldering is to attach a wire to each layer of the cube so that they can be linked to the breadboard.

Step 2: Building the Circuit

The next bit is fiddly and involves you placing the 9 pin of the cube into the breadboard such that each pin is separate from the others. I did it by twisting the cube slightly.

The Adafruit Cobbler is attached to the breadboard and it is simply a case of connecting 9 GPIO output pins to the 9 LED cube vertical wires. Putting power to one of more of these pins will allow the corresponding column of 3 LEDs to potentially light up. To complete the circuit we need to attach each of the 3 layers to ground. If we attach them directly to ground then all three layers will always be connected to ground and you will only be able to light up a column of LEDs instead of individual ones.

So this is where we use the transistors. They were described to me as little switches with 3 pins. The 2 pins on the left and right are like the ends of the wire and for this circuit you attach 1 wire to ground and the other to the wire leading from the layers. If we put power to the middle pin then the switch is turned on and the other 2 wires become connected. So by using 3 more GPIO output pins we can connect them to the middle pin of the 3 transistors.

The electronics part of this build is now complete and we have the ability to send power to each column of LEDs and can turn on and off the connection of the levels to ground. We can now turn on any LED with a combination of LED column and layer being activated.

Step 3: Programming

The following simple Python program demonstrates how to light up the LEDs in pretty patterns:

#**************************************************************************************

#*

#* Title: 3x3 LED Cube #* #* Description: Simple LED cube for soldering practice and demonstrate some #* array handling with GPIO pins #* - Pins P1 to P9 are connected to LED Cathode (-) #* - Layers are connected to LED Anode (+) #* #* Author: Jacob Groves, Coventry Makerspace #* #**************************************************************************************

import RPi.GPIO as GPIO from time import sleep

# Assign the individual LED pins a variable name . . . P1 = 13 P2 = 19 P3 = 26 P4 = 23 P5 = 24 P6 = 25 P7 = 16 P8 = 20 P9 = 21

# Assign the layers to a nice variable . . . Top = 17 Middle = 27 Bottom = 22

# LED sequences represented by an array . . . aPins = [P1, P2, P3, P4, P5, P6, P7, P8, P9] aPinsReversed = [P9, P8, P7, P6, P5, P4, P3, P2, P1] aPinsStar = [P1, P2, P3, P6, P9, P8, P7, P4] aPinsStar2 = [P9, P8, P7, P4, P1, P2, P3, P6] aPinsSpiral = [P1, P2, P3, P6, P9, P8, P7, P4, P5] aPinsSpiralReversed = [P5, P4, P7, P8, P9, P6, P3, P2, P1]

aLayers = [Top, Middle, Bottom]

# Time delay built in between pin output . . . delay = 0.15

#************************************************************************** #* setupColumns - Initialisation of the pins . . . #************************************************************************** def setupColumns():

# GPIO pin addressing will use the virtual number . . . GPIO.setmode(GPIO.BCM)

# Initialise the pins so we can output values to them . . . GPIO.setup(aPins, GPIO.OUT) GPIO.setup(aLayers, GPIO.OUT)

GPIO.output(aPins, False) GPIO.output(aLayers, True) #************************************************************************** #* cyclePins - Receive array of pins & light them up one by one . . . #************************************************************************** def cyclePins(pPins):

for iPin in pPins: GPIO.output(iPin, True) sleep(delay) GPIO.output(iPin, False)

#************************************************************************** #* cyclePinsPair - Receive 2 arrays of pins & light them up in pairs . . . #************************************************************************** def cyclePinsPair(pPins, pPins2):

for iPin in range(len(pPins)): GPIO.output(pPins[iPin], True) GPIO.output(pPins2[iPin], True) sleep(delay) GPIO.output(pPins[iPin], False) GPIO.output(pPins2[iPin], False)

#************************************************************************** #* Mainline logic . . . #************************************************************************** try: print('Press CTRL+C to stop script') i = 0 while(true):

# Spinning star . . . GPIO.output(aLayers, True) GPIO.output(P5, True) cyclePinsPair(aPinsStar, aPinsStar2) cyclePinsPair(aPinsStar, aPinsStar2) GPIO.output(P5, False)

# Zig-zaggy columns . . . GPIO.output(aLayers, True) cyclePins(aPins) cyclePins(aPinsReversed) GPIO.output(aLayers, False)

# Spiral columns . . . GPIO.output(aLayers, True) cyclePins(aPinsSpiral) cyclePins(aPinsSpiralReversed) GPIO.output(aLayers, False)

# Zig-zaggy layers . . . GPIO.output(Top, True) cyclePins(aPins) GPIO.output(Top, False) GPIO.output(Middle, True) cyclePins(aPinsReversed) GPIO.output(Middle, False) GPIO.output(Bottom, True) cyclePins(aPins) GPIO.output(Bottom, False) sleep(delay) except KeyboardInterrupt: GPIO.cleanup()

finally: GPIO.cleanup()

de>

Comments

author
Sasquatch885 (author)2016-11-20

I have been in electronics for over 30 years. The concept is good but implementation has problems. Needed resistors are left out. They are needed to protect the LEDs and transistors as well as the GPIO of the Raspberry Pi. 130 ohm 5% resistors in series with the LEDs and base of the transistors is needed.

author
subzero69 (author)2016-03-22

You also missed the fact that the NPN's need to be connected to a ground pin. How the hell did this win a medal.

author
subzero69 made it! (author)2016-03-22

Made one, took me a good two hours but now I have to clean up the sodding code. Seriously.

2016-03-22 12.57.50.jpg
author
Wwalzu123. (author)2015-12-24

Doesnt this need any recistors... ?

author
Steve99and04 (author)2015-06-29

If somebody knows how to embed code, please let me know because it keeps stripping out spaces/tabs :-(

author
Steve99and04 (author)2015-06-25

Code uploaded as a PY file. I think it is the latest but kids tend not to use source control :-)

author
tanj666 (author)2015-06-23

Excellent project! Any chance you can detail the transistors for me so I can try and make one for myself? Soldering is easy but deciding what components like transistors is tough for me ;)

author
Steve99and04 (author)tanj6662015-06-23

Not an expert but is there such a thing as a NPN transistor? You put a current to the middle pin and it opens the gate to allow a current to flow between the other 2 pins. :-)

author
KerryW (author)2015-06-22

I really love this project, and it is great to see kids making!

author
seamster (author)2015-06-22

Very cool project! Thank you for sharing your work here.

About This Instructable

13,176views

137favorites

License:

More by Steve99and04:Simple Wooden Wine CharmConcertina Potatoes and Butterflied LambEasy Build Wine Spike
Add instructable to: