# DMX512 UART TX. MicroPython (ESP32) and buffer-only on CPython. try: from machine import UART, Pin except ImportError: UART = None Pin = None class DMX: """One DMX512 universe. UART TX on MicroPython; frame-only on CPython.""" def __init__(self, uart=1, tx=0, de=None): self.frame = bytearray(513) # start code 0 + 512 slots self.uart = None self._de = None if UART is None: return self.uart = UART(uart, tx=tx) self.uart.init(250000, bits=8, parity=None, stop=2) if de is not None and Pin is not None: self._de = Pin(de, Pin.OUT) self._de.value(0) def send(self): if self.uart is None: return if self._de is not None: self._de.value(1) self.uart.sendbreak() self.uart.write(self.frame) if self._de is not None: self._de.value(0)