loading
Picture of 4x4x4 LED cube upgrade with Shift Registers (74hc595)
IMG_20120917_182057.jpg
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.

Tools:
Soldering iron/solder/flux/alcohol (Soldering and cleanup)
Tweezers, Pliers, Diagonal nose cutters, knife (for wire and chip prep)
 
Igan9 months ago
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?
Igan Igan9 months ago

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

RobertLu Igan7 months ago

Ian, you are correct, the posted code on page 12 is wrong on several lines.

In fact each line that contained a '<' is truncated and joined with next line.

Use the code on page 11 looks OK, but the missing formatting (indentation) makes it hard to read.

@HippyNerd: to support your audience you perhaps post the code in a zip file, so the formatting is maintained and no copy-paste errors do occur.

HippyNerd (author)  RobertLu7 months ago

Yeah, I've been noticing that formatting gets ugly when pasting code. I think that if I attach a file, it doenst have to be compressed plain text should keep its formatting. I will have to repair the cube before I can test any software though :(

Igan HippyNerd7 months ago

Somehow, I managed to repair the code:

Going thru forums, I found some old code of you. I used it as a guide to change and delete some lines.

But now, I've formatted my pc so I need to search beneath my backups the code. I guess tomorrow or so I'll upload it if I can.

HippyNerd (author)  Igan7 months ago

This code is pretty hacked up, It was kinda hacked up when I got it, and then I did terrible things to it. Its amazing that it works!
This cube design lacks transistors for the planes, which means that the plane pins on the microcontroller are going to take a pretty high load (upto 16 LEDs at one time). I think I also later modified my cube to have resistors on the 16 LED leads.
Honestly, If I was building this cube now, I would use resistors on all 16 LED leads, and transistors on the plan pins. Cleaning the code up would be real helpful too. Making a program to do patterns would be a big benefit also.

Igan HippyNerd7 months ago

Well, I've found the modified code that I used insert in one of my reports to the university as a plain text.

https://www.mediafire.com/?02lpgwkvg1z4uay

I can't test it right now because I borrowed the ICs from the faculty :\ But should work.

Also, there is a pretty page that does patterns in a graphical mode for the cube.

http://www.robota.nl/en/blog/led-cube-4x4x4-patter...

And finally, a video of mi cube working using the modified code and the demo pattern of the last web.

http://www.dailymotion.com/video/k2qpnoNiwjAlDF9rv...

HippyNerd (author)  Igan7 months ago

This is great Igan. I think that you make an instructable with all your improvements. You can use my pictures, code, whatever you need to make it easier or better.

You (all) should not build this without the 16 current limiting resistors; otherwise the current will be
uncontrolled high and will overstress the capabilities of the AVR I/O
pin, and that of each LED. There is no real need to use 16 transistors on the data pins because each sinks or sources only one LED at a time; the AVR I/O pin can handle up to 20mA, although the combined current (16x20=320mA) is a bit much for the AVR common power pins. On the 4 planes you must use transistors because it can sink or source the current of up to 16 LEDs at a time.

The resistors have to be calculated such that the LED current is not more than 20mA. For the High intensity LEDs you may calculate for 1 or 5 mA each, unless blinding the audience is intentional.

HippyNerd (author)  RobertLu7 months ago

I would use 4 transistors, one for each plane pin.
the resistor value, and the current would depend on the LED. most 5mm are 20mA, but you should check the LEDs you are using.
Another option would be to run the LEDs with bigger resistors, so that the plane pins are under 40mA.

Igan HippyNerd7 months ago

This was my current scheme (I finished this project on the early December).

I guess that some connections on the ICs are a bit unclear but still is undertandsable. The real cube worked 100% perfect.

led cube scheme.jpg
HippyNerd (author)  Igan7 months ago

That looks real good, although it would be better to put resistors between the LEDs and shift registers *(value would vary, depending on he LEDs used.)

It looks like the shift registers also need 5v and gnd.

RobertLu RobertLu7 months ago

I missed something here: the 16 databits are not on the AVR but on two 8-bit shift registers. When using 74HC or 74HCT series, the LED current shall be below 5mA each, and the resistors shall be calculated accordingly.

HippyNerd (author)  RobertLu7 months ago

Yeah, the original cube that I built was run directly from the microcontroller. the whole point of this instructable was converting it to use shift registers instead, to free up I/O for other things.

HippyNerd (author)  Igan9 months ago
I have no idea why you are having trouble, Its pretty hard to say from here.
HippyNerd (author)  Igan9 months 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
Igan HippyNerd9 months ago

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:

http://i.imgur.com/oKWZ5Tm.png

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)

Robo-T made it!1 year 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.

IMG_7063s.JPGIMG_7062s.JPG
Robo-T Robo-T1 year 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-T1 year 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.

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-T1 year 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.

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
Hi
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.

Thanks
W
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.
WWC2 years ago
Hi
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.