Step 8: IO port expansion, more multiplexing

We gathered from the last step that an 8x8x8 LED cube requires 64+8 IO lines to operate. No AVR micro controller with a DIP package (the kind of through hole chip you can easily solder or use in a breadboard, Dual Inline Package) have that many IO lines available.

To get get the required 64 output lines needed for the LED anodes, we will create a simple multiplexer circuit. This circuit will multiplex 11 IO lines into 64 output lines.

The multiplexer is built by using a component called a latch or a flip-flop. We will call them latches from here on.

This multiplexer uses an 8 bit latch IC called 74HC574. This chip has the following pins:

  • 8 inputs (D0-7)
  • 8 outputs (Q0-7)
  • 1 "latch" pin (CP)
  • 1 output enable pin (OE)

The job of the latch is to serve as a kind of simple memory. The latch can hold 8 bits of information, and these 8 bits are represented on the output pins. Consider a latch with an LED connected to output Q0. To turn this LED on, apply V+ (1) to input D0, then pull the CP pin low (GND), then high (V+).

When the CP pin changes from low to high, the state of the input D0 is "latched" onto the output Q0, and this output stays in that state regardless of future changes in the status of input D0, until new data is loaded by pulling the CP pin low and high again.
To make a latch array that can remember the on/off state of 64 LEDs we need 8 of these latches. The inputs D0-7 of all the latches are connected together in an 8 bit bus.

To load the on/off states of all the 64 LEDs we simply do this: Load the data of the first latch onto the bus. pull the CP pin of the first latch low then high. Load the data of the second latch onto the bus. pull the CP pin of the second latch low then high. Load the data of the third latch onto the bus. pull the CP pin of the third latch low then high. Rinse and repeat.

The only problem with this setup is that we need 8 IO lines to control the CP line for each latch. The solution is to use a 74HC138. This IC has 3 input lines and 8 outputs. The input lines are used to control which of the 8 output lines that will be pulled low at any time. The rest will be high. Each out the outputs on the 74HC138 is connected to the CP pin on one of the latches.

The following pseudo-code will load the contents of a buffer array onto the latch array:

// PORT A = data bus
// PORT B = address bus (74HC138)
// char buffer[8] holds 64 bits of data for the latch array

PORTB = 0x00; // This pulls CP on latch 1 low.
for (i=0; i < 8; i++)

PORTA = buffer[i];
PORTB = i+1;


The outputs of the 74HC138 are active LOW. That means that the output that is active is pulled LOW. The latch pin (CP) on the latch is a rising edge trigger, meaning that the data is latched when it changes from LOW to HIGH. To trigger the right latch, the 74HC138 needs to stay one step ahead of the counter i. If it had been an active HIGH chip, we could write PORTB = i; You are probably thinking, what happens when the counter reaches 7, that would mean that the output on PORTB is 8 (1000 binary)on the last iteration of the for() loop. Only the first 8 bits of PORT B are connected to the 74HC138. So when port B outputs 8 or 1000 in binary, the 74HC138 reads 000 in binary, thus completing its cycle. (it started at 0). The 74HC138 now outputs the following sequence: 1 2 3 4 5 6 7 0, thus giving a change from LOW to HIGH for the current latch according to counter i.

