Step 10: Program the microcontroller

If you are experiencing problems with speed and/or some LEDs not lighting up. Please read this step carefully.

To program the microcontroller, I use avrdude and the USBTinyISP programmer.

My examples will be on an Ubuntu Linux system. The procedure should be pretty much identical on Windows, but I can't help you with that. If you use another programmer, read thet manual for that programmer and avrdude.

First off, Let's just see if we can make contact with the AVR.

Connect the programmer to your cube and your computer.

The command is "avrdude -c usbtiny -p m16", wherer -c specifies the programmer, and -p the AVR model. You can see the output in the images below.

Now, upload the firmware: "avrdude -c usbtiny -p m16 -U flash:w:main.hex".

By now, the cube should reboot and start doing stuff. It will be running at 1mhz (very slowly) using it's internal oscillator. And some of the leds won't work, because some GPIO ports are used for JTAG by default.

To enable the external oscillator and disable JTAG, we need to program the fuse bytes:
run "avrdude -c usbtiny -p m16 -U lfuse:w:0xef:m"
and "avrdude -c usbtiny -p m16 -U hfuse:w:0xc9:m".

Be carefull when doing this step! If you get it wrong, you can permanently destroy your microcontroller! If you are using another microcontroller than the ATMega16, be sure to read the datasheet carefully before changing the fuse bytes!

After writing the correct fuse bytes, the cube should reboot and start operating at regular speed with all leds operational.

Enjoy your new cube :D

