Step 65: PC Software: Cube updater thread

In cube.c we have a function called cube_push(). This takes the 64 byte array and sends it down the serial line to the LED cube.

It also handles the formatting, sending every 0xff byte twice because 0xff is our escape character. 0xff and 0x00 is sent first to reset the LED cubes internal x and y counters.

In main.c we have the function cube_updater(). This function is launched as a separate thread using pthread_create(). The main thread and the cube updater thread shares the memory area rs232_cube[8][8]. The cube updater thread is just a while true loop that calls cube_push() over and over.

The first attempt at an updater thread turned out to create some flickering in the animations. After some debugging, we found out that frames were being transmitted before they were fully drawn by the effect functions. We generally do a fill(0x00), then some code to draw new pixels. If a frame is transmitted right after a fill(0x00), the cube will flash an empty frame for 1/60th ish of a second.

This wasn't a problem in the code running on the LED cube, since it has a refresh rate of over 1000 FPS, but at 60 FPS you can notice it.

To overcome this we create a double buffer and sync the two buffers at a point in time where the effect function has finished drawing the frame. Luckily all the effect functions use the delay_ms() function to pause between finished frames. We just put a memcpy() inside there to copy the cube buffer to the rs232 buffer. This works beautifully. No more flickering!

<br> Excellent<br> and very exciting site. Love to watch. Keep Rocking.<br><br> <a href="http://phuketmediacompany.com/" rel="nofollow">Phuket web design</a><br>
<p>Nice to read your article! I am looking forward to sharing your adventures and experiences.<br><a href="https://www.youtube.com/watch?v=_pHN8PeeYqU" rel="nofollow">Affilojetpack 2.0 review</a></p>
<p>Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post.<br><br><a href="https://www.youtube.com/watch?v=YRB6IfTZkGc" rel="nofollow">The Venus Factor Review</a></p>
<p>Thanks, that was a really cool read!<br><br><a href="http://bluestar-eliquid.co.uk" rel="nofollow">nicotine concentrate</a></p>
<p>Your website is really cool and this is a great inspiring article.<br><a href="http://www.profischnell.de" rel="nofollow">profischnell.de</a></p>
<h3><a href="http://psychicfox.co.uk" rel="nofollow">(Tarot Card Readings)</a><p><a href="http://psychicfox.co.uk" rel="nofollow"> </a><br> </p></h3><p>Thank you very much for this great post.</p>
<p><a href="http://www.baatkar.com" rel="nofollow">For how to guides and software tutorial visit this</a></p>
<p><a href="http://www.baatkar.com" rel="nofollow">Great Article I Appreciate Your Work</a>. </p><p>Thanks</p>
<p>where are all the comments</p>
<p>I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks<br><a href="http://memyfriends.com/how-to-get-a-hot-girlfriend-if-youre-ugly/" rel="nofollow">can i get a hot girl if i'm ugly</a></p>
<p>Is it just me, or did all the comments disappear?</p>
<h3><a href="http://nasirilyas.com" rel="nofollow">nasir ilyas</a></h3><p>Thanks for sharing this quality information with us. I really enjoyed <br> reading. Will surely going to share this URL with my friends.</p>
<p>This is a great article thanks for sharing this informative information. <br> I will visit your blog regularly for some latest post. I will visit <br>your blog regularly for Some latest post. <br><a href="http://j.mp/AddSite" rel="nofollow">Submit URL</a></p>
<p>This one is good. keep up the good work!..<br> <br><a href="https://www.youtube.com/watch?v=WXPalR1Ljvs" rel="nofollow">Rich Jerk</a></p>
<br> This is such a <br> great resource that you are providing and you give it away for free. I love <br> seeing blog that understand the value of providing a quality resource for <br> free. <br><p><a href="http://www.nagmauritius.org/how-to-get-a-woman-hooked-on-you/" rel="nofollow">nagmauritius.org/how-to-get-a-woman-hooked-on-you/</a></p>
<p>i love reading this article so beautiful!!great job!<br> <br><a href="http://movietubenow.weebly.com/" rel="nofollow">movie tube now</a></p>
<p>These are some great tools that i definitely use for SEO work. This is a great list to use in the future.. <br><a href="http://www.aconsult.fr/pascher.asp" rel="nofollow">Canada Goose Manteau Solde</a></p>
<br> Great <br> Article it its really informative and innovative keep us posted with new <br> updates. its was really valuable. thanks a lot. <br> <br> <a href="http://www.entretien-menager-genial.ca" rel="nofollow">menage apres construction prix</a> <br>
<br> I read <br> that Post and got it fine and informative. Please share more like that... <br> <br>menage apres construction prix <br>
<p>Thank you for such a well written article. <br>It&rsquo;s full of insightful information and entertaining descriptions. Your <br> point of view is the best among many.<br><a href="https://www.youtube.com/watch?v=_pHN8PeeYqU" rel="nofollow">Affilojetpack 2 Review</a></p><br>
<p>hai guys I want to know how much power and amp give for cube and I am using arduino so arduino hold 1.5 amp 5v and connect to driver board or I give power to driver board separately and arduino separately and how much I want give can u give me detail</p>
<p>Hello i have built this cube but i am having problems. i upload the test code and everything works but after i uploar the second code as well as the firmware nothing happens</p>
<br> This is actually <br> the kind of information I have been trying to find. Thank you for writing <br> this information. <br> <br> <a href="http://womeninneuroscience.org/sleep/side-effects-kavinace.html" rel="nofollow">more</a> <br>
<p>I will make it</p>
<p>Thanks for taking the time to discuss this, I feel strongly that love <br>and read more on this topic. If possible, such as gain knowledge, would <br>you mind updating your blog with additional information? It is very <br>useful for me.<br><a href="https://www.youtube.com/watch?v=NQgksA_SL7Y" rel="nofollow">Fat Diminisher</a></p><br>
<p>Your website is really cool and this is a great inspiring article. Thank you so much. <br><a href="https://www.youtube.com/watch?v=tLRUy_wPIro" rel="nofollow">Video Vibe Pro Review</a></p>
<p>I am using arduino mega as isp to program or usb pic or if u any software for led programming that is also good </p>
I'm good to go now found good files on pyroelectro.com by thepyroelectro www.pyroelectro.com/projects/8x8x8_led_cube/arduino_8x8x8_cube.pde
can you tell me how to copy and paste animations into the my main sketch from other sketches? So I can add more animations. what section sketch to copy and where to place it. thanks
<br> Fantastic blog you <br> have here. You&rsquo;ll discover me looking at your stuff often. Saved! <br> <br> <a href="http://www.entretien-menager-genial.ca" rel="nofollow">menage apres construction prix</a> <br>
<p>hi , i have made CRR's led cube but something very strange is happening</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/YZucW88VQr0" width="500"></iframe></p><p>there are led lighting that must not light. I have change emmitter with collector , i have use only one 2n222 as <a href="http://www.instructables.com/member/SuperTech-IT/" rel="nofollow">uperTech-IT</a> says but nonthing good.</p>
<p>I noticed you got yours up and running. Congrats. I see you went the 2 transistor rout in the end, but that's OK, it's just more parts than needed.<br>My boards are a lot more compact than yours, and allow Arduino's ATmega328p or the ATmega32/32A/32L processors, but the end result is pretty much the same. LOL. Here you can also see one of my completed single colour cubes beside one of my RGB cubes.<br></p>
2N2222 transistor have 600ma current max on colector and one led need 0.015ma mutil by 64 led each layer equal ~1A. Therefore you need at leat 2 2N2222 transistor
<p>More precisely, my design uses single 2N2222 for the layers - the whole cube with all LEDs lit draws under 700mA. Anyways, if you still have not worked this out, go to www.TheLEDCube.com and download my source code for your processor which contains a POWER ON SELF TEST. Video the POST and put the video up here and I will analyze it and point you to pretty much exactly what's wrong right off the bat unless there are multiple shorts / bad connections.</p>
<p>Hey, can u uploade a bit more detailed description of the power supply.</p><p>I cannot figure out how to solder the pieces</p>
<p>Your best bet is to simply get a 5V 2A plug-in power supply.</p><p>These are cheap and plentiful on ebay.</p>
<p>What have you used, atmega or arduino? </p>
<p>i use atmega</p>
<p>It worked flawlessly buddy. it is such a great feeling achieving that task</p>
<p>The Arduino is also ATmega in that the processor is an ATmega328P.</p><p>Most people prefer the ATmega32/32A/32L for this project though.</p>
<p>Finally, It worked flawlessly. Now I want to go to the next level and use atmega32. Problem is to get the crystal, I'll have to import it</p>
<p>and of course i have place 8 pull up resistors on collectors ,6.2k</p>
<p>finally it works! there were many short circuits and tow transistor had electrik leak</p>
<p>Glad you got it all up and running! Hope to see a video of your cube in action!</p>
<p>Is there any program to control led cube and make coding easy ,just clicking on leds we want to gets on with the order we want?</p>
wow I'm blown away. I built the jameco 8x8 cube pcb version. their sample code works great but I sure would like more code that will work with this kit. I'm glad I made the cube large with 25mm spacing thanks for the advice.
I built the Jameco 8x8x8 cube PCB version. I need better code than the sample file. Please help.
<br> I found your this <br> post while searching for information about blog-related research ... It's a <br> good post .. keep posting and updating information. <br> <br> <a href="https://www.usheat.com/Thermocouple" rel="nofollow">usheat.com</a> <br>

About This Instructable


3,524 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: