Skip to content

Instantly share code, notes, and snippets.

@alexkafer
Last active September 18, 2022 22:30
Show Gist options
  • Save alexkafer/2009af13bb7be9b04faf5845934bf59a to your computer and use it in GitHub Desktop.
Save alexkafer/2009af13bb7be9b04faf5845934bf59a to your computer and use it in GitHub Desktop.
A script to send DMX packets using an Enttec DMXUSB PRO for use with the Tesla Works Light Show. Based off data from https://www.enttec.com/docs/dmx_usb_pro_api_spec.pdf and implementation from https://github.com/teslaworksumn/enttec-usb-dmx-pro
import serial
import time
import sys
# Create a new instance of the serial
ser = serial.Serial()
# Set the COM Port the DMX Pro is listening on
ser.port = '/dev/tty.usbserial-EN175330'
# Baud rate doesn't matter on FTDI chips
# ser.baudrate = 57600
# Make sure the port isn't open, and if it is, close it
if ser.isOpen():
ser.close()
# Let everyone know!
print ('Opening Enttec USB DMX Pro on', ser.port, 'at', ser.baudrate, 'baud')
# Open the serial connection
ser.open()
# Formulate the frame to send to the ENTTEC DMXUSB Pro
def sendmsg(label, message=[]):
# How many data points to send
l = len(message)
lm = l >> 8
ll = l - (lm << 8)
if l <= 600:
if ser.isOpen():
# Create the array to write to the serial port
arr = [0x7E, label, ll, lm] + message + [0xE7]
# Convert to byte array and write it
ser.write(bytearray(arr))
else:
# Too long!
sys.stderr.write('TX_ERROR: Malformed message! The message to be send is too long!\n')
# Sending the DMX frame (entire thing)
def sendDMX(channels):
# Sends an array of up to 512 channels
data = [0] + channels
# Fill up the channels up to the minimum of 25
while len(data) < 25:
# Make all the extra channels 0
data += [0]
# Send all the data with label 6
sendmsg(6, data)
# The real useful code. This just tests the code above
toggle = False
# Endless demo loop
while True:
# 40 Hertz
time.sleep(.025)
#Flip every loop
if toggle:
# Turn the 3rd channel on to 200 (out of 255)
sendDMX([0, 0, 200])
else:
# Turn off the 3rd channel
sendDMX([0, 0, 0])
#flip toggle
toggle = not toggle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment