DMX512 Unit
DMX Unit is a communication unit specifically designed for DMX-512 data transmission scenarios. It integrates the CA-IS3092W isolated half-duplex RS-485 transceiver, providing up to 5kVrms electrical isolation protection. The onboard 120Ω termination resistor switch matches the characteristic impedance of the signal transmission line, preventing signal reflection and distortion, and can be connected according to the usage scenario.
Support the following products:
Micropython Example Send Data:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from unit import DMX512Unit 9import time 10 11 12Title = None 13label1 = None 14label0 = None 15dmx_0 = None 16 17 18ch_data = None 19 20 21def setup(): 22 global Title, label1, label0, dmx_0, ch_data 23 24 M5.begin() 25 Widgets.fillScreen(0x222222) 26 Title = Widgets.Title("DMX512Unit Send example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 27 label1 = Widgets.Label("Not Sent", 2, 129, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 28 label0 = Widgets.Label( 29 "Not initialized", 2, 76, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 30 ) 31 32 dmx_0 = DMX512Unit(1, port=(13, 14), mode=1) 33 label0.setText(str("Initialized")) 34 ch_data = 0 35 36 37def loop(): 38 global Title, label1, label0, dmx_0, ch_data 39 M5.update() 40 label1.setText(str("Not Sent")) 41 dmx_0.write_data(1, ch_data) 42 dmx_0.write_data(2, ch_data) 43 dmx_0.write_data(3, ch_data) 44 ch_data = (ch_data if isinstance(ch_data, (int, float)) else 0) + 1 45 if ch_data >= 255: 46 ch_data = 0 47 label1.setText(str("Sent")) 48 time.sleep(0.7) 49 50 51if __name__ == "__main__": 52 try: 53 setup() 54 while True: 55 loop() 56 except (Exception, KeyboardInterrupt) as e: 57 try: 58 from utility import print_error_msg 59 60 print_error_msg(e) 61 except ImportError: 62 print("please update to latest firmware")
Micropython Example Receive Data:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from unit import DMX512Unit 9 10 11Title = None 12label0 = None 13label1 = None 14dmx_0 = None 15 16 17dmx_data = None 18dmx_data2 = None 19 20 21def dmx_0_channel1_receive_event(received_data): 22 global Title, label0, label1, dmx_0, dmx_data, dmx_data2 23 dmx_data = received_data 24 label0.setText(str((str("Channel 1:") + str(dmx_data)))) 25 26 27def dmx_0_channel2_receive_event(received_data): 28 global Title, label0, label1, dmx_0, dmx_data, dmx_data2 29 dmx_data2 = received_data 30 label1.setText(str((str("Channel 2:") + str(dmx_data2)))) 31 32 33def setup(): 34 global Title, label0, label1, dmx_0, dmx_data, dmx_data2 35 36 M5.begin() 37 Widgets.fillScreen(0x222222) 38 Title = Widgets.Title("DMX512Unit Rec example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 39 label0 = Widgets.Label("Channel 1:", 0, 57, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 40 label1 = Widgets.Label("Channel 2:", 2, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 41 42 dmx_0 = DMX512Unit(1, port=(13, 14), mode=2) 43 dmx_0.attach_channel(1, dmx_0_channel1_receive_event) 44 dmx_0.attach_channel(2, dmx_0_channel2_receive_event) 45 dmx_0.receive_none_block() 46 47 48def loop(): 49 global Title, label0, label1, dmx_0, dmx_data, dmx_data2 50 M5.update() 51 52 53if __name__ == "__main__": 54 try: 55 setup() 56 while True: 57 loop() 58 except (Exception, KeyboardInterrupt) as e: 59 try: 60 from utility import print_error_msg 61 62 print_error_msg(e) 63 except ImportError: 64 print("please update to latest firmware")
UIFLOW2 Master Example:
UIFLOW2 Slave Example:
dmx512_core2_send_example.m5f2
dmx512_core2_receive_example.m5f2
class DMX512Unit
Constructors
Methods
- DMX512Unit.dmx_init(mode) None
Initializes the DMX512 communication with UART pins and mode.
- Parameters:
mode – Operating mode (1 for Master, 2 for Slave).
UIFLOW2:
- DMX512Unit.write_data(channel, data) None
Updates the data for a specified DMX channel. Data is sent on the next update cycle.
- Parameters:
channel – DMX channel number (1-512).
data – Data value to be sent (0-255). @raises ValueError if the channel number is out of range.
UIFLOW2:
- DMX512Unit.read_data(channel) int
Reads data from a specified DMX channel in Slave mode.
- Parameters:
channel – DMX channel number (1-512).
UIFLOW2:
- DMX512.receive_none_block() None
Starts non-blocking data reception for the specified channels with associated callbacks.
UIFLOW2: