4x4x4 LED cube upgrade with Shift Registers (74hc595)

This project started out with a bag of LEDs that I had removed from flashlights, to convert to UV flashlights. I knew I would find something fun to use them with, but It was months before I figured out what to do with them. When I saw an LED cube on youtube, I knew what to do.

I had about 70 LEDs, and an arduino. I wanted to build the cube with stuff that I already had, and using as little new stuff as possible. I built my using 64 LEDs, and 4 resistors and I would have used bus wire, but I didnt have any, so I used galvanized steel wire from the hardware store (baling wire?). I had to use wire to connect the LEDs, since had been clipped to about 1/8" lead length. To connect the LEDs to the arduino, I used an old IDE cable, because its so convenient for transferring parallel data. I was going to need 20 wires, so one ribbon cable keeps things tidy, and easy to trace. I did this project on a holiday weekend, and I wasnt able to acquire a SIP header, but I was able to make due with a couple paper clips, straightened, and clipped to about 1/2".

I had some problems finding software that would work, because I made my cube common anode, Instead of common cathode (I was thinking of only using 4 resistors, and thought they should be on the positive side, not the negative side...) Since my cube was made up of 4 layers of 16 columns, I used 4 220ohm resistors on the plane pins instead of 16 resistors on the column pins. I figured I could always change the code, but that turned out more challenging than I had anticipated. I have since revised my cube to use 16 100 ohm resistors, instead of the 4 220s, and It is much more evenly lit.

It should also be noted, that the LEDs that I used were in circuits with 3 batteries, they seem to run at about 4.5v. When re-using IDE cable, every other wire is one side of the connector, so if you only use one side (like Im doing), you only use every other wire, this also turned out to be quite handy when hooking up 2 8-bit shift registers.

This worked great, but it used all the pins on my arduino, and I wanted to try to add things, things that will need some of those precious pins. The arduino had some nice programs for using shift registers (74HC595s specifically), so that is what I used.

There are many examples of using LED cubes, so I wont go over that part, this is about converting the cube from parallel to serial using shift registers. With the new code, and use of shift registers, you can expand this cube to virtually any size, you can also add features (buttons, knobs, sounds, sensors, motors,...)

This project needs:

1 4x4x4(64) LED cube, assembled, and working.
2 74HC595 Shift Registers.
1 IDE cable
9 SIP header pins.
Arduino + USB cable + computer to program.
1 USB cell phone charger (to power the cube when not hooked up to the computer.)
You will  also want some kind of container, or board to mount your project.

Soldering iron/solder/flux/alcohol (Soldering and cleanup)
Tweezers, Pliers, Diagonal nose cutters, knife (for wire and chip prep)
Remove these adsRemove these ads by Signing Up
WWC2 years ago
On both of your shift register codes they say for Common Anode. Was one supposes to be for Common Cathode?
HippyNerd (author)  WWC2 years ago
Good catch! I had edited the code, but not the comment at the top. I have changed that in the instructable, and my copy of the code.

Thank you for your help.

P.S. A better way to deal with the common anode/cathode would have been to put a flag that the user selects, or have 2 lines, one of which gets commented.
Reading the common cathode code, I cannot find which are the arduino pins to connect the registers. Are the 16 columns supposed to be conected directly on the arduino? I do not see the clock and latch, nor DS out, can anyone help me?
HippyNerd (author)  Igan.Schacht1 month ago
There are many ways that you can build this cube. This cube started out like you mention, with 16 columns that are each connected to an arduino pin. This instructable is about converting that LED cube to use 2 shift registers instead of 16 pins on the microcontroller.
Its been a couple years since I worked on this cube, so I have to go by my comments in the code, lets hope they are correct:
int dataPin = 7; //Data I added these for Shift Register
int clockPin = 12; // Clock
int latchPin = 13; // Latch

I'm using common cathode version, so the first time I've misread and use the original code (from page 10) instead from the CC one (from page 12, the last page). Also, I'm using Arduino Leonardo, but however is very very very similar to Arduino UNO.

But when I try to compile the last code I get this error:

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

Arduino: 1.0.6 (Windows 7), Board: "Arduino Leonardo"

sketch_nov20a.ino: In function 'void setup()':

sketch_nov20a:237: error: expected `;' before 'pinMode'

sketch_nov20a:237: error: expected `)' before ';' token

sketch_nov20a.ino: At global scope:

sketch_nov20a:239: error: expected declaration before '}' token

I guess that is related to grammar inherent to C/Processing language, but this is my very first time using Arduino and programming, so I dunno how to fix it :\

Thanks in advice.

(Also pardon me if my english is a bit poor, is not my native language)

Ok I've misreading, but the real code does not compile :c

HippyNerd (author)  Igan.Schacht1 month ago
I have no idea why you are having trouble, Its pretty hard to say from here.
Robo-T made it!10 months ago

Good write up. I built the cube with common cathode for each layer. I ran your code, but it really only ran 2 dimensionally. If any bit on the column is on than the whole column is on. doesn't seem to be turning on and off each layer. I believe I wired it correctly and if disconnect one of the layers it doesn't work. Is your code turning off each layer before turning on the next? Thanks, for your work.

Robo-T Robo-T10 months ago

OK, I found the issue in the code. The two "HIGH" settings below (about halfway through the void loop) should
be set to "LOW", then it will work with common Cathode configuration.
digitalWrite( PlanePin[CUBESIZE-1], HIGH );
} else {
digitalWrite( PlanePin[plane-1], HIGH );

HippyNerd (author)  Robo-T10 months ago
Is it possible you built the common anode version? Do your LEDs light up the opposite of what you might expect?
I havnt worked on that cube in over a year, and I cant remember the details as well as I did when I built it.
The primary difference between the common anode and common cathode versions are the lines you mention, and the data, the data is the opposite (1s where it should be a 0).

Someday I may have to build both cubes and test the software.

If you can send me a copy of your working code, I can compare it and edit mine, but I need to build another cube to test it.
Robo-T HippyNerd10 months ago

Mine is common cathode. However, I did sink mine using NPN transistors, so that may affect the outcome. It is working well now. I added some other binary data from other sources for a longer show. I also added a little rain routine, but need to make it a little more complicated to make it look good. Have some other ideas for the code and may go with a whole different approach.

HippyNerd (author)  Robo-T10 months ago

It sounds like maybe you should write up an instructable too!
There are many ways to build this cube, the first way that I built it was nice because it used few parts. You could add a bunch of transistors to this cube to make it nicer on the microcontroller.
Transistors are awesome. I have a 4 x 4 x4 RGB cube that only uses 20 NPNs and 20 resistors and an arduino.
Would you be interested in sharing your code? I would like to try the new data on my cube. Also seriously consider writing something up showing how you did things differently, that would be awesome.

Robo-T HippyNerd10 months ago

Of course I will share any changes to code or my own code, but I need to clean it up a bit. Some of the operations need to be placed in functions. It will make the code easier to understand, manipulate and add-on to. I will let you know.

dwhacks1 year ago
Is your common cathode version not finished? the code doesnt compile, seems to have a few missing parts!
HippyNerd (author)  dwhacks1 year ago
Hrm. I wonder what the problem could be. If I remember correctly, i built a common cathode cube, and thats what I ran my code on.
I havnt messed with that cube in about a year, so my memory isnt too fresh on the details.
Check it out at the begining, the "#include // allows use of PROGMEM to store patterns in flash"
Missing part there,
and a few other places. I compared it to your other code and fixed it.
HippyNerd (author)  dwhacks1 year ago
Ah, yes, now I see the include line that didnt include the file to include.
I edited that one line of the CC code, please try it, and let me know if it works. I dont have a CC cube to test it on myself. It turns out my cube was CA.
WWC2 years ago
Do you have an actual schematic for the 4x4x4 cube with shift registers.
I have a 4x4x4 cube and was wanting to convert it to running with shift registers.

HippyNerd (author)  WWC2 years ago
(removed by author or community request)
WWC HippyNerd2 years ago
OK Thanks
HippyNerd (author)  WWC2 years ago
I did not make a schematic. The way the shift registers are wired, is exactly the way used in the arduino shiftout tutorial with 2 cascaded shift registers.
In step 7, there is a link to a webpage about using shift registers, use those fritzing images for reference.
Pins 1-7 are output, Pin 8(gnd) and 13(OE) are connected to ground, pins 16 (+5v), and 10(SRCLR) should be connected to +5v. The data (pin 14)from the second chip connects to the the first chips pin 9. The rest of the pins should connect to an arduino, or to a resistor/LED. I may be able to make a schematic, but that may take some time to get done.