I have been trying to find a tutorial for a bi-colored led cube. Do you have any idea where I could get some help with one in a 4x4x4? Thank you, Thom Mulford
<p>Right, so i placed RTC to show time, made enclosure from oak, finished with linseed oil, and placed mirror-plating as extra touch to create infinity-mirror effect, only in milder effect, it can be viewed in every direction</p>
<p>forgot to add, took hints/information from your bigger cube like that soldering jig, thanks!</p>
<p>Great project man! <br>Can u send me the code? &quot;HEX&quot;</p><p>Thanks!</p><p>giovanni_25_8@hotmail.com</p>
<p>Hai haii..</p><div>I made led cube 3x3x3<br> Obstacles that arise is when<br> - 3x3 layer 1 __ Is correct (all live)<br>- 3x3 layer 2 __ Is correct (all live) <br>- 3x3 layer 3 __ Is correct (all live)<br><br> Why when I combine layer1, layer2, and layer3 (Many LED DEAD).<br><p>I want to know why many LED die ???</p><p>Thank you very much</p><br><br></div>
<p>check out my 4x4x4 LED Cube</p><p><a href="http://ps-microcontrollerprojects.blogspot.in/2015/09/4x4x4-3d-led-cube-using-avr-atmega16.html" rel="nofollow">http://ps-microcontrollerprojects.blogspot.in/2015/09/4x4x4-3d-led-cube-using-avr-atmega16.html</a></p>
<p>tell me how to generate code for 4*4*4 led cube.,.,</p><p> plz send me link for generationg code for AVR.</p>
<p>can i use a bc548 instead of using bc 338 transistor</p>
<p>Hello, I'm a free user and i wanna make this project. It is showing 11steps, are they complete or should i turn to a paid user?<br>Please tell</p>
<p>There are only 11 steps, free uses can see all the steps and comments, but can not download the project as a pdf, support the site and other things.</p>
<p>I am facing problem in compiling code . Which compiler or converter should be used to convert the above .c files to .hex files</p>
<p>Is Willar programmer fine for Programming Atmega16??</p>
<p>I put the .hex file on the desktop. I got in command prompt this message:</p><p>error opening 4x4x4_ledcube.hex: no such file or directory</p><p>Whats the problem?</p>
<p>I would really like to start this project; it looks so cool! Could I build the 8x8x8 with the Arduino Uno instead? It only has three ports so would it even be possible or would I only be able to build the 4x4x4 cube with the Arduino Uno? If I have to do the 4x4x4 cube, the wiring would probably be different and the code would remain the same though right?</p>
<p>Ungrounded layers sometimes light dimly:</p><p>I built a prototype of a 4x4x4 LED cube on a protoboard following the anode column/cathode layer approach with a set of current limiting resistors between the columns and an arduino controller and close the plane circuits with a set of 4 transistors in the software with an intent to only have a single plane on at a time. As I&rsquo;ve been testing my cube, I found that the fewer the leds that I have lit, the more pronounced an unpleasant effect is where other leds in an activated column (but unactivated plane) light dimly. I&rsquo;m really unsure why these leds would light up. The effect seems more pronounced with fewer leds being lit at a single time and totally disappears when all 16 leds in a plane are lit. Surprisingly, if I remove all grounding that closes a circuit, the activated column still lights with a diffuse lighting across the leds in the column. I&rsquo;ve <a href="https://www.youtube.com/watch?v=8O-Z7RAQRX8" rel="nofollow">linked</a> a video that shows the effect in the hopes that someone can help me understand what&rsquo;s wrong. net/net, I copied this design but hooked it up to an arduino</p>
<p> <br> <br>I love this blog!! <br> The flash up the top is awesome!!</p><p><a href="http://www.monacopropertylistings.com" rel="nofollow">appartamenti a monaco</a></p>
<p>I have problem with the usbtinyisp. who can help me?</p>
<p>You need to install windows driver for your 'usbtinyisp' first.</p>
<p>I installed the driver and the usbtiny communicated with the chip. But when I try to setting the fuse, the programm tell me something like &quot;change 0 with ... (y/n)&quot;. I write &quot;n&quot; and from this moment the usbtinyisp can't communicated (connection failed, rc=-1)</p>
<p>i need to know how can i programme a cube led 4*4*4 without arduino !!!! plzzzzz</p>
<p>can you email me the program with &quot;mikropascal pro&quot; ? khouloudkalil@gmail.com</p>
<p>I built my ledcube thanks to your awesome tutorial, but saw this &quot;To compile the program, open a command prompt, enter the directory with the source code and type &quot;make&quot; on the command line. You should now have a file named main.hex in the source directory&quot; I tried that with the source files and I get all kinds of errors. C:\WinAVR-20100110\xledcube&gt;make</p><p> 0 [main] sh 2156 sync_with_child: child 1572(0x14C) died before initializa</p><p>tion with status code 0xC0000142</p><p> 670 [main] sh 2156 sync_with_child: *** child state waiting for longjmp</p><p>/usr/bin/sh: fork: Resource temporarily unavailable</p><p>-------- begin --------</p><p>avr-gcc (WinAVR 20100110) 4.3.3</p><p>Copyright (C) 2008 Free Software Foundation, Inc.</p><p>This is free software; see the source for copying conditions. There is NO</p><p>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p><p>Compiling: main.c</p><p>avr-gcc -c -mmcu=atmega16 -I. -gdwarf-2 -DF_CPU=14745600UL -Os -funsigned-char</p><p>-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-</p><p>adhlns=main.lst -std=gnu99 -MD -MP -MF .dep/main.o.d main.c -o main.o</p><p>In file included from main.c:74:</p><p>draw.c: In function 'setplane':</p><p>draw.c:170: warning: comparison between pointer and integer</p><p>draw.c:170: warning: comparison with string literal results in unspecified behav</p><p>ior</p><p>..... long list down. What is the problem ? I want to try this to remove some of the effects. I already uploaded the hex file but I want fewer effects.</p>
<p>hey. can u email me the program? hediana11@yahoo.com</p>
<p>Hi there, I want to make my LED Cube on STM32F4 Discovery board. It has Current Limit 150 mA and I have only 270 ohm resistors, which give </p><p>3V Ouput</p><p>11 mA per LED</p><p>177 mA when all 16 LEDs are ON. Will it damage my board?</p><p>Here is documentation link, p 77</p><p><a href="http://www.st.com/web/en/resource/technical/document/datasheet/DM00037051.pdf" rel="nofollow">http://www.st.com/web/en/resource/technical/docume...</a></p><p>P.S. Thanks for great instructable!</p>
<p>I made the cube with this board.</p><p>It won't damage the board. You will have only 150/16~9 mA per LED instead of 11 mA.</p><p>The side-effect is that one LED in layer will glow brighter then 16 in the same time.</p><p>P.S. sorry for my english.</p>
<p>i want to make a 5*5*5 led cube.what changes should i consider??</p>
<p>Hello ! Thank you for this awesome instructable.<br>I made a mistake while programming the microcontroller. <br>I ran &quot;avrdude -c usbtiny -p m16 -U lfuse:w:0xc9:m&quot; instead of &quot;avrdude -c usbtiny -p m16 - U hfuse:w:0xc9:m&quot; (the difference is &quot;lfuse&quot; instead of &quot;hfuse&quot;).<br>What's the command to reset the microcontroller ? <br>Thank you for your help.</p>
<p>Great Instructable!!!</p>
<p>Wahoo! It's finally complete! One of my inner bottom LEDs just died on me though :( That will be fun to switch out.</p><p>This instructable was great!</p>
<p>Time to move up to an 8X8X8 for your next project - and then on to the 8X8X8 RGB....fortunately got you I have instructables on both!</p>
<p>ok then how i can set the fuse bits .... plz tell me.....</p><p>i am using top2008(a universal programmer) burner to program the atmega......</p><p>thanx for the reply</p>
<p>Hello. Thank you for this great detailed instructable, it helped me alot. But i have a question, if all leds will be turned on, wouldn't they all consume (4*4*4)*0.012A=0.768A? And what will be with microcontoller, when its allow max 200mA at once?</p>
<p>Firstly - there are current limiters on the LEDs.</p><p>Second, only one layer is on at a time, max 16 LEDs</p><p>Third - LEDs are modulated - not ON with DC .</p><p>End result - very VERY little current draw.</p>
<p>From what I know the LEDs are not turn on all at once but one by one in a very fast rate nearly 200 frames per second, just giving the illusion of them turned all at once.</p>
<p>Thanks for reply. Thats right what i was thinking :)</p>
<p>i program the with given hex file but speed is very slow how can i increase the speed.</p>
<p>I am guessing you forgot to set the fuse bits to use the external crystal, so the ATmega is running on the internal 1 or 4MHz clock rather than the external 16MHz.</p>
<p>Or in this case, the external 14.7456MHz.</p>
<p>how can i increase the speed please tell me</p>
<p>Hello. Tell me, what transistors attach layers.</p>
<p>i am new to programming can someone please tell me how to start or insert codes in this thing. Thank you..</p>
<p>I LIKE THIS</p>
<p>i see people can't seem to read.... it's not hard. 'save as' re-name </p><p>F6JRI6AFJ1I6CP0.tmp</p><p>to main.hex. upload to atmega16 chip and you are done!</p>
How to increase the flashing speed of led.... ?
How to increase the flashing speed of led.... ?
i have a question&nbsp; how do i use the zip file? the hex i can use it from windows to send it to avr but the zip i didn't know how to use..! can someone tell me if it s important o not?<br />
<p>the zip file contains the original naked coding files which you can edit if you want to, but if you dont know what you are doing... dont touch it.</p><p>if you uploaded the .hex file... you've completed the programming of the atmega chip and theres nothing more you need to do</p>
How do you connect an avr to your pc for the code to load on it? And yes I&nbsp;do have linux<br />
<p>you need a gadget called a 'usbtiny' which is available on Ebay</p>

About This Instructable


1,448 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: