LED 7x7x7 Cube & Effects Generator

Discussion in 'The Completed Projects Collection' started by mhutchie1, Jan 21, 2013.

  1. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    I recently finished constructing and programming a 7x7x7 Blue LED Cube, so I thought I'd share a brief overview of the Cube itself. Please ask any questions if you are interested in making a cube, hopefully I can help you out.

    [​IMG]

    Parts List:
    • 343x Blue LED’s
    • 49x 470 Ohm Resistors
    • 7x 2N2222AG Transistors
    • Approximately 30m of 0.9mm galvanised steel wire
    • 1x Arduino Mega 2560

    Equipment Used:
    • Soldering Iron
    • Heatsink
    • Pliers
    • Multimeter
    • Vice

    Software Used:
    • Arduino Development Platform
    • Processing (Used to design the frames & effects)

    The cube is able to process 142 frames per second, that is, 1 frame every 7 milliseconds. Within this time period, it loops through a still frame 7 times (Each cycle of POV lasts 144 microseconds). This is able to compensate for flickering during video recording, allowing all camera’s to record fluid video without distortion.

    The cube itself is controlled with an Arduino Mega 2560. For each frame in memory, the Arduino reads and bit shifts 49 bytes of data for an encoded duration. This allows for the cube to be applied to a variety of purposes, from text display to effects to music visualization.

    https://www.youtube.com/watch?v=CKCjsbNEUUE

    The frames were generated through complex Processing scripts, allowing for a multitude of operations such as shifting in any direction (seen in the rain effect), and an edge shift (seen in the scrolling text around the outside of the cube). These scripts were used to perform the basis of calculations for fireworks, as well as sine waves in 1, 2 & 3 dimensions (seen in the video).

    [​IMG]

    In this cube the supporting structure was made 0.9 mm galvanized steel wire, straightened by stretching the wire. The 5mm Blue LED’s are positioned 30mm apart, with the anodes being attached to the verticals (white wires in the image above) & the cathodes are attached to the horizontal layers (green wires in the image above – bottom right – shown passing through NPN transistors). The Arduino Mega 2560 R3 is positioned on a suspended platform, with the anodes controlled on the Digital Pins as opposed to the cathodes on remapped Analog Inputs.

    As the cube is divided into layers (shown in the schematics) I made a template with drill pressed holes that I could fit the 49 LED's in with a spacing of 30mm while soldering the layer. By using a template, the LED's were aligned consistently. On the wooden template, I attached several lugs that allowed me to position the structural layers consistently and accurately. Soldering the layers took me approximately 6 hours, as all of the LED's legs need to be bent to attach to the structure.

    I then made a jig out of foam that allowed me to join the first two layers. Layers are joined by soldering vertical straight pieces of galvanised wire to the anodes of the LED's. Once I had done two layers, I shifted the jig up a layer, and mounted the next layer until I had joined all seven layers.

    [​IMG]

    The vertical wires (49 of them) attach to the Arduino on Digital Pins 0-48 directly, shown in the above schematic. At this stage, you essentially have a 2D display with 49 pixels.

    To add the third dimension, a small circuit is required (shown below), which uses seven transistors (one for each layer) to connect the cathodes to ground in sequence, so a 1 pixel resolution is the result. This could be done through an IC, however I opted for a small prototyping board, which has seven transistors (I used 2N2222AG - High Speed). The emitters of these transistors are wired to a common ground on the Arduino Mega 2560, each collector is connected to one of the layers, and then the base's are connected to the Arduino's Analog Pins A0-A6.

    [​IMG]

    Please feel free to ask any question, I more than happy to help!

    Hutchie

    Attached Files:

    Last edited: Jan 23, 2013
    brian25, toffee_pie and absf like this.
  2. thatoneguy

    thatoneguy AAC Fanatic!

    Joined:
    Feb 19, 2009
    Messages:
    6,356
    Location:
    Midwest USA
    7 is an odd number for a cube (and a prime, and...) :D

    Could you go into details about the bit shifting in the frame buffer for the animations?

    That is the part that few have documented for cubes above 4x4 (nibble math).

    It's nice to see a solidly built/professional looking project here.

    I'm also interested in the processing code to create the animations. That would be a goldmine to save work so others can get the project up and running to create new animations as well.
    absf likes this.
  3. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    Dimensions:
    The reason for the cube being 7x7x7 is that effects in general (spirals, text etc.) work much better when there is a true center LED, as it forms an origin for all effects. Similarly text looks far better when the vertical height is an odd number, as you have a "middle line" for letters like "E", B", etc.

    Bit shifting:
    To significantly reduce the amount of data required to display the cube (speeding up the running of the script), bit shifting can be used as an extremely effecient method. Basically what happens is I have defined that there are 49 rows of 7 leds (across all layers), so if you use a byte to store data for a single row, you have 7 bits (0100101) representing the value of each LED, and one left over bit, which can be used as a validation bit (1).
    In the example above I can have the decimal 75, representing the status of that row, along with 48 other bytes of data.


    The arduino runs on a constant loop, reading these bytes, and then converting it into binary. When it then has the binary, it compares 0100101 to 0000001, and realises that the seventh byte is "on", therefor turning the LED on. It then does the bit shift (in this case to the left) and compares 0100101 to 0000010, it detects it should be of, and then starts the cycle again. By using the for loop shown in the code extract below, it will continue to do this until it has read the 7 bits values and outputted them to the cube.

    Code:
    for (byte mask = 1; mask>0; mask <<= 1) { //cycle through bit mask
      if (myFrames[layerInternal] & mask){ // if bitwise AND resolves to true
        digitalWrite(myPins[bitcycle],HIGH);
      }
      bitcycle++;
    }


    Once it has finished this, it loops through reading the other 48 bytes of data, outputting a frame to a cube.

    Finally, the 50th byte in the 2D array for each frame stores the number of milliseconds the frame will last.

    Effect generation:
    In terms of pattern and effect generation, the scripts that generate it are very much dependent of the exact effect that you would like to achieve, for example, for the sine wave, and fireworks, the scripts that I have written would have to accommodate a far wider range of variables to suite individuals preferences for the effects. That being said, i have already started working on this and will hopefully develop this over the next few weeks.
    absf likes this.
  4. thatoneguy

    thatoneguy AAC Fanatic!

    Joined:
    Feb 19, 2009
    Messages:
    6,356
    Location:
    Midwest USA
    Excellent code, fast and clever! Compared to some of the code posted for other cubes, it's genius level.

    If you could post the complete code and the processing script (I'm getting started with Processing since there are questions about it from time to time), that would be most awesome.

    Thanks for sharing!
  5. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    As I only finished this two days ago, I am just commenting and cleaning up the code, so I will post it in the not to distant future.
    Markarduino likes this.
  6. MMcLaren

    MMcLaren Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    Hi mhutchie1,

    It's a work of art before you even turn it on (lol)...

    Would I be correct in assuming your program is basically a small sequencer and that the majority of program memory space is simply the sequence (frame) arrays?
    Last edited: Jan 22, 2013
  7. MMcLaren

    MMcLaren Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    Really? Is that 343 bit write operations per frame? Does Arduino force you to write individual bits only? Is there no way to write multiple bits directly to a port?
    Last edited: Jan 22, 2013
  8. SPQR

    SPQR Member

    Joined:
    Nov 4, 2011
    Messages:
    379
    Location:
    Los Angeles
    What an absolutely beautiful piece of work.
    Congratulations!
    The YouTube is great - did you sync the music beat to the LED movement or just time it to the beat?
  9. thatoneguy

    thatoneguy AAC Fanatic!

    Joined:
    Feb 19, 2009
    Messages:
    6,356
    Location:
    Midwest USA
    A lot of code posted is a large number of digitalWrite[Pin]; delay(xx); code (generated from a animation they like), no framebuffer. You can write to an entire port, but the layout of the boards makes that a bit hard to implement. The "Digital" side on Arduino Leonardo has 14 I/O, which are combined from various pins from ports B, D and E, which does make port writes a bit messy.
  10. SPQR

    SPQR Member

    Joined:
    Nov 4, 2011
    Messages:
    379
    Location:
    Los Angeles
    Could you describe the connections between the wires and the LEDs, or show us a close-up?
    How are the wires insulated from each other?
  11. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    The script itself is only 5Kb, whereas the frame data fills the remaining memory.

    Writing to a port:
    Although you can write to ports on the Ardino board (and yes the layout is not easy to follow), for pov to work the led's need to be on for the longest proportion of time as possible within the 1ms layer. So I figured that if I wrote to the bits through bit shifting (easy enough to do) I would eliminate delays in my script which each have a margin of innaccuracy in their duration, and also avoid the complication of working out which pins belong to each port. See the following link:

    http://arduino.cc/en/Hacking/PinMapping2560

    Audio Sync:
    I made the frames themselves keeping this audio track in mind, however final tweaking was done in the post production of the video, retiming the individual effects minutely.
  12. THE_RB

    THE_RB AAC Fanatic!

    Joined:
    Feb 11, 2008
    Messages:
    5,435
    That is some really neat soldering and alignment, we can only guess how many hours that took but it must have been a lot!

    I hope it doesn't get a bad connection near one of the centre LEDs... :eek:

    Congrats on a very clever project implemented in a very neat and professional way! :)
  13. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    I definitely don't want a bad connection near the middle. I made sure I regularly checked all of the LED's after each stage in the project to avoid "silly" mistakes, of which I found 2 LED's soldered in reverse. Also as shown in the attachments, military cleanliness helped a lot!

    Here is a close up of the wiring of the cube, with the anodes bent, and cathodes attached to the horizontal layers. Soldering was a bit messy on this corner as these were the last LED's of a 6 hour straight soldering experience.

    [​IMG]

    Insulation is only used inside the base of the cube, as the 0.9mm galvanised steel creates a rock-solid structure, so the wires will never touch.

    Attached Files:

    Last edited: Jan 22, 2013
    absf likes this.
  14. SPQR

    SPQR Member

    Joined:
    Nov 4, 2011
    Messages:
    379
    Location:
    Los Angeles
    Ok, now that it's "done".
    What would you do differently if you were to build it again?
  15. hgmjr

    hgmjr Moderator Staff Member

    Joined:
    Jan 28, 2005
    Messages:
    9,030
    Location:
    Tennessee, USA (GMT-6)
    How about a video of your awesome creation in operation?

    hgmjr
  16. SPQR

    SPQR Member

    Joined:
    Nov 4, 2011
    Messages:
    379
    Location:
    Los Angeles
  17. MMcLaren

    MMcLaren Active Member

    Joined:
    Feb 14, 2010
    Messages:
    648
    Location:
    Michigan, USA
    mhutchie1,

    Could you post just one 50 byte frame from one of your sequences, please? I'd like to try something.

    TIA...
  18. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    Here is a 50 byte frame from the project:

    {127,65,65,65,65,65,127,65,0,0,0,0,0,65,65,0,0,0,0,0,65,65,0,0,0,0,0,65,65,0,0,0,0,0,65,65,0,0,0,0,0,65,127,65,65,65,65,65,63,200}

    NOTE: The first 49 bytes are the rows once converted to binary, and the 50th byte is duration (up to 255 miliseconds).
  19. mhutchie1

    mhutchie1 Thread Starter New Member

    Joined:
    Jan 21, 2013
    Messages:
    17
    Location:
    Sydney
    SPQR: This was really hard to answer,

    If I was to make another cube:
    - I would love to make it bigger, maybe 9x9x9 or even 16x16x16. Although this adds exponentially more complexity to the construction and programming of the cube, I still feel it would be worth it.
    - I also considered making the cube from RGB LED's, which would make it look even better, however to buy 350+ RGB LED's starts to get costly quickly.
    - Don't take my word on this one, however you could probably get away with using 0.7mm galvanized steel if you were to making a cube smaller than 7x7x7, but any larger you would definitely need to stay with the 0.9mm wire. By reducing the size of the wire in proportion to the size of the cube enhances the 3D effect of the cube, as you reduce obstructions to seeing the furthest LED's.
    - I would also consider coating the steel wire in black paint, to remove any reflections within the cube, however this would be near impossible to achieve.
    - Another minor issue that I discovered only when I finished the cube assembly was that one corner was higher than the other three (the jig I made to hold the layers together was slightly uneven).
    - I would also reduce the depth of my base in future, probably to 40mm if possible to enhance the presence of the cube and minimize its supporting structure.
  20. SPQR

    SPQR Member

    Joined:
    Nov 4, 2011
    Messages:
    379
    Location:
    Los Angeles
    Good, clear thinking.
    My congratulations!
    Keep up the good work!

Share This Page