Home arrow Tutorials arrow Software arrow Light Sequencing and Decoding DMX with an Arduino
Light Sequencing and Decoding DMX with an Arduino | Print |
Written by Akiba   
Monday, 31 October 2011

It's been a while since I posted anything and that deserves another post just to talk about everything that happened in the last 8 months since the March earthquake and tsunami here in Japan. I'm a little bit tired of heavy topics and serious projects so I thought I'd put together a little something that's kind of fun and also timely. Now that we're moving into the holiday season, we're about to start seeing the hard core Christmas people setting up the elaborate light displays. The equipment to switch all the lighting channels and sequence everything is usually a bit costly but it doesn't have to be. If you're familiar with the Arduino environment and willing to put in a bit of elbow grease, blinging out your lawn is just a couple of mouse clicks away :)

I put this three part video tutorial together on how to use the Arduino platform to decode the DMX protocol. The DMX protocol is a standard protocol for stage lighting displays and it happens to be supported by a nice freeware light sequencer called Vixen. In the first part, I go over the DMX-512 protocol and the Arduino source code to decode it. In the second part, I show how to configure a lighting sequence with Vixen, some hardware implementations, and the whole system working together. And in the final part, I show how some simple changes to the code can enable you to control your lights wirelessly.

You can download the source code here.

Note: A sample of the modified "HardwareSerial.cpp" is also included as a reference on how to modify the one inside your particular Arduino IDE installation. I'd recommend using a fresh installation of the Arduino IDE to try this tutorial out. The reason is that the HardwareSerial.cpp file needs to be modified and this may break other Arduino projects you might have. 

Hope you enjoy :)

 

 

 


Updated 2011-11-06: I just checked the latest version of Vixen and they no longer use the name DMX-512 for the DMX plugin. They now use the name "Enttec Open DMX" but it maps to the same DMX-512 DLL. Also, I forgot to mention but the DMX plugin looks specificatlly for FTDI USB/Serial chips which are standard for OpenDMX devices. Please see picture below:

 

Updated 2011-11-06: I've been getting a couple of questions about the boards in the videos. Regarding the devices that I'm using, one of them is an Arduino-platform based breadboard I designed for Tokyo Hackerspace. As of this writing, those are not yet released to the public. Mostly I need to finish up the documentation on them. In the third tutorial, I'm using the Freakduino which I sell in my webshop. Here is the link . Its also possible to use any Arduino based board that has an FTDI USB/Serial IC to connect to a PC/Mac.
Hits: 40716
Trackback(0)
Comments (14)Add Comment
PWM lights
written by sydkahn, November 02, 2011
Just wondering if I could put the values from the channel(s) on one of the PWM pins - The DMX protocol sends 8 bit values for each channel doesn't it?

I built an expensive controller with 16 channels of triacs and such - it does variable light levels not just the On/Off in your tutorial. http://www.diylightanimation.c...al_Express

It would be very cool if I could do just a few channels with variable levels and some bright LEDs inside for cheap.
report abuse
vote down
vote up
Votes: +2
...
written by Akiba, November 02, 2011
Yes, that's actually an easy modification. In the decoder, you can check whether the pin is a PWM pin. If it is, then you can just do an analogWrite to that pin with the value from the DMX channel. I was going to add that as a tweak as well, but figured three videos was pretty much. Might come later.
report abuse
vote down
vote up
Votes: +10
New to DIY projects
written by Charles Candles, November 05, 2011
Was wondering if the is a place where i can get more information about "HardwareSerial.cpp" changes. I try several thing, including replacin/utilizing the exmaple provided.
The "HardwareSerial.cpp" has a different sequence of event and after several tries of commenting different areas/segments I have not been succsesful to compile.

Any help or guidance is apreciate it.
report abuse
vote down
vote up
Votes: +0
...
written by Akiba, November 05, 2011
Hi Charles. Sorry about the confusion. My modified file was from Arduino 0021. For Arduino 0022 (or any other version), you can just comment out the whole block of code for the UART ISR. In 0022, it would be from line 80 to line 167. Here is an example from the HardwareSerial.cpp in 0022:

/* Commenting out the ISR from HardwareSerial.cpp

#if defined(USART_RX_vect)
SIGNAL(USART_RX_vect)
{
#if defined(UDR0)
unsigned char c = UDR0;
#elif defined(UDR)
unsigned char c = UDR; // atmega8535
#else
#error UDR not defined
#endif
store_char(c, ℞_buffer);
}
#elif defined(SIG_USART0_RECV) && defined(UDR0)
SIGNAL(SIG_USART0_RECV)
{
unsigned char c = UDR0;
store_char(c, ℞_buffer);
}
#elif defined(SIG_UART0_RECV) && defined(UDR0)
SIGNAL(SIG_UART0_RECV)
{
unsigned char c = UDR0;
store_char(c, ℞_buffer);
}
//#elif defined(SIG_USART_RECV)
#elif defined(USART0_RX_vect)
// fixed by Mark Sproul this is on the 644/644p
//SIGNAL(SIG_USART_RECV)
SIGNAL(USART0_RX_vect)
{
#if defined(UDR0)
unsigned char c = UDR0;
#elif defined(UDR)
unsigned char c = UDR; // atmega8, atmega32
#else
#error UDR not defined
#endif
store_char(c, ℞_buffer);
}
#elif defined(SIG_UART_RECV)
// this is for atmega8
SIGNAL(SIG_UART_RECV)
{
#if defined(UDR0)
unsigned char c = UDR0; // atmega645
#elif defined(UDR)
unsigned char c = UDR; // atmega8
#endif
store_char(c, ℞_buffer);
}
#elif defined(USBCON)
#warning No interrupt handler for usart 0
#warning Serial(0) is on USB interface
#else
#error No interrupt handler for usart 0
#endif

//#if defined(SIG_USART1_RECV)
#if defined(USART1_RX_vect)
//SIGNAL(SIG_USART1_RECV)
SIGNAL(USART1_RX_vect)
{
unsigned char c = UDR1;
store_char(c, ℞_buffer1);
}
#elif defined(SIG_USART1_RECV)
#error SIG_USART1_RECV
#endif

#if defined(USART2_RX_vect) && defined(UDR2)
SIGNAL(USART2_RX_vect)
{
unsigned char c = UDR2;
store_char(c, ℞_buffer2);
}
#elif defined(SIG_USART2_RECV)
#error SIG_USART2_RECV
#endif

#if defined(USART3_RX_vect) && defined(UDR3)
SIGNAL(USART3_RX_vect)
{
unsigned char c = UDR3;
store_char(c, ℞_buffer3);
}
#elif defined(SIG_USART3_RECV)
#error SIG_USART3_RECV
#endif

*/
report abuse
vote down
vote up
Votes: +2
Re:Light Sequencing and Decoding DMX with an Arduino
written by gbmhunter1, October 01, 2012
I just had a look at HardwareSerial.cpp in the latest Arduino release (v1.0.1), and it looks like it has been changed again from the '022' version.

I couldn't get Vixen to talk to my Arduino (the RX interrupt was never being triggered), I have a got a feeling it is because I have the new HardwareSerial.cpp version and don't know enough to comment out the correct parts.
report abuse
vote down
vote up
Votes: +1
Light Sequencing and Decoding DMX with an Arduino
written by FEK_, October 05, 2012
Same problem here : the latest release (v1.0.1) has been changed from the '022' version.

Any idea to how properly comment the good lines for HardwareSerial.cpp ?
report abuse
vote down
vote up
Votes: +0
...
written by FEK_, October 05, 2012
Dear gbmhunter1,

Check out below in discuss section, we need to comment 1.0.1 differentely.

All works now.

Best regards
report abuse
vote down
vote up
Votes: +0
Commenting out the Arduino Hardware serial.cpp to run DMX sequences
written by Shawn Styrcula, May 20, 2013
I have not been able to find current instructions on how to comment out the hardwareserial.cpp. Can anyone help me find an example of how to do this?
report abuse
vote down
vote up
Votes: +2
...
written by Akiba, June 04, 2013
Hmm...I probably need to update this post since there seems to be quite a bit of interest in this. Let me think about different ways to make it easier. When I first did it, I didn't really think others would be very interested in it.
report abuse
vote down
vote up
Votes: +1
Arduino Uno -DMX 512 ???
written by Peter Chan, July 18, 2013
Hi, Akiba
I have Arduino UNO and now I see that it can't control DMX lamp cuz there are no FTDI chip. Vixen send me a error (error opening ftd2xx device 0).Can I buy or do something to control the RGBW lamp with DMX protocol and Arduino Uno ? Or must change it with other arduino (I have Leonardo) ? smilies/sad.gif

p.s. Great job with your tutorials
report abuse
vote down
vote up
Votes: +0
...
written by Akiba, July 19, 2013
Yeah, for Vixen's DMX output, it looks for an OpenDMX device which is based on an FTDI chip. You might be able to trick Windows into thinking you support OpenDMX by modifying the USB descriptors the Arduino Uno is sending to the PC, but it might be easier to just get an FTDI based board.
report abuse
vote down
vote up
Votes: +1
...
written by Peter Chan, July 19, 2013
Can you give me a link or some direction, how to modifying the usb ?
If I buy a FTDI Cable, are you sure it will work with Arduino uno and your sketch? I want to control RGBW led with DMX protocol and arduino uno?
Can I control all of the light with only one RGBW led ? If I can please write me.
report abuse
vote down
vote up
Votes: +0
Vixen has serial output
written by syd, July 19, 2013
read here
http://doityourselfchristmas.c...-Arduino!
report abuse
vote down
vote up
Votes: +0
...
written by Akiba, July 20, 2013
If you're trying to build your own RGB lamp, then I'd probably not use DMX. Vixen's generic serial is easier to work with. If you want to control a DMX device with Vixen, then you'll need an FTDI chip to extract serial data. Then you'll need to get that data into the Arduino. It shouldn't be too difficult to do that though and you basically just need to attach wires from the FTDI output to the serial input of the arduino.
report abuse
vote down
vote up
Votes: +0

Write comment

busy
 

Discuss (65 posts)
Michael Morlan
Re:Light Sequencing and Decoding DMX with an Arduino
Feb 18 2012 16:17:46
Thanks, in advance, for taking the time.
#3938
Michael Morlan
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 22 2012 14:17:35
Hi Akiba,

Thanks, again, for sharing your project. I'm not sure why I couldn't replicate your results.

I finally gave up trying to get your code to work on my setup and found success with the DMXSerial library created by Matthias Hertel over at http://www.mathertel.de/Arduino/DMXSerial.aspx.

Best,

Michael
#4623

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 23 2012 00:42:51
Sorry about not getting back to you. Things got super hectic over here. But thanks for sharing the link. I'd like to check it out and see if there's anything I can learn from his project. Good luck on yours!
#4631
Michael Morlan
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 23 2012 14:16:58
You've been very generous to share your own projects. Thank you.

I now have a Boarduino driving a 2x16 LCD and TLF5940 chip. The TLF chip drives two hobby servo motors on a pan/tilt rig and a ULN2803 transistor array to a 3w RBG LED.

I have a multi-channel DMX scheme, much like intelligent moving heads, with acceleration/deceleration functions to handle smooth movement of the servos.

Having a lot of fun.

Michael
#4658
j reckart
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 26 2012 12:11:59
Michael Morlan wrote:
QUOTE:
You've been very generous to share your own projects. Thank you.

I now have a Boarduino driving a 2x16 LCD and TLF5940 chip. The TLF chip drives two hobby servo motors on a pan/tilt rig and a ULN2803 transistor array to a 3w RBG LED.

I have a multi-channel DMX scheme, much like intelligent moving heads, with acceleration/deceleration functions to handle smooth movement of the servos.

