3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

LED Cube 8x8x8

Step 41Build the controller: RS-232

Build the controller: RS-232
«
  • IMG_5970.JPG
  • IMG_5965.JPG
To get the truly amazing animations, we need to connect the LED cube to a PC. The PC can do floating point calculations that would have the AVR working in slow motion.

The ATmega has a built in serial interface called USART (Universal Synchronous and Asynchronous serial Receiver and Transmitter).

The USART communicates using TTL levels (0/5 volts). The computer talks serial using RS232. The signal levels for RS232 are anywhere from +/- 5 volts to +/- 15 volts.

To convert the serial signals from the micro controller to something the RS232 port on a PC can understand, and vice versa, we use the Maxim MAX232 IC. Actually, the chip we are using isn't from Maxim, but it is a pin-compatible clone.

There are some 100nF ceramic capacitors surrounding the MAX232. The MAX232 uses internal charge-pumps and the external capacitors to step up the voltage to appropriate RS232 levels. One of the 100nF capacitors is a filter capacitor.

The RS232 connector is at a 90 degree angle for easy access when the latch array board is mounted on top of the AVR board. We used a 4 pin connector and cut one of the pins out to make a polarized connector. This removes any confusion as to which way to plug in the RS232 cable.

In the second picture you can see two yellow wires running from the ATmega to the MAX232. These are the TTL level TX and RX lines.

1) Connect the GND and VCC pins using solder trace or wire. Place a 100nF capacitor close to the GND and VCC pins.

2) Solder in place the rest of the 100nF capacitors. You can solder these with solder traces, so its best to do this before you connect the tx/rx wires.

3) Solder in place a 4 pin 0.1" header with one pin removed. Connect the pin next to the one that was removed to GND.

4) Connect the tx/rx input lines to the micro controller, and the tx/rx output lines to the 4 pin header.

The wires going to the 4 pin header are crossed because the first serial cable we used had this pinout.
« Previous StepDownload PDFView All StepsNext Step »
16 comments
Feb 29, 2012. 4:45 PMchaserled says:
Hi Trium i really don't know why it doesn't work for me my PC serial port is com1 i did edit cube.c to change port but still doesn't work at all and also i try on Ubuntu but not get anything work , i really need your help or who may point me a direction
Mar 1, 2012. 10:32 PMtriumphtotty says:
Are you starting the AVR board in RS232 mode? If so, the status LEDs (the ones which flash at startup) will flicker whenever data is received. Try a normal terminal program on COM1 and just type some nonsense to check you have comms working. Did you fix the swapped TX/RX pins issue on the schematic, and add Vcc and GND to your MAX232?
Mar 2, 2012. 8:36 AMchaserled says:
i already try but isn't work, so do i need to modify the main.c file or any file to run this, i believe win7 work but dont know why
Mar 2, 2012. 9:17 AMtriumphtotty says:
The main.c code for RS232 is fine. When you press your RS232 button do the LEDs stop flashing? If so, it should be working OK. Double-check your wiring for the MAX232. It's otherwise very simple. I don't think it's easy to get the cube_pc code to run in Windows, but I don't have any way of testing it on my system.
Mar 4, 2012. 1:21 AMchaserled says:
thank God finally it work , thank trium, now the cube is look great , i really like these amination i mean the code effect look very cool, so how can i combine it to the main.hex and main.eep? trium i know that i have too many qestion sorry
beacause i'm the new comer on the field
Mar 4, 2012. 3:23 AMtriumphtotty says:
Hah. The reason for using the PC to do these effects is that they take a lot of processor time, especially the sidewaves and ripples which use square roots, sine and cosine which are floating point. The ATmega32 does not have a floating point unit, so it takes it hundreds of cycles to work out the sine of a number and thousands to do a square root.

However I have optimised Game Of Life, sidewaves and ripples to run at full speed on the ATmega32, so could send you over the C code for these if you would like? There are other effects I have coded which might be of interest too, even if just to show what goes on my mad programmer's mind!?
Mar 6, 2012. 3:03 AMristdaro says:
Hi Triumph,

I've tried following your instructions regarding the new animations. I get the following error when I try to compile

effect.c:279: error: 'FF_DELAY' undeclared (first use in this function)

I'm not sure if I've missed something. Where should this be defined?

any help appreciated
Mar 6, 2012. 3:07 AMtriumphtotty says:
Hey, if that's all I missed I did OK!!  Just add the line
#define FF_DELAY 500
at the top near the other define statements in effect.c
Let me know how you get on!
Mar 11, 2012. 1:09 AMchaserled says:
Hi triumph,' i have a question for you , if i want to add in the effect spheremove and linespin it is posible? if so how to add in?
Mar 11, 2012. 4:35 AMtriumphtotty says:
It's possible.  The original code within cube_pc is written for a full computer, so it expects (a) something fast, e.g. 1GHz or faster and most importantly (b) it expects a fast floating point arithmetic unit.  Floating point numbers, e.g. doing 3.5*sin(0.7) are very, very fast on a proper computer.

The ATmega32 does NOT have any ability to do floating point maths internally, so these are emulated in integer maths.  Any time you do (float)3.5+(float)101.2 it takes tens of processor cycles.  sin(x) takes hundreds of cycles and sqrt(x) takes thousands.

If you look at how I did int_ripples, the principle is the same for converting those other routines.  Work in BIG integers, then scale them down from 0-7 to plot on the cube at the end.  I wrote tottymath.c to do just that.  Right now there's just totty_sin and totty_cos, although I have a beta totty_sqrt which is VERY fast, using a Newtonian approximation.  There's a bit of that in int_ripples again, although the comments are a bit out of date.

Anyway, I'm out all day today, but will take a poke at spheremove later on, if only to tidy up totty_sqrt for once and for all.  :o)
Mar 6, 2012. 4:11 AMristdaro says:
Hey,

ok, that worked but now got a few more for you!

launch_effect.c:178: error: too few arguments to function 'int_ripples'
launch_effect.c:220: error 'x' undeclared
launch_effect.c:221: error 'y' undeclared
launch_effect.c:222: error 'z' undeclared

Thanks
Mar 6, 2012. 4:20 AMtriumphtotty says:
Aaaargh. That's the problem with taking code stubs out of context. I have NO idea why int_ripples was called like that.  Change the line to:
int_ripples(100,300);

The x,y and z declarations should be at the top of launch_effect.c within the launch_effect function.  Safest place is immediately above the fill(0x00); statement.  Just paste in:
unsigned char x,y,z;

Hopefully no more compiler errors...  Fingers crossed.  :o)
Mar 6, 2012. 6:18 AMristdaro says:
All working now. Really really great animations!!! thank you for sharing...

I love the ripples and sidewaves effects.

One last question. how do i get the ripple effect to last longer, its amazing !!!
Mar 6, 2012. 9:11 AMtriumphtotty says:
:o) So glad you like them! It's a great platform to program on. The two parameters for ripples are the iterations and delay, so just call it with:
int_ripples(200,500); to make it last twice as long, or:
int_ripples(200,400); to make it run faster and last longer.  You can concatenate these within the case statement, e.g.:
case 5:
  int_ripples(100,500);
  int_ripples(150,400);
  int_ripples(200,300);
  break;

Will make the effect run 3 times at different speeds one after the other.
Mar 9, 2012. 8:15 AMristdaro says:
Hi Triumph,

I've a question for you on the ripples effect

I've noticed that the wave stops short of using the full cube at layer 1 of the cube

Is there a reason for this or can I make an adjustment so that the effect uses layer 0 as well.

Thanks
Mar 9, 2012. 10:16 AMtriumphtotty says:
Hi Ristardo.  The weekend has started.  It's one of the joys/downfalls of integers.  z can be 3.  z can be 4.  But it can't really be anything in between!  So no nice z=3.5+3.5*sin(blah) will work in integers to give a value from 0-7.  But there are always ways of working round these things...

Flying blind, I think you need to find this line in int_ripples:
height=4+totty_sin(LUT,distance+i)/52;
and change it to:

height=(181+totty_sin(LUT,distance+i))/46;

totty_sin() returns a value from -181 to +181 (see comments for reason for using this range), so 181+totty_sin() should be a value from 0 to 362.
Dividing this by 46 should hopefully give a centred integer value from 0 to 7.

If that looks too "flat" top and bottom, try changing the 181 and 46 to 196 and 49, which should reduce the time spent at the top and bottom.

Hopefully the code and the explanation make sense!  With luck, it might even compile...  :o)
Mar 9, 2012. 11:04 AMristdaro says:
Triumph,

Thanks for the quick reply,

I've tried both sets of values and it looks great with 196 and 49 !!! It now also uses all the layers 0-7

Thanks again....

Mar 9, 2012. 8:58 PMchaserled says:
Hi ristdaro can you share the effect ripples that you are already change 0-7
i don't know how to change it , i had try but there are error when i compile
Mar 10, 2012. 2:45 AMristdaro says:
Hi Chaserled,

Here is my modified effect.c file

The modified line is

height=(196+totty_sin(LUT,distance+i))/49;

as per Triumphtotty's intructions
Mar 10, 2012. 4:14 AMchaserled says:
thank ristdaro
Mar 6, 2012. 5:26 PMchaserled says:
Hi triumph
i do the following from the Install new tottyeffect but the commend said ( Missing separator. stop. ) it look there is something missing?
Mar 7, 2012. 12:33 AMtriumphtotty says:
Hi there. I've put together everything into the C files and put it here:

http://www.instructables.com/file/F8JYOBUGZHK30NN/

The effects are all at the end, so if you want to reshuffle them you'll need to edit the case statements yourself as in INSTALL.TXT in my last message.

Cheers!

T
Mar 6, 2012. 10:39 PMtriumphtotty says:
The error should tell you which file (e,g, effect.c) and which line number. Let me know and I will take a look!
Mar 7, 2012. 2:18 AMchaserled says:
Hi triumph
this is the error Compiling: launch_effect.c
avr-gcc -c -mmcu=atmega32 -I. -gdwarf-2 -DF_CPU=14745600UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=launch_effect.lst -std=gnu99 -MD -MP -MF .dep/launch_effect.o.d launch_effect.c -o launch_effect.o
launch_effect.c: In function 'launch_effect':
launch_effect.c:9: error: 'x' undeclared (first use in this function)
launch_effect.c:9: error: (Each undeclared identifier is reported only once
launch_effect.c:9: error: for each function it appears in.)
launch_effect.c:9: error: 'y' undeclared (first use in this function)
launch_effect.c:9: warning: left-hand operand of comma expression has no effect
launch_effect.c:9: error: 'z' undeclared (first use in this function)
launch_effect.c:9: warning: left-hand operand of comma expression has no effect
launch_effect.c:177: error: too few arguments to function 'int_ripples'
Makefile:460: recipe for target `launch_effect.o' failed
make: *** [launch_effect.o] Error 1

Mar 7, 2012. 4:28 AMristdaro says:
Chaserled,

I've attached a copy of my modified files.

Just compile and you are good to go
Mar 10, 2012. 12:34 PMbrucesallen says:
I thank you too. I also have it working!! Long live ATMEGA generated waves.
Mar 7, 2012. 4:46 PMchaserled says:
thank alot ristdaro for sharing the file
Mar 7, 2012. 3:33 AMtriumphtotty says:
If you read the other comments in this thread, ristdaro had the same problems.  It's VERY hard to take code stubs out of context from the main program.  (My other files are all hacked to bits, my wiring is non-standard, and I don't have any RS232 interface, so I cannot easily post my code as a whole unfortunately!)

Make these changes to launch_effect.c:

Change the line int_ripples(100) to:
int_ripples(100,300);

The x,y and z declarations should be at the top within the launch_effect function.  Safest place is immediately above the fill(0x00); statement.  Just paste in:
unsigned char x,y,z;
Mar 16, 2012. 2:10 PMchaserled says:
Hey triumph is possible if i used atmega16 instead of atmega32?
Mar 16, 2012. 11:44 PMtriumphtotty says:
 Hi! You definitely can, but it won't be completely straightforward for a couple of reasons. From memory, Chr's default code compiles to just over 16384 bytes (perhaps 16600?) so you may need to remove some code. There are some routines in draw.c (line, for example) which are never used, so that would be all you would need to do to get the code size down.  For obvious reasons, there won't be enough space to add any new effects without clearing out old ones.

Secondly, the 16 on has 1K of RAM and the 32 has 2K, so there might be some effects which won't run in just 1K.

Note that although the 16 is pin and code compatible, it is not binary compatible, so the code must be specifically compiled for it.  You cannot use the test.hex code for example.  You need to change the first line in the Makefile to MCU=atmega16 and recompile.
Mar 7, 2012. 7:19 PMchaserled says:
thank alot Triumph the cube work fine now i really like the way you write effect ,
u are a big help for me buddy, again truely thank to your hard work Triumph
wish you have a wonderful life buddy
Mar 8, 2012. 2:00 AMtriumphtotty says:
Hey, you're welcome.  Programming has been a hobby of mine since I was 10 or 11, so it's nice to see it appreciated!

I'm always fiddling and changing my code.  Should I keep posting stuff in here?  Maybe start my own Instructable on coding and effects?

Just remember none of this would be possible without the genius of Chr et al.  Truly we stand on the shoulders of giants!
Mar 9, 2012. 6:45 AMristdaro says:
Hey Triumph,

Check the video, some of the best animations I've seen

May give you a few ideas !!!! :o)

http://www.youtube.com/watch?v=03bkigwYOx0&context=C346dbdaADOEgsToPDskJy6EYiZ-m3BJ5MaZ1ny1M_
Mar 9, 2012. 1:52 AMchaserled says:
Hey triumph that is a great gift to me if you are going to do that i really appreciate your spouse and sharing your knowledge .......
Mar 8, 2012. 10:34 AMristdaro says:
Hey triumph,

that sounds like a great idea. I would definitely be interested in seeing more of your creations.

Thanks again for the coding you've shared so far.
Mar 5, 2012. 11:19 AMristdaro says:
Hi Triumph,

Could you please share the C code for the animations with me also. It would be nice to see them running on the ATMEGA32
Mar 4, 2012. 3:32 PMchaserled says:
yeah! Trium i really expected for your help, i like those effect it look really nice,
could you send it to me over the C code? and you said you have more effect code that made me feel very interested ...
Mar 6, 2012. 12:09 AMtriumphtotty says:
http://www.instructables.com/file/FM0TVAEGZGBNPTS/

I'm in a bit of hurry, but quickly scribbles some install instructions for the new effects.  Should be OK.  Message me if anything goes wrong!
Mar 7, 2012. 3:01 AMchaserled says:
(removed by author or community request)
Mar 7, 2012. 3:36 AMtriumphtotty says:
Which text editing program are you using to edit Makefile?

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
651
Followers
7
Author:chr
I like microcontrollers and LEDs :D