Wednesday, February 8, 2012

4x4x4 Led Cube



A couple of years ago I saw a 4X4X4 Led Cube at Fry's. Ever sense that day I have been wanting to make one for my self. So I finally got to doing it. I wanted to use an arduino to control it so I started digging in my parts bins and found some blue LEDs, a perfboad, and some shift registers.

I did not know were to start, so I searched the internet to see if anybody had done any using these parts. Luckily I found a few posted at instructables.com, but the only ones using shift registers where the 8x8x8 cubes. People making the 4X4X4 were not using shift registers. They were just using all the pins on their arduinos. I did not want to use up all of the pins on just the cube because eventually I also want to add a 16x2 lcd display and maybe an RTC.

So not finding any examples to work with I went ahead and started building it anyway. I used this great example to help me with the soldering part. I also took a look at the Arduino ShiftOut tutorial to help me with the wiring and to get some code started. Since I could not find any examples of anybody using this set up I had to come up with my own code.

I am not an expert. This is my hobby, and I love working with electronics. I know that there might be a better way to do it, but this is how I did it.  If you can tell me of a better way to do it. Either in hardware or software, please let me know, and if you have any questions please feel free to ask and thank you for reading.

So if you check out the link above of the great example on instructables.com. You will see that all the cathodes are connected together in each layer. I soldered every thing exactly the same way. In the picture above I labeled the layers and the transistors.

The transistors control the layers(floors)
  •  When you apply current to the base of transistor Q-1, current will flow thru the transistor. allowing layer-0 to connect to ground.
  • When you apply current to the base of transistor Q-2, current will flow thru the transistor. allowing layer-1 to connect to ground.
  • When you apply current to the base of transistor Q-3,.... Ok I think you get the point.
The shift registers control the columns

The picture above shows the columns with labels. The red columns are controlled by IC-B and the blue columns are controlled by IC-A. Each column has its own address.
  • COL-7B = 128
  • COL-6B = 64
  • COL-5B = 32
  • COL-4B = 16
  • COL-3B = 8
  • COL-2B = 4
  • COL-1B = 2
  • COL-0 = 1
If you notice the addresses, they are all binary numbers. COL-7A to COL-0A have the same address as COL-XB, but are controlled by IC-A. I'll give a few examples to show you how I implemented the ShiftOut tutorial from the Arduino website to control my cube. First I will show how I turn on all the LEDs on layer-0 (bottom layer). Second I'll show how I turn on the top right corner  LED (COL-4B) and the bottom left corner (COL-3A) on layer-3 (top layer). Third I will show how I turn on two COL-7B + COL-6B and COL-1A + COL-6A on layer-1.
  1. Turn on all the LED on layer-0.
    1. Send current to the base of Q-1 to allow current to flow thru layer-0. (My code looks something like this. digitalWrite(layer0, HIGH)).
    2.  Set the latch pin LOW so the LEDs don't change while you send the bits. (My code looks like this. digitalWrite(latch, LOW)).
    3. Turn all LEDs on like this. First line of code will be to send the first set of bits to IC-B and the second line of code will be for the second set of bits to IC-A. (first line) shiftOut(data, clock, MSBFIRST, 255); (second line) shiftOut(data, clock, MSBFIRST, 255);. The first line is for IC-B and the second line is for IC-A.
    4. Set the latch pin HIGH when your done sending bits. (digitalWrite(latch, HIGH)).
  2.  Turn on COL-4B and COL-3A on layer-3.
    1. Send current to the base of Q-4 to allow current to flow thru layer-3. (My code looks something like this. digitalWrite(layer3, HIGH)).
    2. Again set the latch pin LOW the same way.
    3. Turn on COL-4B and COL-3A like this. (first line) shiftOut(data, clock, MSBFIRST, 16); (second line) shiftOut(data, clock, MSBFIRST, 8);
    4. Set the latch pin High when your done sending bits.
  3.  Turn on COL-7B + COL-6B and COL-1A + COL-6A on layer-1.
    1.  Send current to the base of Q-2 to allow current to flow thru layer-1. (My code looks something like this. digitalWrite(layer1, HIGH)).
    2.  Set the latch pin LOW.
    3. COL-7B + COL-6B = 192 and COL-1A + COL-6A = 66. So in code you would do it like this. (first line) shiftOut(data, clock, MSBFIRST, 192); (secon line) shiftOut(data, clock, MSBFIRST, 66);
    4. Set the latch pin HIGH.

Here is the schematic.

Here is the code.
The code is well commented and maybe a bit overkill, but I wanted  it to be clear enough for even a beginner to understand and modify.

4 comments:

  1. I tried to download your code, but I got an error message. Could you possibly email me the Arduino code to goldeagle98201@yahoo.com? I, too, am an amateur and just learning Arduino code.

    ReplyDelete
  2. It's the best manual on revival a led cube. Your code will be very helpfull for everyone, and for me too. (dfedor54@gmail.com)

    ReplyDelete
  3. Could you send the code to me, too. I am a novice. But, I think I can handle this if I get the code. TIA
    Arnold

    ReplyDelete
  4. Oops. My EMail is arnoldbaker@lincolnxing.org. Thanks again.

    ReplyDelete