3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

LED Cube 8x8x8

Step 70Run the cube on an Arduino

Run the cube on an Arduino
«
  • IMG_6369.JPG
  • IMG_6370.JPG
  • IMG_6376.JPG
  • arduino_code.png

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.
 

« Previous StepDownload PDFView All StepsNext Step »
40 comments
Mar 30, 2012. 6:00 AMlhwong says:
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?
Feb 18, 2012. 1:44 PMTangoDelta says:
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.
Jan 27, 2012. 7:11 AMlscarmic says:
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.
Jan 31, 2012. 4:13 PMlscarmic says:
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.
Feb 2, 2012. 12:28 AMtriumphtotty says:
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.
Feb 2, 2012. 3:59 AMtriumphtotty says:
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!
Feb 2, 2012. 12:12 PMlscarmic says:
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.
Feb 2, 2012. 4:11 PMlscarmic says:
that did it! thanks triumphtotty.
Feb 2, 2012. 11:53 PMtriumphtotty says:
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?
Feb 3, 2012. 4:46 AMlscarmic says:
i certainly am! started the first layer last night. i might use this phase to play with making my own PCBs.
Jan 29, 2012. 1:15 AMcsalas200 says:
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!
Jan 17, 2012. 5:54 AMderuiter2 says:
hey, Thanx for all the help, almost done with the led cube. Just one more question. Do you need the sv1, sv2 and sv3 if you're working with the arduino?

If you need it can someone help me wat the sv1, sv2 and sv3 are?

Thanx already!
Jan 20, 2012. 3:27 AMtriumphtotty says:
SV3 connects the outputs from the transistors to each "layer" of the LED cube.  I suppose you could hard solder these, but having an 8-pin socket makes it easy to disconnect the whole cube from the multiplexer and AVR (or Arduino) for troubleshooting.  Or painting.  :o)

SV1 and SV2 connect the microcontroller to the multiplexer board
16 pins are used to provide:
(a) the latch address (3 pins)
(b) the latch data (8 pins)
(c) the latch enable (1 pin)
(d) the status LEDs (2 pins)
(e) the start switch (1 pin)
(f) a GND connection (1 pin)

See the steps from 30 to 37 in this Instructable for details on the multiplexer board and how it connects back to the microcontroller.
Jan 14, 2012. 7:13 PMalahamm says:
How can I upoad an EAGLE file? Thanks.
Jan 8, 2012. 1:37 PMalahamm says:
Hi Chr. My respects; I wish I were YOU!
I like the arduino part much more because I won´t need mo make the AVR board,but can we have all the animations as with a PC? Thanks.
P.S. Just a few details to finish the MUX board, but need some time.
Feb 20, 2011. 6:13 PMemihackr97 says:
Hi, I want to make one and use it with an arduino, but apparently it lacks 1 output,
since it has 14 digita I/O (Yes,14, including the pin 0) and 6 Analog I/digital O, which gives a total of 20 Digital Outputs, but u said it needs 21, despite that, you were ale to do it, but how???
Jan 7, 2012. 7:18 PMalahamm says:
iemihackr97, you only need 20; 8 for the DATA BUSS, 3 ADDRESS to select which latch is selected, 1 for Output Enable ( OE ) and to drive the Layers´transitors.
Oct 8, 2011. 3:51 PMmaewert says:
It seems people are confused as to how to add Arduino instead of using your microprocessor. As an attempt to help out I've shown what parts are no longer needed and I show how to hook up the arduino in its place:

Please let mw know if I misunderstood anything.

Best Wishes
Nov 24, 2011. 4:27 AMdrueki says:
Hi, do we still need to build the latch of it is connected to arduino?
Jan 7, 2012. 7:02 PMalahamm says:
Hi Drukei. You won´t need the AVR board becauase you´ll be using the Arduino´s AVR. You STILL need to build the multiplexer board.
If I got it straightthe coonections would be:

Do --- SV1-14 DIGITAL pin0 ( on the Arduino )goes to connector SV1 pin 14
D1 --- SV1-13
D2 --- SV1-12
D3 --- SV1-11
D4 --- SV1-10
D5 --- SV1-09
D6 --- SV1-08
D7 --- SV1-07 SV1 is the connector on the mux board

D8 --- SV1-03
D9 --- SV1-04
D10--- SV1-05
D11--- SV1-06

These drive the LAYERs transistors:

A0 ( Analog pin1 )
A1
A2
A3
A4
A5
D12 ( Digital pin12 )
D13
I don´t remember the orderright now; I think it´s Layer 1 to Layer 8, but i´m not going to risk having to type ALL this again. Check it out.
Nov 17, 2011. 5:35 PMecamarillo says:
hi i was trying to go to the link but just don´t open can you help me please thanks!
Oct 9, 2011. 12:41 AMDirkle says:
It's hard to tell from the resolution of your images, but what parts are no longer required when going with the Arduino implementation? Thanks!
Oct 10, 2011. 7:09 AMmaewert says:
This link may be useful to review the pictures using flicker at their original resolution:
http://www.flickr.com/photos/zaphod-bb/sets/72157627737041381/
Oct 10, 2011. 10:13 PMthe_burrito_master says:
Those pics are very help full thanks a lot i might build this after Christmas and you helped a ton.
Oct 9, 2011. 6:00 PMfromeout11 says:
I agree, a litte bit more clarification would be nice.

Another question: since chr says that this design will work more reliably with the 14.7456 MHz crystal, is there any way to remove the 16 MHz crystal supplied with the Duemilanove/Uno, and replace it with the 14?
Oct 10, 2011. 6:28 AMmaewert says:
I see no need to change your crystal on the Arduino. The 14.7456 Mhz crystal gives 'perfect' baud rates for serial communications. I've seen no problems communicating with the Arduino running at its 16 Mhz. If you *really* wanted to do it I think it would be possible, but you'd also have to make software changes since the frequency of the crystal is known to software and is used for the Delay and other timing functions.
Oct 10, 2011. 5:01 PM'earl says:
Well, being as thats how I would do it. And I dont understand what is what on the schematic, is there any chance you could make one and provide a detailed instructable for it? Its kind of a lot to ask but you would help tons of people. And you would have your own cube.

;D
Oct 10, 2011. 11:16 AMfromeout11 says:
Thanks for the reply, I'm glad there doesn't seem to be any problems.
Dec 29, 2011. 11:54 AMegon277 says:
Any recommendations on where to buy this and a part number? Thanks!
Dec 4, 2011. 12:36 AMylan12 says:
can i use this ?

http://www.ebay.com/itm/AVR-development-board-ATmega32A-mega32L-mega32-/140633496023?pt=BI_Electrical_Equipment_Tools&hash=item20be68d9d7
Nov 24, 2011. 4:37 AMdrueki says:
Hi there,
As inr0626 has asked,
Is the total IO needed when used with an arduino board is 20 or 21?
Thank you for you time
Sep 28, 2011. 3:19 AMfryddog says:
Hullo,
I cannot seem to download the .pde file. All I receive is a .tmp file that doesn't work. I found this same problem with another person's instructable. Putting the file into a .zip worked then.

Thanks in advance!
Oct 17, 2011. 1:49 PMTechNotes says:
Just rename the .tmp file to .hex or whatever it is supposed to be.
Sep 17, 2011. 4:34 AMSteel Chameleon says:
Hi,

You say that the data bus for the Arduino ( Digi Pins 0-7) corresponds to Port D on the Mega, did you not mean Port A on the Mega and Port D on the Arduino? Looks like a typo, Port D on the Mega looks like it's just used for the MAX232 and a few buttons which if im correct are not needed for the Arduino.

Thanks
Jan 2, 2011. 6:31 AMtigerbomb8 says:
where is the code
and it should work on the uno right
Sep 17, 2011. 4:29 AMSteel Chameleon says:
Posting late but the UNO and Duel use the same registers, check out both of the schematics at :

http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf

and

http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf
Jan 2, 2011. 6:22 PMtigerbomb8 says:
i looked at the data sheet and can not find a thing about registers
Sep 17, 2011. 3:20 AMSteel Chameleon says:
(removed by author or community request)
Aug 8, 2011. 4:16 PMVick Jr says:
Can you explain what the output enable (OE) for the latches does?

Also, for some reason I cannot download the pde.

Any idea on how to use a second 74HC138 or a shift-register to control the layers?

Thanks!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
651
Followers
7
Author:chr
I like microcontrollers and LEDs :D