Having a lot of fun.

Michael


I'd be very interested in your moving light project! I have always thought of doing that. Can you post more specifics, schematics , pictures, or videos?

Jr
#4708
Michael Morlan
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 26 2012 15:47:56
Yes, of course. I'm still debugging the acceleration algorithm (which is essentially a simple, physics-based accel/de-accel routine rather than a math-based s-curve calculation.)

I'm not sure where best to post the project. Akiba, is it okay to post in this thread or do you recommend another forum?

Michael
#4709
j reckart
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 05 2012 23:27:29
I would like to build a wall mounted DMX controller that would fit into a single gang box. I would like to have maybe four buttons on the faceplate, that i would pre-program to various "scenes" for a church, ie full on, full off, worship, prayer.

the Arduino would do this, but i have a twist. I would sometimes control the lights with full DMX console. so i would want to have the Arduino be a "middle man".

DMX Console --> Arduino wall mount controller --> wire to dimmer packs --> lights

I would want the DMX to check for an incoming signal, and if none is found act as a DMX master and "take over" sending the signal down the line, according to which scene's button was pressed.

But if it detects a signal, I would want it to "repeat" the incoming signal from my Console down the line.

Is the Arduino Robust enough, or fast enough to do this?

JR
#4971

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 06 2012 00:42:39
No problem to post it here
#4974

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 06 2012 00:45:19
I think you'd have to check to see if there is any speed issue on the Arduino. At 8 MHz, which is what the Freakduino runs at, I can decode the DMX and send/receive wireless data. For standard Arduinos, they run at 16 MHz so you can theoretically get twice the performance (or utilization) out of them. So in theory, you should be able to both decode, toggle lighting, and forward the data.
#4975
j reckart
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 06 2012 13:01:10
Is there an appropriate spot here that i can start a discussion on this? I would be using the full arduino, not the freakduino, but the folks here seem to be morte friendly and helpful that other places. I would be willing to post all info or schematics to help others also.
thanks JR
#5013

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 06 2012 23:47:04
Ha ha ha. Start away. Might be good to use a new thread though. I'm actually starting up a project in Tokyo Hackerspace for DMX light sequencing for some stage work using an Arduino so I should be actively developing on the software too.
#5032
Mitch
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 22 2012 13:51:02
Hi everyone. I'm new to the forum and I'm glad I've found this precious resource.

In particular, I'm planning to realize an arduino-based project involving wireless DMX lighting control.

I've consulted the tutorial above and I think it is brilliant work. Actually, I'm planning to realize this with a RFM12B transmitters (they are very cheap and support 115K baud rate, on paper at least). What I want to do is connect a PC running e.g. FreeStyler (multi-platform lighting control software) to an arduino which will then send DMX data via the RFM12 transmitter to a RFM12 receiver on another arduino board which in turn will be connected to the 3-pin DMX input of a fixture (e.g. a scanner, moving head or LED PAR).

The above I think is covered by the tutorial (with some tweaking due to the different wireless protocol). However, I'll also need to get going with the DMX "daisy-chain" to more fixtures (e.g. PC -> LED PAR -> scanner -> Laser -> moving head -> 120ohm DMX terminator). All this I'm planning to realize wirelessly.

The problem I see is in using only 1 arduino per fixture to manage both the DMX input TO the fixture and the forwarding of the DMX output FROM the same fixture to the next light in the daisy-chain.

Would in your opinion 1 arduino uno board be capable of processing both Input and Output streams? would 2 separate RFM12 transmitters per board be needed? Is it possible to go for a point-multipoint wireless solution where, instead of a "chain" of fixtures, the first arduino connected to the PC broadcasts the DMX universe separately to all receiving arduinos and lights connected thereto? This I think could be possible as I understand that the DMX protocols works by addresses so that every light only takes into account the part of the signal addressed to it and just forwards the DMX signal stream without processing.

As you see I'm in pre-alpha stage here. Any suggestion would be highly appreciated.

Also, do please move this post as appropriate.

Sorry if I've been long. Thank you very much for your appreciated attention =)
#5482

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 23 2012 01:55:03
I don't think you'd want to decode the data and then re-encode the data to forward it. I would probably recommend tying the DMX input pins to the DMX output pins for the forwarding. Then tap off the input pins to the Arduino to decode the data. That way, you won't have to burn CPU cycles re-encoding things. Even processing 250kbps serial data is a huge burden on the Arduino.
#5490
Michael Morlan
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 23 2012 16:01:40
Yes, exactly. Tap off a pass-thru DMX circuit. (Don't forget to have a 120ohm terminator on the last DMX device in the line.)

M
#5508
Alex
Re:Light Sequencing and Decoding DMX with an Arduino
May 10 2012 21:05:34
Hello.I have a question. I made the same(as on video), but on usb cord. But when i connect Xbee- light-emitting diodes stop to blink. What Wireless you used, and what setting is?
can i do the same using Xbee? Explane plz how to make it!
I use arduino, xbee shield, and xbee 2 series
#6259
Kevin McLoughlin
Re:Light Sequencing and Decoding DMX with an Arduino
Nov 05 2012 22:58:21
I have just made a similar setup using and arduino uno r2 and v1.01
Vixen - Enttec Open DMX - USB-RS485 (FTDI Adaptor cable) - max 485 chip output to RX pin on Uno.
I have added a line to Akib`s setup code... and left in (commented out) a couple of other things i tried. Not sure why it works but it does!
Thanks for this excellent site, i would be totally lost without the help of the software guys.

void setup()
{
// set update flag idle
update = 0;

// set default DMX state
dmx_state = DMX_IDLE;

// set DMX pins to ouput and idle value
for (int i=0; i<DMX_NUM_CHANNELS; i++)
{
pinMode(dmx_pin[i], OUTPUT);
//pinMode (13, OUTPUT);
digitalWrite(dmx_pin[i], LOW);
}

// initialize UART for DMX
// this will be 250 kbps, 8 bits, no parity, 2 stop bits
//UCSR0C |= (1<<USBS0);
// NEXT LINE PUT IN TO ENABLE REC AND REC COMP INTERUPT
//UCSR0B = (1<<RXEN0) | (1<RXCIE0);
// From ATmeg manual
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
Serial.begin(250000);
}
#8953
Eddie Noyes
Re:Light Sequencing and Decoding DMX with an Arduino
Feb 01 2013 04:37:16
Maybe I'm missing something, and I feel a simple answer exists so excuse me if this is already posted on another thread.

I have the DMX receiver working with the software through the USB, but I'd like to make this a standalone device that can accept DMX input from another lighting console through a max485 chip and the pins on the arduino. What modifications need to be made in the code for this to work? I'm relatively new to digital logic design and the arduino platform itself, so any help would be greatly appreciated.
#10497

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Feb 01 2013 07:30:28
The USB looks just like a serial port from the Arduino's perspective. If you want to make it standalone from a 485 transceiver, just connect the serial pins from the RS-485 chip to the Arduino's serial pins. Don't forget to terminate the RS-485 properly.
#10500
Eddie Noyes
Re:Light Sequencing and Decoding DMX with an Arduino
Feb 02 2013 00:06:18
Thanks so much. This is one of the most helpful forums I've found on the topic so far.
#10507
Eddie Noyes
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 25 2013 03:21:02
I finally had the opportunity this past weekend to prototype a DMX reception circuit to dim an LED up and down using an external DMX controller. I had some issues, the main being that the LED flickers the entire time, and ch 2 on the controller decides that it also wants to control the LED. I made a video demonstrating this and offering a better explanation to my problem, any help would be great. I wasn't sure if anyone else here was having the same problem as I am. I would like to get this working to control strips of red, green, and blue, thus the reason my code has 3 channels declared.

Video:
http://www.youtube.com/watch?v=ZzbTI0iwSjU&feature=youtu.be

Code:
QUOTE:

#define DMX_NUM_CHANNELS 3

enum
{
  DMX_IDLE,
  DMX_BREAK,
  DMX_START,
  DMX_RUN
};

volatile unsigned char dmx_state;

// this is the start address for the dmx frame
unsigned int dmx_start_addr = 1;

// this is the current address of the dmx frame
unsigned int dmx_addr;

// pins that will toggle based on dmx data
unsigned char dmx_pin[DMX_NUM_CHANNELS] = {9,10,11};

// this is used to keep track of the channels
unsigned int chan_cnt;

// this holds the dmx data
unsigned char dmx_data[DMX_NUM_CHANNELS];

// tell us when to update the pins
volatile unsigned char update;

/**************************************************************************/
/*!
  This is the setup code
*/
/**************************************************************************/
void setup()
{
// set update flag idle
update = 0;

// set default DMX state
dmx_state = DMX_IDLE;

// set DMX pins to ouput and idle value
for (int i=0; i<DMX_NUM_CHANNELS; i++)
{
pinMode(dmx_pin[i], OUTPUT);
//pinMode (13, OUTPUT);
digitalWrite(dmx_pin[i], LOW);
}

UCSR0C = (1<<USBS0)|(3<<UCSZ00);
Serial.begin(250000);
}

/**************************************************************************/
/*!
  This is where we translate the dmx data to the pin outputs
*/
/**************************************************************************/
void loop()
{
  if (update)
  {
    update = 0;
    
    for (int i=0; i<DMX_NUM_CHANNELS; i++)
    {
     analogWrite(dmx_pin[i], dmx_data[i]);
    }
  }
}

/**************************************************************************/
/*!
  This is the interrupt service handler for the DMX
*/
/**************************************************************************/
ISR(USART_RX_vect)
{
  unsigned char status = UCSR0A;
  unsigned char data = UDR0;
  
  switch (dmx_state)
  {
    case DMX_IDLE:
      if (status & (1<<FE0))
      {
        dmx_addr = 0;
        dmx_state = DMX_BREAK;
        update = 1;
      }
    break;
    
    case DMX_BREAK:
      if (data == 0)
      {
        dmx_state = DMX_START;
      }
      else
      {
        dmx_state = DMX_IDLE;
      }
    break;
    
    case DMX_START:
      dmx_addr++;
      if (dmx_addr == dmx_start_addr)
      {
        chan_cnt = 0;
        dmx_data[chan_cnt++] = data;
        dmx_state = DMX_RUN;
      }
    break;
    
    case DMX_RUN:
      dmx_data[chan_cnt++] = data;
      if (chan_cnt >= DMX_NUM_CHANNELS)
      {
        dmx_state = DMX_IDLE;
      }
    break;
    
    default:
      dmx_state = DMX_IDLE;
    break;
  }
}

#12536
Eddie Noyes
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 25 2013 03:22:46
I also don't want anyone to get the wrong impression, I don't claim any ownership of this code, it was all borrowed from earlier posts on this thread. I really only added the analogWrite line instead of using the digitalWrite.
#12537

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 25 2013 03:26:59
How many channels are you decoding?
#12538
Eddie Noyes
Re:Light Sequencing and Decoding DMX with an Arduino
Mar 25 2013 03:43:44
Right now for testing purposes I only have 1 LED hooked up, however the code is ready to use 3 channels for RGB using PWM pins 9,10,11 on the Uno.
#12539
Danny
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 01 2013 23:15:57
For starting quickly writing you arduino dmx master or slave app you might want to take a look at the following library: http://sourceforge.net/projects/dmxlibraryforar

It is a uart based library and still under development but support all basic functionality required to get running.

If you want advice on shields to use just leave me a message.
#13224

Akiba
Re:Light Sequencing and Decoding DMX with an Arduino
Apr 01 2013 23:56:42
Nice. Thanks for the link!
#13243
There are too many comments to list them all here. See the forum for the full discussion.

Discuss...
< Prev   Next >