Step 70Run 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| « Previous Step | Download PDFView All Steps | Next Step » |

































































































![Hard Wired LED Cube: [No Programming]](http://img.instructables.com/files/deriv/FTD/SF1T/GO8DC8KW/FTDSF1TGO8DC8KW.SQUARE.jpg)















Question: If you use an Arduino, do you still need the serial connection to a PC in order to do the fancy animations?
This is a great project, with mesmerizing results.
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.
#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?
If you need it can someone help me wat the sv1, sv2 and sv3 are?
Thanx already!
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.
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.
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???
Please let mw know if I misunderstood anything.
Best Wishes
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.
http://www.flickr.com/photos/zaphod-bb/sets/72157627737041381/
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?
;D
http://www.ebay.com/itm/AVR-development-board-ATmega32A-mega32L-mega32-/140633496023?pt=BI_Electrical_Equipment_Tools&hash=item20be68d9d7
As inr0626 has asked,
Is the total IO needed when used with an arduino board is 20 or 21?
Thank you for you time
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!
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
and it should work on the uno right
Should work on the Arduino Uno, but you have to check the data sheets to see if the ATmega on the Arduino Uno uses the same registers.
http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf
and
http://arduino.cc/en/uploads/Main/arduino-duemilanove-schematic.pdf
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!