├── documentation ├── max485.jpg ├── ESP8266_DMXController_Prototype.fzz ├── ESP8266_DMXController_Prototype_schem.pdf └── ESP8266_DMXController_Prototype_schem.png ├── esp32_example ├── cpp │ ├── ESPDMX.h │ └── ESPDMX.cpp └── esp32_example.ino ├── esp8266_example └── esp8266_example.ino └── README.md /documentation/max485.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cansik/esp-dmx-max485/HEAD/documentation/max485.jpg -------------------------------------------------------------------------------- /documentation/ESP8266_DMXController_Prototype.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cansik/esp-dmx-max485/HEAD/documentation/ESP8266_DMXController_Prototype.fzz -------------------------------------------------------------------------------- /documentation/ESP8266_DMXController_Prototype_schem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cansik/esp-dmx-max485/HEAD/documentation/ESP8266_DMXController_Prototype_schem.pdf -------------------------------------------------------------------------------- /documentation/ESP8266_DMXController_Prototype_schem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cansik/esp-dmx-max485/HEAD/documentation/ESP8266_DMXController_Prototype_schem.png -------------------------------------------------------------------------------- /esp32_example/cpp/ESPDMX.h: -------------------------------------------------------------------------------- 1 | // - - - - - 2 | // ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. 3 | // ESPDMX.cpp: Library implementation file 4 | // 5 | // Copyright (C) 2015 Rick 6 | // This work is licensed under a GNU style license. 7 | // 8 | // Last change: Marcel Seerig 9 | // 10 | // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx 11 | // - - - - - 12 | 13 | #include 14 | 15 | 16 | #ifndef ESPDMX_h 17 | #define ESPDMX_h 18 | 19 | // ---- Methods ---- 20 | 21 | class DMXESPSerial { 22 | public: 23 | void init(); 24 | void init(int MaxChan, int dmxPin); 25 | uint8_t read(int Channel); 26 | void write(int channel, uint8_t value); 27 | void update(); 28 | void end(); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /esp8266_example/esp8266_example.ino: -------------------------------------------------------------------------------- 1 | // - - - - - 2 | // ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. 3 | // 4 | // Copyright (C) 2015 Rick 5 | // This work is licensed under a GNU style license. 6 | // 7 | // Last change: Musti (edited by Musti) 8 | // 9 | // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx 10 | // Connect GPIO02 - TDX1 to MAX3485 or other driver chip to interface devices 11 | // Pin is defined in library 12 | // - - - - - 13 | 14 | #include 15 | 16 | DMXESPSerial dmx; 17 | 18 | void setup() { 19 | //dmx.init(); // initialization for first 32 addresses by default 20 | dmx.init(512); // initialization for complete bus 21 | delay(200); // wait a while (not necessary) 22 | } 23 | 24 | void loop() { 25 | 26 | for (int i = 0; i < 512; i++) 27 | { 28 | dmx.write(i, 255); 29 | } 30 | dmx.update(); // update the DMX bus 31 | delay(1000); // wait for 1s 32 | 33 | for (int i = 0; i < 512; i++) 34 | { 35 | dmx.write(i, 0); 36 | } 37 | dmx.update(); 38 | delay(1000); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /esp32_example/esp32_example.ino: -------------------------------------------------------------------------------- 1 | // - - - - - 2 | // ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. 3 | // 4 | // Copyright (C) 2015 Rick 5 | // This work is licensed under a GNU style license. 6 | // 7 | // Last change: Musti (edited by Musti) 8 | // 9 | // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx 10 | // Connect GPIO02 - TDX1 to MAX3485 or other driver chip to interface devices 11 | // Pin is defined in library 12 | // - - - - - 13 | 14 | #include 15 | 16 | DMXESPSerial dmx; 17 | 18 | void setup() { 19 | Serial.begin(115200); 20 | 21 | delay(3000); 22 | 23 | Serial.println("starting..."); 24 | 25 | dmx.init(512, 4); // initialization for complete bus 26 | 27 | Serial.println("initialized..."); 28 | delay(200); // wait a while (not necessary) 29 | } 30 | 31 | void loop() { 32 | 33 | for (int i = 0; i < 512; i++) 34 | { 35 | dmx.write(i, 255); 36 | } 37 | Serial.print("turning on..."); 38 | dmx.update(); // update the DMX bus 39 | Serial.println("updated!"); 40 | delay(1000); // wait for 1s 41 | 42 | for (int i = 0; i < 512; i++) 43 | { 44 | dmx.write(i, 0); 45 | } 46 | Serial.print("turning off..."); 47 | dmx.update(); // update the DMX bus 48 | Serial.println("updated!"); 49 | delay(1000); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266 / ESP32 to DMX over MAX485 2 | An example on how to send dmx over a max485 with an ESP8266 or ESP32. 3 | 4 | ### Important 5 | The library uses multiple Serial protocols which is **very** slow! I am using a new library for the `ESP32`, which does the protocol change directly through chaning the registers. Please take a look at the library here ([LXESP32DMX](https://github.com/bildspur/til/tree/master/src/controller/driver/LXESP32DMX)). Here is an example on how to use it ([DMXLightRenderer.h](https://github.com/bildspur/til/blob/master/src/controller/renderer/DMXLightRenderer.h)) 6 | 7 | ### Library 8 | - [DMX Library for Arduino with ESP8266](https://github.com/Rickgg/ESP-Dmx) 9 | 10 | ### MAX485 to RS485 MCU 11 | [![Max485](documentation/max485.jpg)](https://www.aliexpress.com/item/FREE-SHIPPING-5PCS-LOT-MAX485-module-RS485-module-TTL-turn-RS-485-module-MCU-development-accessories/1738470391.html?spm=2114.search0104.3.57.4be9268aPDQrqa&ws_ab_test=searchweb0_0,searchweb201602_3_10065_10068_204_318_319_10059_10884_10887_100031_10696_450_320_10084_10083_10103_452_10618_535_534_10307_533_532_448_449_10134,searchweb201603_2,ppcSwitch_0&algo_expid=0ea8df45-c2bc-4a0a-afba-c7e46db1f402-8&algo_pvid=0ea8df45-c2bc-4a0a-afba-c7e46db1f402) 12 | 13 | ### Circuit for NodeMCU V1.0 14 | *Caution: This is just an example that worked for me. Have a look at [#1](https://github.com/cansik/esp-dmx-max485/issues/1) for more information about safe wiring!* 15 | ![Circuit](documentation/ESP8266_DMXController_Prototype_schem.png) 16 | -------------------------------------------------------------------------------- /esp32_example/cpp/ESPDMX.cpp: -------------------------------------------------------------------------------- 1 | // - - - - - 2 | // ESPDMX - A Arduino library for sending and receiving DMX using the builtin serial hardware port. 3 | // ESPDMX.cpp: Library implementation file 4 | // 5 | // Copyright (C) 2015 Rick 6 | // This work is licensed under a GNU style license. 7 | // 8 | // Last change: Marcel Seerig 9 | // 10 | // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx 11 | // - - - - - 12 | 13 | /* ----- LIBRARIES ----- */ 14 | #include 15 | 16 | #include "ESPDMX.h" 17 | #include 18 | 19 | 20 | 21 | #define dmxMaxChannel 512 22 | #define defaultMax 32 23 | 24 | #define DMXSPEED 250000 25 | #define DMXFORMAT SERIAL_8N2 26 | #define BREAKSPEED 83333 27 | #define BREAKFORMAT SERIAL_8N1 28 | 29 | bool dmxStarted = false; 30 | int sendPin = 4; //dafault on ESP32 31 | int receivePin = -1; 32 | 33 | //DMX value array and size. Entry 0 will hold startbyte 34 | uint8_t dmxData[dmxMaxChannel] = {}; 35 | int chanSize; 36 | 37 | HardwareSerial DMXSerial(1); 38 | 39 | void DMXESPSerial::init() { 40 | chanSize = defaultMax; 41 | 42 | DMXSerial.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); 43 | pinMode(sendPin, OUTPUT); 44 | dmxStarted = true; 45 | } 46 | 47 | // Set up the DMX-Protocol 48 | void DMXESPSerial::init(int chanQuant, int dmxPin) { 49 | sendPin = dmxPin; 50 | 51 | if (chanQuant > dmxMaxChannel || chanQuant <= 0) { 52 | chanQuant = defaultMax; 53 | } 54 | 55 | chanSize = chanQuant; 56 | 57 | DMXSerial.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); 58 | pinMode(sendPin, OUTPUT); 59 | dmxStarted = true; 60 | } 61 | 62 | // Function to read DMX data 63 | uint8_t DMXESPSerial::read(int Channel) { 64 | if (dmxStarted == false) init(); 65 | 66 | if (Channel < 1) Channel = 1; 67 | if (Channel > dmxMaxChannel) Channel = dmxMaxChannel; 68 | return(dmxData[Channel]); 69 | } 70 | 71 | // Function to send DMX data 72 | void DMXESPSerial::write(int Channel, uint8_t value) { 73 | if (dmxStarted == false) init(); 74 | 75 | if (Channel < 1) Channel = 1; 76 | if (Channel > chanSize) Channel = chanSize; 77 | if (value < 0) value = 0; 78 | if (value > 255) value = 255; 79 | 80 | dmxData[Channel] = value; 81 | } 82 | 83 | void DMXESPSerial::end() { 84 | delete dmxData; 85 | chanSize = 0; 86 | DMXSerial.end(); 87 | dmxStarted == false; 88 | } 89 | 90 | void DMXESPSerial::update() { 91 | if (dmxStarted == false) init(); 92 | 93 | //Send break 94 | digitalWrite(sendPin, HIGH); 95 | DMXSerial.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin); 96 | DMXSerial.write(0); 97 | DMXSerial.flush(); 98 | delay(1); 99 | DMXSerial.end(); 100 | 101 | //send data 102 | DMXSerial.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); 103 | digitalWrite(sendPin, LOW); 104 | DMXSerial.write(dmxData, chanSize); 105 | DMXSerial.flush(); 106 | delay(1); 107 | DMXSerial.end(); 108 | } 109 | 110 | // Function to update the DMX bus 111 | --------------------------------------------------------------------------------