<p>please give me a code and schematic email asimsheikh780@gmail.com</p>
<p>Great survey, I'm sure you're getting a great response.<br><a href="http://markoservices.pl/pod-lupa-szklo-w-kaszkach-nestle/" rel="nofollow">szklo w nestle</a></p>
<p>Hello, I understand that the use of two transistor for each layer is due to the current limitation of the transistor. Can those 2 be changed for a more powerfull transistor ?<br>Also,its not possible to use some kind of shift register to control the transistors ?Use 3 ports instead of 8 ports ?</p>
<p>Great work..</p>
Hii....i built my cube but its not glowing properly....
<br> The<br> website is looking bit flashy and it catches the visitors eyes. Design is<br> pretty simple and a good user friendly interface.<br><p><a href="http://journalistesportif.tumblr.com" rel="nofollow">http://journalistesportif.tumblr.com</a></p>
<p>Hi, I've added your project to the &quot;<strong>A Collection of WAAAY To Many 8X8X8 RGB LED Cubes!</strong>&quot; Collection</p><p>This is the link If you are interested:</p><p><a href="http://www.instructables.com/id/A-Collection-of-WAAAY-To-Many-8X8X8-RGB-LED-Cubes/">http://www.instructables.com/id/A-Collection-of-WA...</a></p>
<p>Hi guys! ? </p><p>first, thanks to chr for that incredible instructable! it has me inspired, a lot. </p><p>i tried to download the files from the project. but i was not successfull.</p><p>any ideas?</p>
<br> <a href="http://damdaar.com/14-major-incidents-by-global-warming-climate-changes/" rel="nofollow">hardly heat waves in Argentina</a><br>
<p>I tried it, but failed to glow all...</p>
<p>Good work...</p>
<p>hi all</p><p>As like &quot;<a href="http://www.instructables.com/member/power000" rel="nofollow">power000</a>&quot; my led cube also having da same problem, some led column remain on constantly, pls help &amp; suggest the reason and how to rectify the problem.</p>
<p>go to my revisited instructable and get my code or go to <a href="http://www.TheLEDCube.com"> www.TheLEDCube.com </a> and download the RAMP.zip file, and upload my code to your cube.</p><p>Video the POWER ON SELF TEST and send me a message with a link to your video, and I will diagnose your issue.</p>
<p>Hi, I seem to have successfully set the fuse bits, but here's the thing: after uploading the test.hex file to atmega32 and turning the cube on i get some random layers light up and stay on (with some flickering). Here's the video of that: <a href="https://www.dropbox.com/s/qpha7qhs9xkwyb8/VID_20151030_185558.mp4?dl=0" rel="nofollow">https://www.dropbox.com/s/qpha7qhs9xkwyb8/VID_2015...</a></p><p>I have a suspicion, that i may have fried something on the board and i hope that you may have an answer to that. At one point, i have accidentally powered on the cube via the 5V power source while it was still connected to USBasp which was plugged in the usb port. The USBasp didn't work afterwards (lol), so i ordered a new one. I also had trouble connecting to the atmega via the on-board connector, so i put it on a breadboard to see if it makes a difference - still no go. But after adding the crystal and two 22pF capacitors on the XTAL1 and XTAL2 SUCCESS! Avrdude started displaying the correct signature, i managed to set the fuse bits and write the test.hex successfully into the atmega. Do you have any idea if i could tinker with a multimeter to see whether anything went bad? Oh, i had a 1A fuse installed, which went off during my &quot;accident&quot;.</p><p>Thank you in advance!</p><p>P.S. I'm thinking of upgrading my cube in the long run by purchasing one of your premade boards to eliminate the wiring. However, I'm confused on which one i should get and how much that would cost me.</p>
<p>One of the fuses you set initially is switching from the internal 4MHz clock to the external crystal - so no crystal = no running after setting the fuses...that is until you add the crystal. So chances are, you didn't damage anything. In fact it did exactly what one would expect. For a mono cube, you'll want one of the RAMP boards.</p>
<p>So basically what you're saying is that atmega is not &quot;seeing&quot; the external crystal?</p>
<p>No, what I am saying is it never looks for the crystal UNTIL you set the fuse bits.</p><p>Once they are set, it MUST have a crystal.</p><p>No crystal means no clock, and a CPU running at zero clock cycles won't get much done! That's why it sprang to life once you added the crystal.</p>
<p>I finally got test.hex flashed and it works..sort of (video here: https://www.dropbox.com/s/5kophve403vw5cr/VID_2015...</p><p>I was happy nonetheless, because the sequence runs nicely with a few exceptions:</p><p>1. There must be a wiring issue, because the rows go like this: 1, 2, 4, 3, 6, 5, 7, 8. I tried tinkering with the wires to no avail, i don't really understand what could be causing this. I'm thinking maybe transistors?</p><p>2. The flickering and unlit LEDs must be caused by soldering errors or lack of contact, am I right?</p><p>3. There are some LEDs which faintly glows when turned off (itcan be seen when the whole cube goes dark). Does it mean that those LEDs receive some of the current even in the off state?</p>
<p>You may have the last 2 bits of the demultiplexer reversed....</p><p>so instead of bits A0, A1, A2 you have them wired bits A0, A2, A1. (as I recall, these would be pins 2 and 3 of the 74HC138) This might explain the sequence.</p><p>Triple check your wiring to the 138</p><p>Also you might have the data bus wired wrong, or you may simply have wired the cube to the controller incorrectly.</p><p>Your dropbox link isn't working, maybe try to youtube it.</p>
<p>Ok, thanks, I'll try that. </p><p>Here's link to youtube: <iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/nvisYO6vk0E" width="500"></iframe></p>
<p>looks more like a wiring issue from controller to cube than demultiplexer issue.</p><p>try the main.hex from <a href="http://www.instructables.com/id/CHRs-8X8X8-LED-Cube-Revisited-with-improvements/step10/How-do-I-modify-the-software-Questions-Answers-and/">http://www.instructables.com/id/CHRs-8X8X8-LED-Cub...</a> </p><p>I think that has my power on self test, which I would like you to video. It will tell me in better detail what's wrong with your cube.</p>
<p>main.hex video here:</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/las1Agjynrc" width="500"></iframe></p><p>Very nice sequence, can't stop watching the cube!</p>
<p>I tried to transfer the correct code to you by skype, but you never came back online.</p>
Thanks for your time. Sorry I didn't have the time for that, I'm studying in college and working night shifts, so free time is scarce :D after placing the pcb boards with the wiring on a stable surface (the boards were just placed beneath the cube without any extra support) and running the cube for several hours I've noticed an improvement in terms of flickering and missing LEDs. There's still one part that is flickering, but I believe I'll manage that. Also, after flashing this main.hex file I noticed that the sequence runs in order (maybe the test.hex had it's flaws?). So, apart 2 burned LEDs and some minor flickering during certain animation I find the cube in an OK condition, requiring minor tweaks. So I don't really want to bother you with such minor problems. I'd appreciate any .hex files you can throw my way though. Many thanks, I'll keep in touch!
<p>OK, but remember you won't get any text unril you also flash the MAIN.EEP. both the eep and the hex need to be flashed to the chip to get the text, otherwise all the letters will appear as solid blocks.</p>
Alright, but if I remember correctly, I have to use rs232 connector? I have a slight problem with that, because my computer doesn't have the serial port (db9).
<p>nope. You know those squares that go around the outside of the cube right now? Those are actually undefined letters.</p>
<p>crap, that's the old main.hex....I'll have to compile one for you that has the power on self test. However, in the mean time...you do seem to have some short circuits, and you seem to have some of the lines wired wrong. I'll PM you my skype address, and I'll try to have a video session with you. Add me to your skype.</p>
<p>...sorry, can I impement this Code<br>(RAMP.zip) in Arduino UNO??? it&acute;s the same?? I have looked at:<br><a href="http://www.TheLEDCube.com/" rel="nofollow">www.TheLEDCube.com</a> but I<br>haven&acute;t seen it, in which section it is? I can&acute;t see it...Many<br>thanks! </p>
<p>At the top of the main page, click SOURCE CODE then download RAMP.ZIP</p><p>Unzip the file to a folder on your hard disk / desktop.</p><p>The source code for the Arduino is in the Atmega 328 section/folder.</p><p>Because my board conforms 100% to this project on both the Atmega328P (Arduino) and the ATmega32, I include code for both processors.</p><p>Please remember that with the Arduino, you lose serial capabilities (and on my boards, you also lose music response)</p>
<p>...I think got it!, do you think is this file: &quot;8X8X8 Arduino.pde&quot;?</p>
<p>that one or the one WITH POST (Power On Self Test)</p>
<p>...which one, which one? (do you mean this instructable publication you <br>are recomending me?) and where can I see the one with POST (Power On Self Test) you said? Sorry this instructable publication is yours, or you <br>post it? Many thanks!!!</p>
<p>You can use either code. If you downloaded the RAMP mini-CD then the code with POST is in a subdirectory where the regular arduino code is.</p><p>This instructable is not mine, it's one I post in. This was the instructable that got me into microcontrollers and LED cubes. TheLEDCube.com is my site where I offer PC Boards and extended code for this and the RGB LED cube projects.</p><p>Please don't expect people to tell you what to do every step of the way. Try to explore and READ and figure things out on your own. If you have a question that is BEYOND all the documentation, then we are here to help.</p>
<p>Yes sorry!!! Many thanks I will ;D</p>
<p>...mmm wow, I like Arduino because it seems less work to do, but so which circuit is the best or more complete to do? The one of Instructables? &amp; sorry serial capabilities for what? what can I do with that?</p>
<p>To answer all your questions, please finish reading this complete instructable, and then go through my &quot;revisited&quot; instructable.</p>
<br> This is<br> such a great resource that you are providing and you give it away for free. I<br> love seeing blog that understand the value. Im glad to have found this post<br> as its such an interesting one! I am always on the lookout for quality posts<br> and articles so i suppose im lucky to have found this! I hope you will be<br> adding more in the future...<br><br> <a href="https://www.youtube.com/watch?v=ZyF8T0eOYqc" rel="nofollow">Genius marketing pro review </a><br>
<p>Hi, </p><p>Thanks a lot for this instructable, i finished building the cube and it works almost perfecly. The only issue is that when the cube wants to show the first data of the fifth IC(547) it turns all the plane on. i've checked the continuity between all the data lines as well as changing the IC, but none of this worked. I would really aprecciate your help since i don t know what else to do.</p><p>(By the way i&acute;m using an Arduino UNO and it's a 7x7x7 cube).</p>
<br> This was<br> a really great contest and hopefully I can attend the next one. It was alot<br> of fun and I really enjoyed myself..<br><br> <a href="https://www.youtube.com/watch?v=aUuMyaPyby4" rel="nofollow">Build my list 2.0 review</a><br>
<br> Greatpost, you have pointed out somefantasticpoints , Ilikewisethinkthis s a verywonderful<br> website.<br><br> <a href="https://www.youtube.com/watch?v=2OKOGM3JYCc" rel="nofollow">Build my list 2.0 bonus</a><br>
<p>Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. <a href="https://www.youtube.com/watch?v=6XvjFwRywZU" rel="nofollow">Commission Juggernaut Reloaded</a></p>
<br> I felt<br> very happy while reading this site. This was really very informative site for<br> me. I really liked it. This was really a cordial post. Thanks a lot!.<br><br> <a href="http://lagrill.co.ukhttp://lagrill.co.uk" rel="nofollow">restaurants in sutton coldfield</a><br>
<br> howdy,<br> your websites are really good. I appreciate your work.<br><br> <a href="http://vertshocked.net" rel="nofollow">how to improve a vertical jump</a><br>
<br> Hey There. I found<br> your blog using msn. This is a very well written article. I&rsquo;ll be sure to<br> bookmark it and come back to read more of your useful info. Thanks for the<br> post. I&rsquo;ll definitely return.<br><br> <a href="https://www.youtube.com/watch?v=BbRyrYF0NmQ" rel="nofollow">ecom premier academy review</a><br>
<br> If you set out to<br> make me think today; mission accomplished!I really like your writing style and how you express your ideas.Thank you.<br><br> <a href="https://www.youtube.com/watch?v=BbRyrYF0NmQ" rel="nofollow">ecom premier academy review</a><br>
<br> I have been<br> checking out a few of your stories and i can state pretty good stuff. I will<br> definitely bookmark your blog<br><br> <a href="https://www.youtube.com/watch?v=YRB6IfTZkGc" rel="nofollow">The Venus Factor Review</a><br>
<p>I am not using rs232 ic just using atmega32 and 74hc574and 74hc138ic just using basic module I don want confuse I want program the atmega working alone </p>
<p>check my &quot;revisited&quot; instructable.</p>

About This Instructable


3,647 favorites


Bio: I like microcontrollers and LEDs :D
More by chr: Reverse Engineering: RGB LED Bulb with IR remote Reverse engineering: USB controlled home automation hack LED Cube 8x8x8
Add instructable to: