Overview
DMX512 is the protocol that runs most of the lighting and control systems used in theaters, concerts, and other large-scale events, as well as more advanced architectural lighting. It's been around since the early 1980s, and it's still relevant today.
In this guide, we’ll explore the basics of DMX512 and how you can use it to control lights and effects from typical DMX controllers as well as from a microcontroller with a DMX board.
Light Fixtures
There are plenty of inexpensive DMX controlled light fixture options to get started with, such as LED PARs, washes, light bars, spots, and even moving head lights.
You can also run foggers, strobes, and other effects via DMX control.
or
XLR Cable
You'll use either 5-pin or 3-pin XLR cables to send data through the system. The DMX512 spec calls for 5-pin, but 3-pin is very common, especially in less expensive systems.
Each cable will have one plug end and one socket end, sometimes known as XLR3M to XLR3F cable.
Proper DMX512 cable has 110Ω impedance, but you can often get away with using regular old (cheaper) XLR microphone cable, especially for shorter runs.
or
DMX Shield for Arduino
You can use most Arduino-compatible boards along with a MAX485-based DMX shield to send and receive messages to and from your DMX fixtures and controllers.
There are a few different designs out there, we'll be using this one from Conceptinetics.
or from Amazon:
Arduino Uno or Metro 328
The library we'll use for the DMX shield only works on AVR-based microcontrollers, so an Arduino Uno R3 or a Metro 328 will be a good choice.
or
Optional
You won't need a controller like the one shown below if you're only sending DMX from your microcontroller to your fixtures, but they are pretty cool to play around with!
Also, one can be used to send DMX to your microcontroller, which we'll cover in an update to this guide coming soon.
DMX512 Controller
A compact, DJ-style controller is enough to get started with hands-on lighting control as well as basic chase and scene programming.
or
Page last edited December 11, 2024
DMX512
DMX512 is a serial communication protocol that sends data in the form of a packet. Each packet is a set of data bytes that are interpreted by devices daisy-chained across the network, typically lighting fixtures or effect units such as foggers or air cannons.
In the diagram below we have a DMX controller (typically a lighting control board with faders and buttons, but we'll later use a microcontroller in this role) connected to a DMX fixture via an XLR cable.
- Fixture 1 uses DMX channels 1-4 to control brightness, red, green, and blue
- Fixture 2 uses eight channels, starting at channel 17, this could be a more sophisticated fixture with pan/tilt motors, RGBW lights, and motorized gobos and filters
- we can go all the way up to channel 511
- the final fixture requires a 120Ω resistor across the data pair, this is typically integrated into the fixture itself when no cable is plugged at the output. Otherwise a terminator plug can be used
Wiring
These devices receive data via a 3-pin or 5-pin XLR connector and then send the data along to the next fixture in the chain.
Channels
DMX devices listen on specific channels (usually user configured) and respond to data sent over those channels. For example, an RGB light fixture may be set to listen to:
- Channel 1 Brightness
- Channel 2 Red
- Channel 3 Green
- Channel 4 Blue
- Channel 5 Strobe
The second light in the chain may be set to:
- Channel 17 Brightness
- Channel 18 Red
- Channel 19 Green
- Channel 20 Blue
- Channel 21 Strobe
You can see here that many channels have been skipped simply to meet with a typical convention of DMX control boxes having a bank of 16 faders, so the ergonomics of holding a modification key to flip between the channels makes certain numbering schemes make more sense than others.
Range: Each DMX channel can handle values from 0 to 255, which means it can be used to control things like brightness, color, or effects with reasonable granularity.
Page last edited December 11, 2024
Board Setup
Jumper Settings
Set the jumpers on the DMX shield as shown:
- EN off (in the on position the shield enable pin is grounded, turning off the shield)
- Mode ON (allows the mode pin 2 to set the board to sender or receiver mode via software)
- TX-IO (sets the TX pin to pin 4 instead of UART pin 1 which can interfere with board uploads)
- RX-10 (sets the RX pin to pin 3 instead of UART pin 0 which can interfere with board uploads)
Plug Cable
Plug a 3-pin XLR cable into the OUT connector on the board, then plug this cable into your first light fixture (shown in the image below as the blue marked cable).
Then, use a second XLR cable to plug the OUT of fixture 1 to the IN of fixture 2. This is the red marked cable in the image below.
Page last edited December 11, 2024
Code Arduino DMX Sender
Arduino Setup
Plug in your Arduino Uno or Metro 328 to your computer over a known good USB cable.
Before going any further, make sure you have a basic understanding of how to program and use an Arduino. Thankfully, we have a lot of great tutorials on how this whole thing works. Click here to get started with Arduino, and then come back to this guide to continue.
Additional Boards Manager URLs
To use the Metro board in Arduino, check the Arduino IDE Tools > Board list and select Adafruit Metro. Note: if you don't see the Metro on that list, add this URL to your Arduino > Preferences > Additional Boards Manager URLs:
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
Install Adafruit AVR
Then, go to the Arduino > Tools > Board > Boards Manager... and type 'metro' in the search, then install the Adafruit AVR Boards package.
DMXSimple Library
Next, you'll add the DMXSimple library by clicking on Tools > Manage Libraries... and then entering 'dmxsimple' in the search box.
Click the Install button.
You can find out more about this library here.
/* This program allows you to set DMX channels over the serial port.
**
** After uploading to Arduino, switch to Serial Monitor and set the baud rate
** to 9600. You can then set DMX channels using these commands:
**
** <number>c : Select DMX channel
** <number>v : Set DMX channel to new value
**
** These can be combined. For example:
** 100c355w : Set channel 100 to value 255.
**
** For more details, and compatible Processing sketch,
** visit http://code.google.com/p/tinkerit/wiki/SerialToDmx
**
** Help and support: http://groups.google.com/group/dmxsimple */
#include <DmxSimple.h>
void setup() {
Serial.begin(9600);
Serial.println("SerialToDmx ready");
Serial.println();
Serial.println("Syntax:");
Serial.println(" 123c : use DMX channel 123");
Serial.println(" 45w : set current channel to value 45");
}
int value = 0;
int channel;
void loop() {
int c;
while(!Serial.available());
c = Serial.read();
if ((c>='0') && (c<='9')) {
value = 10*value + c - '0';
} else {
if (c=='c') channel = value;
else if (c=='w') {
DmxSimple.write(channel, value);
Serial.println();
}
value = 0;
}
}
Modifications
We'll make a few small changes to use this example with the Conceptnetics DMX shield.
Pin definitions
First, we'll define the pins for transmitting and mode selection. Add these two lines after the #include line:
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 const byte modeSelectPin = 2; // conceptinetics mode pin
Setup
Next, in the setup() loop we'll set the mode select pin to OUTPUT with a HIGH value, placing the shield in sender mode.
You'll also tell DmxSimple to use the pre-defined transmit pin, and set the max channel value to 512 so that a full-length message is sent every time (some fixtures don't like receiving a shorter message).
pinMode(modeSelectPin, OUTPUT); digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode) DmxSimple.usePin(dmxTransmitPin); DmxSimple.maxChannel(512);
Here's the final code, you can copy this and paste it into your Arduino IDE to upload to the Metro.
/* This program allows you to set DMX channels over the serial port.
**
** John Park update for Conceptinetics DMX shield for this example
** After uploading to Arduino, switch to Serial Monitor and set the baud rate
** to 9600. You can then set DMX channels using these commands:
**
** <number>c : Select DMX channel
** <number>v : Set DMX channel to new value
**
** These can be combined. For example:
** 100c355v : Set channel 100 to value 255.
**
** For more details, and compatible Processing sketch,
** visit http://code.google.com/p/tinkerit/wiki/SerialToDmx
**
** Help and support: http://groups.google.com/group/dmxsimple */
/*
________
EN -- •
SL • --
TX -- •
RX -- •
________
*/
#include <DmxSimple.h>
//Constants
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 or use TX(1) with jumper to the right
const byte modeSelectPin = 2; // conceptinetics mode pin
void setup() {
pinMode(modeSelectPin, OUTPUT);
digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode)
/* The most common pin for DMX output is pin 3, which DmxSimple
** uses by default. If you need to change that, do it here. */
DmxSimple.usePin(dmxTransmitPin);
DmxSimple.maxChannel(512);
Serial.begin(9600);
Serial.println("SerialToDmx ready");
Serial.println();
Serial.println("Syntax:");
Serial.println(" 123c : use DMX channel 123");
Serial.println(" 45v : set current channel to value 45");
//set initial values
DmxSimple.write(1, 255); // ch1 is brightness on first fixture
DmxSimple.write(3, 150); // ch3 is green on first fixture
DmxSimple.write(17, 255); // ch17 is brightness on second fixture
DmxSimple.write(20, 200); // ch20 is red on second fixture
}
int value = 0;
int channel;
void loop() {
int c;
while(!Serial.available());
c = Serial.read();
if ((c>='0') && (c<='9')) {
value = 10*value + c - '0';
} else {
if (c=='c') channel = value;
else if (c=='v') {
DmxSimple.write(channel, value);
Serial.println();
}
value = 0;
}
}
DMX Fade Up
Let's check out another example -- this will fade up the values on one channel.
Click on File > Examples > DMXSimple > SerialtoDMX to open the example file.
We'll make a few adjustments to suit the Conceptinetics shield, and add a second fixture:
/* Welcome to DmxSimple. This library allows you to control DMX stage and
** architectural lighting and visual effects easily from Arduino. DmxSimple
** is compatible with the Tinker.it! DMX shield and all known DIY Arduino
** DMX control circuits.
** John Park update for Conceptinetics DMX shield for this example
**
** DmxSimple is available from: http://code.google.com/p/tinkerit/
** Help and support: http://groups.google.com/group/dmxsimple */
/* To use DmxSimple, you will need the following line. Arduino will
** auto-insert it if you select Sketch > Import Library > DmxSimple. */
/*
________
EN -- •
SL • --
TX -- •
RX -- •
________
*/
#include <DmxSimple.h>
//Constants
const byte dmxTransmitPin = 4; // conceptinetics transmit pin 4 or use TX(1) with jumper to the right
const byte modeSelectPin = 2; // conceptinetics mode pin
void setup() {
pinMode(modeSelectPin, OUTPUT);
digitalWrite(modeSelectPin, HIGH); // set to sender mode (low for receiver mode)
DmxSimple.usePin(dmxTransmitPin);
DmxSimple.maxChannel(512);
// first fixture
DmxSimple.write(1, 0); // set brightness
// set R,G,B
DmxSimple.write(2, 0);
DmxSimple.write(3, 0);
DmxSimple.write(4, 150);
// second fixture
DmxSimple.write(17, 0); // set brightness
// set R,G,B
DmxSimple.write(18, 0);
DmxSimple.write(19, 150);
DmxSimple.write(20, 0);
}
void loop() {
// fade loop:
int brightness;
/* Simple loop to ramp up brightness */
for (brightness = 0; brightness <= 255; brightness++) {
/* Update DMX channel 1 and 17 to new brightness */
DmxSimple.write(1, brightness);
DmxSimple.write(17, brightness);
/* Small delay to slow down the ramping */
delay(7);
}
delay(1000);
DmxSimple.write(1, 0); // set brightness to 0
DmxSimple.write(17,0);
delay(1000);
}
Page last edited December 11, 2024
Code Arduino DMX Receiver
Now we'll flip the equation -- instead of using your microcontroller to send DMX messages to commercial fixtures, you'll use a commercial controller to send DMX messages to the microcontroller! This means you can drive any sort of prop imaginable, not just the things available off the shelf.
For our demo we'll drive some NeoPixel strips with eight DMX channels each:
- Start hue
- Start saturation
- Start value (brightness)
- Start pixel location
- End hue
- End saturation
- End value (brightness)
- End pixel location
Board Setup
This setup is similar to the send demo, but we'll change the jumpers around to receive instead of send, and use the DMX output instead of input to XLR cable.
To connect NeoPixel strips a Proto ScrewShield works well and can be stacked.
NeoPixel Wiring
For info on getting the Proto ScrewShield set up, check this guide.
Connect the NeoPixel strips to 5V, Ground, and A0, A1, and A2 for data, respectively.
Arduino Setup
Plug in your Arduino Uno or Metro 328 to your computer over a known good USB cable.
Before going any further, make sure you have a basic understanding of how to program and use an Arduino. Thankfully, we have a lot of great tutorials on how this whole thing works. Click here to get started with Arduino, and then come back to this guide to continue.
Conceptinetics DMX Library
We'll use a more sophisticated DMX library for this example, since it allows us to put the board into receive mode, not just send mode.
Download the Project Bundle
To get everything you need, click on the Download Project Bundle link below, and uncompress the .zip file.
Drag the contents of the uncompressed bundle directory into your Arduino sketches folder, then open the DMX_NeoPixels.ino file in the Arduino IDE.
// SPDX-FileCopyrightText: 2024 John Park for Adafruit Industries
//
// SPDX-License-Identifier: MIT
// Use a DMX controller to drive NeoPixel strips
// Arduino Uno or Metro 328 + Conceptinetics DMX Shield
// Recieves incoming DMX messages from controller, translates to NeoPixel
#include "Conceptinetics.h"
#include <Adafruit_NeoPixel.h>
// User adjust these for the number of strips, pins, pixels per strip, and color formats:
#define NUM_STRIPS 3
const int pin_for_strip[] = {A0, A1, A2};
const int leds_per_strip[] = {30, 20, 30};
const neoPixelType format_per_strip[] = {NEO_GRB + NEO_KHZ800, NEO_BGR + NEO_KHZ800, NEO_GRB + NEO_KHZ800 };
#define CH_PER_STRIP 16 // only 4 used per strip, but 16 is nicer on UI of controllers that have 16 channel/page
#define DMX_CHANNELS (CH_PER_STRIP * NUM_STRIPS)
const int ledPin = 13;
Adafruit_NeoPixel *strips[NUM_STRIPS];
DMX_Slave dmx_slave ( DMX_CHANNELS ); // Configure a DMX receiving controller
uint16_t channelValues[DMX_CHANNELS]; // Array to store DMX values
void setup() {
// Set led pin as output pin
pinMode ( ledPin, OUTPUT );
digitalWrite(ledPin, HIGH);
// set up strips
for(int i=0; i< NUM_STRIPS; i++) {
int pin = pin_for_strip[i];
int num_leds = leds_per_strip[i];
int format = format_per_strip[i];
Adafruit_NeoPixel *strip = new Adafruit_NeoPixel(num_leds, pin, format);
strips[i] = strip;
strips[i]->begin();
}
// light up all the strips RGB to test
for(int i=0; i< NUM_STRIPS; i++) {
strips[i]->fill(0xff0000);
strips[i]->show();
delay(1000);
strips[i]->fill(0x00ff00);
strips[i]->show();
delay(1000);
strips[i]->fill(0x0000ff);
strips[i]->show();
}
delay(1000);
// Enable DMX receiving interface and start receiving DMX data
dmx_slave.enable ();
dmx_slave.setStartAddress (1);
}
void loop()
{
// Fetch all DMX channel values into the array
for (int i = 0; i < DMX_CHANNELS; i++) {
channelValues[i] = dmx_slave.getChannelValue(i + 1); // Get values starting from channel 1
}
for(int i=0; i<NUM_STRIPS; i++){
//remap some channels for specific value ranges
uint16_t strip_hue1 = map(channelValues[0 + (i * CH_PER_STRIP)], 0, 255, 0, 65535);
uint16_t strip_hue2 = map(channelValues[4 + (i * CH_PER_STRIP)], 0, 255, 0, 65535);
uint16_t strip_pix1 = map(channelValues[3 + (i * CH_PER_STRIP)], 0, 255, 0, leds_per_strip[i] - 1);
uint16_t strip_pix2 = map(channelValues[7 + (i * CH_PER_STRIP)], 0, 255, 0, leds_per_strip[i] - 1);
strips[i]->fill(0x000000);
strips[i]->setPixelColor(strip_pix1, strips[i]->ColorHSV(strip_hue1, channelValues[1+(i*CH_PER_STRIP)], channelValues[2+(i*CH_PER_STRIP)])); //first pixel
strips[i]->setPixelColor(strip_pix2, strips[i]->ColorHSV(strip_hue2, channelValues[5+(i*CH_PER_STRIP)], channelValues[6+(i*CH_PER_STRIP)])); //last pixel
// all the pixels in between
for (int j = strip_pix1; j <= strip_pix2; j++) {
float fraction = float(j - strip_pix1) / float(strip_pix2 - strip_pix1); // Calculate the fraction of the interpolation (0 to 1)
// Interpolate HSV components (Hue, Saturation, Value)
uint16_t interpolated_hue = int(lerp(strip_hue1, strip_hue2, fraction)) % 65536; // Wrap around Hue
uint16_t interpolated_saturation = lerp(channelValues[1+(i*CH_PER_STRIP)], channelValues[5+(i*CH_PER_STRIP)], fraction);
uint16_t interpolated_value = lerp(channelValues[2+(i*CH_PER_STRIP)], channelValues[6+(i*CH_PER_STRIP)], fraction);
// Set the interpolated color to the pixel
strips[i]->setPixelColor(j, strips[i]->ColorHSV(interpolated_hue, interpolated_saturation, interpolated_value));
}
}
for(int i=0; i<NUM_STRIPS; i++){
strips[i]->show();
}
delay(100);
}
// Linear interpolation function
float lerp(float start, float end, float t) {
return start + (end - start) * t;
}
Use It
With the Arduino powered and the XLR cable connecting the DMX controller and DMX shield, fire up your DMX controller.
Here are the controls (use the pages 1-3 for the different strips):
- ch. 1 = start hue
- ch. 2 = start saturation
- ch. 3 = start value (brightness)
- ch. 4 = start pixel location
- ch. 5 = end hue
- ch. 6 = end saturation
- ch. 7 = end value (brightness)
- ch. 8 = end pixel location
Hue values are automatically interpolated between the start and end values for however many NeoPixels you light up.
Page last edited December 11, 2024