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 68Next »
the seaker says: Jan 7, 2011. 5:59 PM
This is by far the best instructable on here! the one question i have for you though is if you could possibly give me more information on what i could leave out in order to use the Arduino? i would love to build this but i would like to have a better idea of what i need to do to make it especially for the Arduino
chr (author) in reply to the seakerJan 10, 2011. 9:20 AM
You can leave out the entire AVR board except the transistors.
SuperTech-IT in reply to chrJun 16, 2013. 7:58 AM
Or you can do what I did, and move the transistors to your LED Driver board.
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).
Driver-Board.jpg
omid-el in reply to chrMay 30, 2013. 9:37 PM
hi,i've made my big cube(8*8*8) and it has some problems
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
20130524_172531.jpg20130521_120555.jpgIMG_20130523_183423.jpg20130523_183249.jpg
SuperTech-IT says: Jun 16, 2013. 7:49 AM
Nobody seemed to pick up on this, but 8+8+3+1 = 20 lines, not 21 - which is a good thing because the arduino actually only has the 20 lines. A0 to A5 = 6 lines, and D0 to D13 = 14 lines...and 14 + 6 = 20. This hit me as I was getting ready to hook up the Arduino to my driver board, and wiring the driver board to the I/O connector. It's all good though and since the hookup instructions all work, it's not even a big deal. I just thought I'd point it out in case anyone else was scratching their heads.
SuperTech-IT in reply to SuperTech-ITJun 16, 2013. 7:50 AM
Maybe they included the 5V or the GND as the 21st line...
Morpheous87 says: May 23, 2013. 5:51 AM
Hi, it it possible to get from somewhere the eagle schematic file - .sch for the controller board (not the one with the MCU), so it will be easier to design a PCB for it. It will be much easier to solder. Thanks
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 in reply to SuperTech-ITApr 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 in reply to Andre888Apr 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 in reply to Andre888Mar 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 in reply to tarPancakeFeb 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) in reply to ofniedanJan 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 in reply to chrNov 19, 2012. 1:14 PM
Wouldn't this prohibit enabling more than one layer at a time?
froggyman in reply to fromeout11Nov 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 in reply to lscarmicJan 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 in reply to lscarmicFeb 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 in reply to triumphtottyFeb 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 in reply to triumphtottyFeb 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.
1-40 of 68Next »
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!