Step 70: Run the cube on an Arduino
Since we published our last LED Cube instructable, we have gotten a lot of questions from people wondering if they could use an Arduino to control the cube.
This time, we are one step ahead of you on the "Can i use an arduino?" front :D
The IO requirements for an 8x8x8 LED cube is:
- Layer select: 8
- Data bus for latches: 8
- Address bus for latches: 3
- Output enable (OE) for latches: 1
Total: 21
The Arduino has 13 GPIO pins and 8 analog inputs, which can also be used as GPIO. This gives you a total of 21 IO lines, exactly the amount of IO needed to run the LED cube!
But why write about it when we could just show you?
We hooked the cube up to an Arduino and ported some of the software.
Since the multiplexer array and AVR board are separated by a ribbon cable, connecting the IO lines to an Arduino is a simple matter of connecting some breadboard wires. Luckily, we soldered in a female 0.1" pin header for the transistor lines when we were debugging the first set of transistors. Just remove the ATmega and connect wires from the Arduino to these pin headers.
We connected the cube like this: DATA bus: Digital pins 0-7. This corresponds to PORTD on the ATmega328 on the Arduino board, so we can use direct port access instead of Arduinos digitalWrite (which is slow). Address bus: Digital pins 8-10. This corresponds to PORTB bit 0-2. On this we HAVE to use direct port access. Arduinos digitalWrite wouldn't work with this, because you can't set multiple pins simultaneously. If the address pins are not set at the exact same time, the output of the 74HC138 would trigger the wrong latches. Output Enable: Digital pin 11. Layer transistors: Analog pins 0-5 and digital pins 12 and 13.
We had to go a bit outside the scope of the Arduino platform. The intention of Arduino is to use digitalWrite() for IO port access, to make the code portable and some other reasons. We had to sidestep that and access the ports directly. In addition to that, we had to use one of the timers for the interrupt routine.
The registers for the interrupt and timers are different on different AVR models, so the code may not be portable between different versions of the Arduino board.
The code for our quick Arduino hack is attached.
arduinocube.pde12 KB
Remove these ads by
Signing Up











































































































Visit Our Store »
Go Pro Today »




This allows me to use any other microcontroller - but of course you have to write the code for it. 26 pin connectors and cables are very common, so this gives you enough for the 8 data, 8 layer select, 3 column (address) select and 1 output enable lines (20 pins total) with room left over for power and ground (input or output).
how can i amplify it by 12v or output layer selection?
think problem is about layer selection .and i use tip122 for 8 layer.
please help
I just finished putting all the parts together and hooked up the cube to an atmega328 and something seems to be off. when I upload the sketch all the led's light up and they stay lit and nothing else happens. did anyone else stumble upon this problem?
http://www.instructables.com/id/Led-Cube-8x8x8/step70/Run-the-cube-on-an-Arduino/?&sort=ACTIVE&limit=40&offset=40#DISCUSS
Thanks Maewert
help me pls
j' ai construit le cube , je le pilote avec arduino uno
le problème est que j' ai " ROW1, ROW2, ROW3" qui reste allumé donc j' ai 192 leds
qui ne s' animes pas
pourriez vous me donner quelques conseils
merci
/*
Sine wave animation for 8x8x8 LED cube running Arduino Uno
John Alarcon, 2013.
*/
void ripples (int iterations, int delay)
{
// Remember, it takes 300+ for just a couple seconds of animation...
for (int i=0; i // Iterate through x and y.
for (int x=0; x<8; x++) {
for (int y=0; y<8; y++) {
// Light LED at x,y at the correct height.
setvoxel(x, y, (int)((4+sin(sqrt((3.5-x)*(3.5-x)+(3.5-y)*(3.5-y)) / 1.3 + (float)i/50) * 4)));
}
}
// This would normally be used to slow the animation but, well, the animation
// can't really get any slower than it already is, so, yea.
delay_ms(delay);
// Clear the cube to ready it for the next iteration.
fill(0x00);
}
}
Would using an Arduino allow for streaming effects from the pc via USB?
I noticed that the Arduino uses digital pins 0 and 1 (PORTD) also for tx and rx, i.e. serial communication via the USB port. I guess this could complicate things, I'd appreciate your insights on this.
The idea is to scan through each layer, one at a time, with a high refresh rate so it appears as if multiple LEDs are on at the same time.
To try and get a handle on the problem I changed the loop code to alternate the lights as all on to all off every other second using the fill function. Well it worked, only it was inverted. The lights were all on when they should have been off and vise versa.
I am a bit lost as how to interpret this.
The only thing I could think of is that I am using an Uno SMD edition and perhapse the interupt and timers are different from the intentions in the code as the guide mentions. I'm clueless to the deeply technical aspects of Aurdino, so any insight would be greatly appreciated.
Just wondering about power. Is the Arduino capable of running the LED cube without building/buying the external PSU mentioned in an earlier step? I assume not but just wondering if anybody could help me out.
@maewert, thanks for your images (in a comment below), they help alot but I don't see connections running from the PSU and I am assuming it is necessary to simply connect the PSU VCC/GND to the appropriate arrows.
Also, just to be clear - Which circuits actually need to be built if I'm using the Arduino instead of the ATmega32 microcontroller? I would prefer not to buy components that I won't use.
Hope somebody understands my query :/
Again, my problem is that the entire row 0 plane is always on (that is, the 16 voxels from 0,0,0 to 3,0,3). For a test, I loaded the effect_planboing function just to see what would happen and same thing, the XZ planes along the Y axis for row 1, 2 and 3 work fine, but the row 0 plane just stays full on.
I tested solder joints per triumphtotty's suggestions but didn't find anything alarming.
I'm at a loss. Here's a link to the larger images: http://flic.kr/p/bjjDGZ
As always, thanks for your help.
lsc
by the way, i realize this is a 4x4x4 question on the 8x8x8 instructable. however, since i'm using the same method as the 8x8x8 i thought it was appropriate.
my only thought at this point is to go back to the code (posted in the next step). can anyone think of why there would be a problem running a 4x4x4 cube by simply scaling down the 8x8x8 code?
thanks again.
#define LATCH_MASK 0x07
#define LATCH_MASK_INV 0xf8
and change these to:
#define LATCH_MASK 0x03
#define LATCH_MASK_INV 0xfc
These are actually used for the latch address bits. The latch loop runs from 0 to 3, but the output is from 1 to 4. If you AND 4 with 0x03 you get 0x00, but if you AND it with 0x07, you will get 0x04, which means your latch 0 never gets to see the data. Hopefully that'll fix it!
changing to 0x03 and 0xfc i can see it the effect and it makes perfect sense.
thanks again for helping though this. i'll try it tonight and report back. i'll also make a note on the code i posted in step 71 for future reference.