Serial to DMX project Questions

Hello everyone,

after browsing through the forums I'm significantly inspired to take on a project of my own, with the aim of being able to control many DMX lighting fixtures, reliably and "smoothly" using MaxMSP and/or PureData cheaply, using an Arduino.

So far I've managed to control a 4 channel RGB LED lamp with my Arduino via RS232, using the DMXsimpe library [Google Code Archive - Long-term storage for Google Code Project Hosting.] and a 75176 chip with great success.

But, I would like to wrap up and "finish" the project, so I'm left with a box which I can plug in and use like any other peripheral. I've got a loose plan of how I'm going to do it, but I have a few questions which my weak google-fu has left unanswered:

1) Is the data rate of RS232 potentially fast enough to update 256 channels of DMX?

At present my slightly ham-fisted approach is to send a channel-value pair, to set channel X to value Y, in ASCII over serial, formatted CCC:VVV where CCC is the channel number (1-512) and VVV is the value (0-255) which I realise is a very inefficient way to send this data.

If I represent and send the channel number as two ascii characters, for example "1d" would represent channel 149 (1 being ASCII char 49 + and d being 100) and the value in the same way, that would save significant bandwith, but would it be enough to cram 256 channels with their values down RS232? Can anyone suggest an even more bandwidth-efficient way of sending these channel-value pairs?

Also, using serial, what is the calculation for working out how much useable bandwidth you have available for a given baud rate? For example, sending 4 ASCII characters over 9600/no parity/8 data bits/1 stop bit, would the calculation be

(9600 bits per second / (8 data bits + 1 stop bit) ) / (4 ASCII characters * 7 bits per character) = 38 lots of 4 ASCII characters per second

Is that anywhere near correct?

2) Will the ATMega328 be able to update all 256 channels at a rate of at least 25Hz?

This may be a question for the makers of the DmxSimple library, but would you imagine the ATMega328 to be fast enough to receive over serial and update 256 channels of DMX (with their 256 values) at least 25 times a second?

From Ujjal's DMX pages: [dmx512-online.com/packt.html]

"The following is a mathematical layout of the typical DMX512(1990) timing :-

[(88)+(12)+(44)+(CHL44)+(CHLMTBF)+(MTBP)] microsecs

Where CHL is the no of Channels under consideration.

The ideal timing ( this is purely my personal opinion) :-

[(120)+(12)+(44)+(CHL*44)+(0)+(50)] microsecs

For 512 channels my timing would be 22754 microsecs.

Thus the refresh rate = 1000000 / 22754 = 43.9 or 44 Hz"

3) Can the ATMega328 receive RS232 without additional hardware?

Once I've finished prototyping on the Arduino board itself I'd like to burn the code to the ATMega328, take it out of the Arduino board and put the whole project on a circuit board. If I am to communicate with the chip over serial, can I do it quickly and reliably just using the chip alone? Or will I need to invest in another chip to handle this?

4) What precautions other than opto-isolators would you reccomend for connecting to potentially dodgy lighting rigs in venues?

Call me overcautios, but I dont feel comfortable connecting my project, and by proxy my laptop to a venue's dodgy lighting system to potentially fry my stuff. I'm going to add opto-isolators into the finished system to reduce the chance of that happening, but would you reccomend any other precautions I could take to a) not damage my equipment, and b) not damage any lighting equipment?

This is my first serious electronics project and will no doubt be a learning curve, I would be massively grateful to any kind of answers to the above questions, or a point in the right direction.

I'll be documenting the project so that beginners like me in the future will find it easier to do this kind of thing. My ultimate goal is to make a cheap DMX controller to allow users of MaxMSP/Pd to control lighting fixtures quickly and reliably.

Many thanks in advance,

ilumos