DMX512 is a lighting control standard widely used in theater and nightclub technology. It enables all kinds of stage equipment to be remotely controlled from a central console, simply via a long three-wire bus on which the spotlights are chained. But can a Yoctopuce module be used to access a DMX512 bus?
Why would we want to do that?
Being able to receive DMX512 messages with a Yocto-RS485-V2 opens up a whole world of possibilities for making your own systems controlled by a central DMX console. No need to search for a specialized DMX-controlled device for each stage trick: for example, a few lines of code suffice to automatically drive a relay or an RC servo-motor, according to a command received via DMX.
On the other hand, if you're building a system that requires a lot of analog controls, reusing a standard DMX console can make your project much easier to build, even if your project has nothing to do with stage technology. Conversely, being able to drive a DMX bus allows you to use all kinds of lighting and signaling equipment on a project, and they are easy enough to set up.
Two DMX devices that can be useful for your projects
So, since we're publishing this post today, you may have guessed that the answer is yes: it's possible. In fact, the physical layer of DMX512 is nothing other than an RS-485 bus. So, a priori, a Yocto-RS485-V2 should do the trick. But there are still a few subtleties of the DMX512 protocol to be taken into account...
DMX512 data format
Encoding messages on a DMX512 bus is extremely simple:
- Each message carries up to 512 control values.
- The values, ranging from 0 to 255, are all sent in sequence.
- The value at offset 0 doesn't count; it's always 0.
- If you assign to a projector address 2, it simply switches on according to the value at offset 2.
This means you can address up to 512 monochrome spotlights on a DMX512 bus, hence the name. But modern fixtures often use several consecutive values, to control power with greater finesse over 16 bits, to choose the color, or even to control the spotlight's orientation. To compensate for the limited address space, several separate buses are used, called separate DMX universes.
Messages are sent by the DMX console continuously, typically at a frequency of 10 to 50 Hz. To transmit so many values at this frequency, the DMX512 bus operates at 250 kbps (8 bits, no parity, 2 stop bits). Note that control consoles managing fewer than 512 channels send shorter messages, which saves them time and enables them to increase the refresh rate.
Last but not least: to identify the start of messages, they are preceded by a break at least two bytes wide (~0.1 ms).
Connection and configuration
DMX uses XLR sockets with 3 or 5 contacts:
Using XLR contacts for DMX512
To connect your Yocto-RS485-V2 to a DMX512 bus, the easiest way is probably to buy a small XLR cable corresponding to the standard of your device and cut it in two. All that's left is to identify each of the wires using a tester to put them in the right position on the Yocto-RS485-V2 terminal.
To configure the module, use the parameters below:
Configuring the Yocto-RS485-V2 for DMX512
The delay between messages is not important, as the break sent at the start of each message automatically generates the appropriate separation.
Listening to a DMX512 bus with a Yocto-RS485-V2
Unlike using a traditional RS485 interface, with a Yocto-RS485-V2 you don't need your program to read the data stream continuously: you can simply use
to retrieve the most recent fully received DMX message.
But it's possible to do something even more efficient: you can define a job in the Yocto-RS485-V2 that analyzes the messages and directly extracts the values you're interested in (for an introduction to this subject, consult the user's guide or this previous post). For example, if you're interested in the values at positions 1 to 3, define a job with a custom task that contains the following command:
expect 00($1:BYTE)($2:BYTE)($3:BYTE).*
This extracts the corresponding values and assigns them directly to genericSensor1..3. If you're using 16-bit values, using the WORD keyword instead of BYTE even allows you to decode them directly.
For this to work, there's just one small subtlety to be observed: don't use a reactive task, as is usually done in this case, but use a periodic task according to the refresh rate you wish to use - for example, a 25 ms period for a 40 Hz refresh. This avoids the risk of overloading the Yocto-RS485-V2 if the console sends messages faster than it can process them. In any case, there is no risk of data loss as all messages repeat all values.
This is what your task should look like:
Task for automatic decoding of DMX512 messages
And to prove that it works, here's a little Python application that reads three values from the DMX512 bus and displays a corresponding vu-meter on an Ethernet-connected NeoPixel display we built for a previous post.
Our 'home made' DMX512 vu-meter
The code for this example is available on GitHub.
Controlling a DMX512 device with a Yocto-RS485-V2
Sending a DMX message with the Yocto-RS485-V2 is even simpler: simply set the desired values in an integer array and use the
- the sendBreak(1) method to signal the start of the message
- the writeArray(msg) method to send the values
Remember that the value at offset zero of your array is not used and must always be zero.
So here's a second little Python application that reads the orientation of a Yocto-3D-V2 and orients a small DMX512 motorized spotlight in the same direction. The projected color is chosen according to the angle of inclination on the 3rd axis (the roll axis).
Our DMX512 gyroscopic joystick
The code for this example is also available on GitHub.
Conclusion
The Yocto-RS485-V2 is perfectly suited to integrating DMX512 devices into your various projects.
On the other hand, if your aim is solely to control stage devices with existing DMX512 control software, you'll be better off using a simple mainstream DMX512 adapter which, while less subtle, is natively supported by your software.