DMX512 Module
DMX-Base is a functional base specially designed for DMX-512 data transmission scenarios, communicating and enabling control with M5 host through serial port, equipped with XLR-5 and XLR-3 male and female interfaces, convenient for users to connect DMX devices with different interfaces, in addition, the module has HT3.96 pitch 485 interface to facilitate connection to Expansion 485 devices.
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 module import DMX512Module 9import time 10 11 12Title = None 13label1 = None 14label0 = None 15module_dmx_0 = None 16 17 18ch_data = None 19 20 21def setup(): 22 global Title, label1, label0, module_dmx_0, ch_data 23 24 M5.begin() 25 Widgets.fillScreen(0x222222) 26 Title = Widgets.Title( 27 "DMX512Module Send example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 28 ) 29 label1 = Widgets.Label("Not Sent", 2, 129, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 30 label0 = Widgets.Label( 31 "Not initialized", 2, 76, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18 32 ) 33 34 module_dmx_0 = DMX512Module(2, mode=1) 35 ch_data = 0 36 label0.setText(str("Initialized")) 37 38 39def loop(): 40 global Title, label1, label0, module_dmx_0, ch_data 41 M5.update() 42 label1.setText(str("Not Sent")) 43 ch_data = ch_data + 1 44 if ch_data >= 255: 45 ch_data = 0 46 module_dmx_0.write_data(1, ch_data) 47 module_dmx_0.write_data(2, ch_data) 48 module_dmx_0.write_data(3, ch_data) 49 label1.setText(str("Sent")) 50 time.sleep(0.7) 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")
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 module import DMX512Module 9 10 11Title = None 12label0 = None 13label1 = None 14module_dmx_0 = None 15 16 17dmx_data = None 18dmx_data2 = None 19 20 21def module_dmx_0_channel1_receive_event(received_data): 22 global Title, label0, label1, module_dmx_0, dmx_data, dmx_data2 23 dmx_data = received_data 24 label0.setText(str((str("Channel 1:") + str(dmx_data)))) 25 26 27def module_dmx_0_channel2_receive_event(received_data): 28 global Title, label0, label1, module_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, module_dmx_0, dmx_data, dmx_data2 35 36 M5.begin() 37 Widgets.fillScreen(0x222222) 38 Title = Widgets.Title( 39 "DMX512Module Rec example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18 40 ) 41 label0 = Widgets.Label("Channel 1:", 0, 82, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 42 label1 = Widgets.Label("Channel 2:", 0, 134, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 43 44 module_dmx_0 = DMX512Module(1, mode=2) 45 module_dmx_0.attach_channel(1, module_dmx_0_channel1_receive_event) 46 module_dmx_0.attach_channel(2, module_dmx_0_channel2_receive_event) 47 module_dmx_0.receive_none_block() 48 49 50def loop(): 51 global Title, label0, label1, module_dmx_0, dmx_data, dmx_data2 52 M5.update() 53 54 55if __name__ == "__main__": 56 try: 57 setup() 58 while True: 59 loop() 60 except (Exception, KeyboardInterrupt) as e: 61 try: 62 from utility import print_error_msg 63 64 print_error_msg(e) 65 except ImportError: 66 print("please update to latest firmware")
UIFLOW2 Master Example:
UIFLOW2 Slave Example:
dmx512_core2_send_example.m5f2
dmx512_core2_receive_example.m5f2
class DMX512Module
Constructors
Methods
- DMX512Module.dmx_init(mode) None
Initializes the DMX512 communication with UART pins and mode.
- Parameters:
mode – Operating mode (1 for Master, 2 for Slave).
UIFLOW2:
- DMX512Module.deinit() None
Deinitializes the DMX512 module and stops any ongoing operations.
UIFLOW2:
- DMX512Module.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:
- DMX512Module.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:
- DMX512Module.attach_channel(channel, callback) None
Attaches a callback function to a specified DMX channel.
- Parameters:
channel – DMX channel number (1-512) to attach the callback to.
callback – The function to be called when data changes on the specified channel.
UIFLOW2:
- DMX512.stop_receive() None
Stops the non-blocking data reception task.
UIFLOW2: