Thursday, 12 February 2009

DMX lighting

This is one of the things I'd anticipated using this blog for: making notes on what I do to make things work so I don't have to work it all out repeatedly. By doing it online perhaps it will help other people too.

Today's (well, the next few minutes') random task is to get DMX lighting control working from my Linux boxes. I have a iColor 4 light and an Enttec OpenDMX USB to DMX convertor here and want to have some basic control over it. I've done this three or four times now but forget the moving parts every time.

OK, most importantly forget about dmx4linux. It appears to be old, unmaintained and clearly the thing you want when you google. Oh well. These days it's LLA that's the new kid on the block, and in particular the kernel drivers can be found in git using git-clone http://www.erwinrol.com/git/dmx_usb_module/

Once that's installed, you get a /dev/dmx0 which is a seekable 512 byte character special corresponding to the 512 DMX channels. You need to update it frequently or the fixtures go into reset so do something like:

DMX = map(lambda n: 0, range(512))

exited = False
def dmxthread():
dmx = open("/dev/dmx0", "w")
while not exited:
buf = "\0"

for i in xrange(0, 512):
buf += "%c" % DMX[i]

dmx.write(buf)
dmx.seek(0)

time.sleep(0.05)

t = threading.Thread(target = dmxthread)
t.setDaemon(True)
t.start()


Obviously if this weren't a quick hack that ought to be a class with private state for the DMX channels. But the above gives you the basics for writing to DMX devices asynchronously. I've hacked it a bit further to use a Behringer BCF1000 to control the first 8 channels.

Now the next, and more interesting, part of this project will be making a bunch of classes representing lights, another bunch representing controllers (both human interaction and beat detection and the like) and stringing them together to sequence some sort of scripted light show. But not today.

No comments:

Post a Comment