Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Simple DMX Transmitter


  • Please log in to reply
7 replies to this topic

#1 Tecchie

Tecchie

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationGermany

Posted 06 March 2011 - 05:50 PM

Generating DMX data with Netduino is quite simple, as DMX is just (more or less) a serial RS485 protocol. Its properties are 250kbit/s, 8 data bits, no parity bit, 2 stop bits. So you don't have to manually bitbang to generate the DMX data, but one can use one of the netduino UARTs.

Of course you have to convert the ttl serial signal into the differential RS485 form, but there are many ICs out there, which do just that. I'm using the simple SN75176B in my example as i had that one lying around, but depending on which fancy features you want to have (ESD protection, galvanic isolation, ...) you may use another one.

But there's one feature in the DMX protocol which interferes with just using the serial port. That's the >88µs break (setting signal to low) which marks the beginning of a new dmx data frame. On the full blown .NET the SerialPort class has a Break property which can be used to generate the break, but i haven't seen that on the micro SerialPort class.

So i had to do it in another way. I'm generating the break on a seperate pin (D4 in my example) and use an AND-gate to combine the serial output and the break signal. I'm using one of the gates of a 74HCT32 74HCT08 IC.

The code side is quite simple. Just create a SerialPort with the correct properties and the OutputPort for the break signal. For each dmx frame generate the break and then send the data, up to 513 bytes for the start code (0x00 for DMX data) and a full blown DMX universe (512bytes). To get a correct length of the break, i'm just calling Write two times on the OutputPort which results in a ~110µs break on my Netduino Plus.

    public class Program
    {
        // data for a whole universe including start code (which must be zero for DMX data)
        private static byte[] data = new byte[513];

        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            // init test bytes
            for (int i = 0; i < data.Length; i++)
            {
                // first byte (=start code) must be zero for DMX data
                data[i] = (byte)i;
            }

            OutputPort pBreak = new OutputPort(Pins.GPIO_PIN_D4, true);
            SerialPort sp = new SerialPort(SerialPorts.COM2, 250000, Parity.None, 8, StopBits.Two);
            sp.Open();

            while (true)
            {
                led.Write(true);
                // create the break (2x Write(false) to get a break length of >88µs)
                pBreak.Write(false);
                pBreak.Write(false);
                pBreak.Write(true);
                // rely on .net lazyness for 8µS Mark-after-Break
                sp.Write(data, 0, data.Length);
                led.Write(false);

                Thread.Sleep(40);
            }
        }

    }

In the specification of DMX there's a 8µs Mark-after-Break between the break and the serial data in which the signal should be high. I'm not explicitly generating that as the Write-Call on the serial port already takes much longer to start sending the data.

Disclaimer: i've only tested it with my really old DMX tester, not with any actual lighting fixture. But it should work with those :)

[edit: corrected small error in fritzing diagram]
[edit2: corrected IC name, sorry for the confusion]

Attached Files



#2 David Kallesen

David Kallesen

    New Member

  • Members
  • Pip
  • 2 posts

Posted 05 April 2012 - 12:31 AM

I am trying to build a DMX controller with N+ (after I read about you great sample); But I am confused; you write that you use a 74HCT32 => AND-gate (also on the IC in picture), but that is a OR-gate as can see on different web pages. Correct me if I am wrong, please. - Before I connect something wrong. /Regards David

#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 05 April 2012 - 12:09 PM

I am trying to build a DMX controller with N+ (after I read about you great sample);

But I am confused; you write that you use a 74HCT32 => AND-gate (also on the IC in picture), but that is a OR-gate as can see on different web pages.

Correct me if I am wrong, please. - Before I connect something wrong. /Regards David


Here is some info about the DMX: http://en.wikipedia.org/wiki/DMX512
Here about the line driver: http://www.ti.com/li...nk/sn75176b.pdf

Agree: it should be a 74HC08. The operation needed is an AND. Look here: http://www.nxp.com/d.../74HC_HCT08.pdf


Also I suggest a couple of resistor on the output wiring. One 1Meg pullup at pin 6, and one 1Meg pulldown at pin 7 (of the 75176). That prevents undefined reception at the receiver side, when there's no enable of transmission.

The solution is a bit hacked, and delicate, but worthy the same.
Good point.
Cheers
Biggest fault of Netduino? It runs by electricity.

#4 martinarcher

martinarcher

    Member

  • Members
  • PipPip
  • 16 posts

Posted 06 April 2012 - 03:04 AM

I have built this shield as well with the 74HCT32 and had no luck and then realized after looking up the datasheet it's an OR chip. I replaced it with a SN74HCT08N AND chip and am still struggling to get any DMX output from the shield at all with the above code. I agree with the guys above that the functionality of the code makes sense combining the serial and a digital pin, but certainly calls for an AND chip. I've used the same 485 chip and shield (minus the AND chip) with an Arduino sketch and it works fine. Anyone have any ideas of why the above code and shield drawing wouldn't work? I am using the same SN75176B line driver/485 chip. Thanks all!

#5 martinarcher

martinarcher

    Member

  • Members
  • PipPip
  • 16 posts

Posted 07 April 2012 - 08:57 PM

I figured it out...in the code above I was hard coding all elements of the data array to 254 (all on). The first element must have the value of 0 for the DMX controller to operate...the following 512 elements contain the data for the controller's channels.

#6 dx9s

dx9s

    Member

  • Members
  • PipPip
  • 12 posts

Posted 13 April 2012 - 02:57 PM

Thanks for the info... I wasn't sure if the serial port was able to do 250 kbps ( http://msdn.microsof...y/ee425155.aspx ) ... I did see the ability to set the two stop bits and was curious about how to do the break. I plan to make a DMX interface too.. I'll probably get the MAX 485 driver and look into some transistor based logic AND (or wire or).. I haven't looked at the TTL levels closely to see which is required to "add" a break line. I plan to port some code that I've been running on PC over to my NF (for simulating candle flickering and driving DMX dimmer pack) -- off topic: when I say simulate.. I mean SIMULATE. I've even convinced (tricked) a few times folks into thinking my simulation was a real candle. --Doug

#7 Mercer

Mercer

    Member

  • Members
  • PipPip
  • 17 posts

Posted 27 April 2012 - 09:05 PM

Is it normal for the SN75176B to become hot. The chip is so hot I cannot touch it. I am running 5v directly from the board and have it wired as shown in the diagram. Any ideas?

#8 Tecchie

Tecchie

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationGermany

Posted 09 May 2012 - 08:55 PM

Sorry for the confusion about the IC name and the late response. I haven't been here for a longer while. But Mario kindly helped out.

Also I suggest a couple of resistor on the output wiring. One 1Meg pullup at pin 6, and one 1Meg pulldown at pin 7 (of the 75176). That prevents undefined reception at the receiver side, when there's no enable of transmission.


The transmit enable pin is hardwired to logic high in my example, so transmission is always enabled. So these bias resistors are not necessarily needed here, but one may add them.

The solution is a bit hacked, and delicate, but worthy the same.


Of course, it's a bit of a hack. The two common solutions on a µC would be either to set the break flag in the UART register or decrease the baud rate and send 0x00. Unfortunately both options are not available on the netduino/.NET Micro Framework. The Break property on the SerialPort class is only available in full .NET and changing the baud rate while leaving the port opened isn't allowed (at least when i tested that).

Thomas




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.