Understanding the 4x4x4 LED cube code

Hello,

I have built myself a 4x4x4 led cube and I want to control it using my Arduino Uno. I have seen a lot of people not using transistors while they still light up the entire cube. This guy says that you can ditch the transistors because you will only be lighting up one layer at a time, but at about 10mA per LED you would still blow the c*** out of you microcontroller! I wonder if it has something to do with this code everyone is using:

https://dl.dropboxusercontent.com/u/21892130/121118%20-%20LED%20Cube/LED_cube_4x4x4/LED_cube_4x4x4.ino

Could it be that this lets you light up only one LED at a time and multiplex that very fast? If not, how can everybody get away by not using transistors and still have a nice bright fully lit cube?

Best regards,

Polo9n

Hi, that code appears to use a 1:4 multiplex strategy. One layer at a time is lit, ie. up to 16 leds. If the series resistors have been chosen to allow 10mA per led and all 16 were lit then 160mA would be drawn from a single Arduino pin. However, ths current would be drawn for only 25% of the time, so the average would be 40mA. Maybe this is why the cube’s designer believes this is a safe approach. My understanding is that this could shorten its life and possibly cause instantaneous failure. I have never risked an Arduino to find out.

It may be that the patterns chosen never exceed 4 leds switched on per layer, resulting in a max current of 40mA per pin and an average of 10mA.

Paul

It does do one layer at a time!, interesting. So the thing is, each column has a common annode with their own current limiting resistor and four different grounds. So for one layer 16 outputs would supply 10mA each. But only one output would sink 160mA! I think it will be a good idea to use some transistors for the current sinking of each ground connection. Will something like a 2n2222 do the trick? And would it be a good idea to drop the current through the LED's a bit more? There is one pattern in the code (the line with all the 11111's in it) that will drive all the LED's in a layer at once but that is only for 10ms i believe.

Thanks for your help!

Best regards,

Polo9n

Yes I think 2n2222 would be ok, or bc337. Put 2K2 between its base and the Arduino output.

The 10mA per led should be ok even with all leds on.

The transistors will invert the logic for the cathodes, so change the sketch to make the cathode control outputs HIGH to switch a layer on and LOW for off.

Ok, I have some BC337’s laying around.
But I only have 2K Ohm resistors do they work as well?
What should i change in this sketch?

https://dl.dropboxusercontent.com/u/21892130/121118%20-%20LED%20Cube/LED_cube_4x4x4/LED_cube_4x4x4.ino

Just change the digitalWrite to High in the code below or should i change more things?

// turn current plane on
digitalWrite( PlanePin[plane], LOW );
// delay PLANETIME us
delayMicroseconds( PLANETIME );
} // for plane
} // while <EndTime
} while (DisplayTime > 0); // read patterns until time=0 which signals end
}

Best regards,

Polo9n

2K will be ok for the base resistors. If you have 4K7 try that it may work just as well, and use a little less current.

Swapping HIGH & LOW for the plane pins should be the only change needed.

polo9n - this thread regarding that code might be of some minor interest to you

http://forum.arduino.cc/index.php?topic=193436.0

Hello,

I have received almost all components. :sunglasses: Because I am building my cube on perfboard, I am going to use a standalone ATMEGA328P. I would like to program it with my USBTinyISP. I read somewhere that you cant drive low impedance loads with the ICSP pins. Because I need all the I/O pins I have to use the ICSP pins to drive LEDs. Am I going to be in trouble trying to program my ATMEGA while the LEDs are attached?

Best regards,

Polo9n

Some suggestions to think about:

Use an ic socket for the atmega. Program it on breadboard, then transfer it to the socket.

Put some jumper headers on the ics pins so you can remove the jumpers for programming.

Use the ics pins to drive the transistors controlling the cube layers. This will make them higher impedance and you may get away with programming like that. Test this theory on breadboard first.

Paul

If I was going to make a 4 by 4 by 4 LED cube (which I just might), I would simply use a MAX7219.

All control problems completely solved! Just focus on the resultant simplified code.