LED Cube 8x8x8 by chr
Contest WinnerFeatured

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.
 

 
Remove these adsRemove these ads by Signing Up
1-40 of 64Next »
turbatu.andrei says: May 19, 2013. 9:13 AM
hello,

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?
rrussis82 says: May 1, 2013. 1:50 AM
how could I integrate an MSGEQ7 chip into this to make the cube respond to music?
SuperTech-IT says: Apr 29, 2013. 3:27 PM
I may have missed it, but what is the wire mapping for this ?
SuperTech-IT says: Apr 29, 2013. 3:52 PM
OOPS - it's right here:
http://www.instructables.com/id/Led-Cube-8x8x8/step70/Run-the-cube-on-an-Arduino/?&sort=ACTIVE&limit=40&offset=40#DISCUSS

Thanks Maewert
chewdog316 says: Apr 5, 2013. 10:08 AM
Has anyone built or knows where to buy cables to replace the jumpers?
Andre888 says: Mar 11, 2013. 11:38 AM
http://www.instructables.com/files/orig/FUE/5V3S/H94ZBLQ0/FUE5V3SH94ZBLQ0.txt
omid-el says: Apr 4, 2013. 4:01 AM
how i can change font and program it too eeprom memory?? for example (hello worled)
help me pls
omid-el says: Mar 31, 2013. 12:33 PM
so havev can we programm the atmega please help.
SuperTech-IT says: Apr 2, 2013. 11:05 AM
I have to wonder how well a VIC-20 or Commodore 64 might be able to do something like this. Since the keyboard input can be redefined as output, and there's another 8 lines on the user port, we could do without the 74138 because we'd have 8 lines X 8 lines X 8 lines. If it was done in machine code, we might be able to pull it off, I may try it since I still have a VIC-20.
abuchard says: Feb 17, 2013. 11:50 AM
bonjour
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
tarPancake says: May 22, 2011. 11:58 PM
does anyone have the ripples, fireworks, or the sidewaves functions ported to pde yet? thanks in advance.
wcjcs says: Feb 6, 2013. 8:06 PM
I posted a comment at the top of the thread. There is a function you can copy into your sketch. If achieves the effect, but its laggy due to all the math. Good luck.
wcjcs says: Feb 6, 2013. 8:04 PM
This is the sine wave ripple effect all in one easy function that you can copy into your Arduino sketch and then call in your main loop. Note that this effect will run on an Arduino Uno, however, with the sheer number of complicated mathematical calculations involved, the Arduino chokes on it. I'm guessing here, but that seems logical. Anyway, I've stripped everything out, removing extra function calls, avoiding assigning temp vars, and even doing some math (as much as possible) ahead of time. In spite of this, the animation still lags. All the same, now you have something you can hack at. If you improve the performance, please post the code back. Also note that it takes 300+ iterations to create a full cycle of the animation, so give it a much larger number to keep the animation running longer. The delay argument isn't useful as written; even when it is set to 0, the animation still lags. You can port the other animations in the same way. Good luck.

/*
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);
}
}
rex19 says: Jan 29, 2013. 9:33 PM
Will this work on a arduino with atmega328? help me pls.
zstryker says: Jan 13, 2013. 10:11 PM
Will this work on a Raspberry Pi?
mattbowes191 says: Dec 31, 2012. 5:29 AM
Hi, I'm new to Instructables, but the arduinocube.pde download link seems to be broken. Can anyone advise if it is or whether it's just me? It looks like it's referring to a .tmp file rather than the correct file?
Akardo1502 says: Nov 25, 2012. 9:59 AM
Can you take the programmed microcontroller on arduino (ATmega328) and place it where the ATmega32 was?? Would it still work??
ofniedan says: Jan 13, 2011. 10:34 AM
Great project, chr!
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.
chr (author) says: Jan 17, 2011. 11:53 AM
You can use a 3-to-8 encoder to control the layer transistors. That would free up 5 IO lines.
fromeout11 says: Nov 19, 2012. 1:14 PM
Wouldn't this prohibit enabling more than one layer at a time?
froggyman says: Nov 24, 2012. 12:46 PM
Yes. But you don't want to light up more than one layer at a time anyways. The resistors aren't rated to have more than 1 LEDs on at time, and the the latches are not going to be happy if you start drawing too much current.

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.
patyork says: Nov 7, 2012. 10:43 PM
Just a thought: You're using 8 lines to select the correct layer; could a 3x8 decoder not accomplish the same thing? Still waiting on parts, but this is how I have mine designed at the moment.
arighi1 says: Nov 5, 2012. 12:54 PM
hey guys, hope y r doing well I have this problem, I have a arduino softwar mega and I changed port L by the port D and I sent it to arduino uno it function normaly but there is a lign it has to be One led light, but the hall cube light, and am sure the problem is in the program Please help am waiting ^_^
imagenotes.jpg
victinho says: Oct 23, 2012. 4:28 AM
preciso se possivel dos ajustes para o codigo usando o arduino mega 2560 alguem pode me dar um forcinha por gentileza?
chobostyle says: Oct 5, 2012. 2:21 PM
Has someone got the Source Code or the needed adjustments for use with Arduino MEGA 2560 (r3) ?
froibo says: Sep 11, 2012. 9:17 PM
So I hooked up the cube to my Arduino with this code and all I got was crazy gibberish.

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.
Pog49 says: Aug 16, 2012. 1:37 PM
Hey Everybody!

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 :/
shredape says: Jul 24, 2012. 11:52 AM
It's alive! After many hours of tinkering and building I finally got the lattice to light up, with spectacular results. I am using an Arduino UNO as the programmer and power source to my cuber, but I'm not able to really understand the code even though it works out great. My question is, can anyone post a tutorial on how to program this cube? I'm very interested in creating my own animations but I do not know how, because I'm a novice when it comes to coding. Will anyone help me with this last step of the best lighting project?!
lscarmic says: Jan 27, 2012. 7:11 AM
Ok. Here I am again. If someone gets a sec, can you double check my R values? I don't really think that would be causing my problems but I wanted to double check anyways. I'm ok with the LED and pull-up values. It's the Rb values I'm not 100% on.

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.
6770903469_bcf536b734.jpg
lscarmic says: Jan 31, 2012. 4:13 PM
well for anyone watching, i completely replaced the latch for row 0 (the one misbehaving). i actually wired over to a new latch on a breadboard complete with separate Vcc and GND (from the same power supply) and new resistors. unfortunately, still have the same result.

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.
triumphtotty says: Feb 2, 2012. 12:28 AM
Did you check the logic for the latch OE pin? Chr uses the fact it rolls over from 0x07 to 0x08 (0111 to 1000) to trigger the change on latch zero. The 136 chip has inverted outputs. I'm in a hurry (work in 5 mins), but will check this out later and get back to you.
triumphtotty says: Feb 2, 2012. 3:59 AM
It's not the OE pin. In main.h find the lines:
#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!
lscarmic says: Feb 2, 2012. 12:12 PM
awesome! after your first suggestion i started my Microsoft Logic Analyzer (Excel spreadsheet) to start tracing it through bit by bit. i could see there was an issue on PORTB in that i never had a 000 on my latch address bits (bits 0-2 on PORTB). just wasn't sure what to do about 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.
lscarmic says: Feb 2, 2012. 4:11 PM
that did it! thanks triumphtotty.
triumphtotty says: Feb 2, 2012. 11:53 PM
Excellent!! :o) If you wanted to make the code portable, I suppose that
#define LATCH_MASK (CUBE_SIZE-1)
and
#define LATCH_MASK_INV ~LATCH_MASK
would work nicely.  The preprocessor will replace these with constants when compiling, so there's no code size overhead.

Glad it's working now.  Are you going to start on the 8x8x8?
lscarmic says: Feb 3, 2012. 4:46 AM
i certainly am! started the first layer last night. i might use this phase to play with making my own PCBs.
shenn164 says: Jun 13, 2012. 7:07 AM
Can you share the changes you made i'm trying to do the same project but i'm confused on to simplify the circuit. thanks
lhwong says: Mar 30, 2012. 6:00 AM
I'll add my thanks for this great project!

Question: If you use an Arduino, do you still need the serial connection to a PC in order to do the fancy animations?
TangoDelta says: Feb 18, 2012. 1:44 PM
In the last weeks I spent a couple of hours here and there on this project, and tonight I reached the stage where I could hook it op to my Arduino Uno, and it works a charm! I was kinda nervous, I couldn't find the 2n2222's, so I used others, and I had to replace some things here and there, also my wiring's a mess, but it works!

This is a great project, with mesmerizing results.
csalas200 says: Jan 29, 2012. 1:15 AM
Hi. Chr you are amazing guy, your guide is the most complete all over the web and I've just completed this instructable with not at all any problems and it's running on arduino Duemilanove with the code that you provided. The effects are amazing. Is there any possibility to post any other animations? Thanks again for sharing this with us!
1-40 of 64Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!