-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
DMX Output - Runtime Config & replace SparkFunDMX with esp_dmx #5433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c0d662a
37732ca
96d4489
84ce66f
d40f0f6
7d3a673
d336b97
576b628
2f874cf
034e4f5
834c285
22aff94
585d174
7a910c8
5cdca58
48168ed
93ef454
cd08d6f
c8ff292
b11c7f7
d5061ed
1ccef16
4a60207
3b92b2d
ec64355
02274e1
b8fcb1c
306ba83
f5522e6
38330b5
daa2223
e28774d
c20f59d
ea3aba9
ab632e9
cf1f236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,14 +134,6 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo | |||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (inputPortNum <= (SOC_UART_NUM - 1) && inputPortNum > 0) { | ||||||||||||||||||||||||||||||
| this->inputPortNum = inputPortNum; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||
| DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum); | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if (rxPin > 0 && enPin > 0 && txPin > 0) { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const managed_pin_type pins[] = { | ||||||||||||||||||||||||||||||
|
|
@@ -156,6 +148,15 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo | |||||||||||||||||||||||||||||
| DEBUG_PRINTF("en in use by: %s\n", PinManager::getPinOwner(enPin)); | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| if (inputPortNum <= (SOC_UART_NUM - 1) && inputPortNum > 0) { | ||||||||||||||||||||||||||||||
| this->inputPortNum = inputPortNum; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||
| DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d, default to 1\n", inputPortNum); | ||||||||||||||||||||||||||||||
| this->inputPortNum = 1; | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+151
to
+158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid-port fallback exits too early and leaves allocated pins reserved. At Line 157, init returns after setting fallback port Suggested fix- if (inputPortNum <= (SOC_UART_NUM - 1) && inputPortNum > 0) {
- this->inputPortNum = inputPortNum;
- }
- else {
- DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d, default to 1\n", inputPortNum);
- this->inputPortNum = 1;
- return;
- }
+ if (inputPortNum <= (SOC_UART_NUM - 1) && inputPortNum > 0) {
+ this->inputPortNum = inputPortNum;
+ } else {
+ DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d, default to 1\n", inputPortNum);
+ this->inputPortNum = 1;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| this->rxPin = rxPin; | ||||||||||||||||||||||||||||||
| this->txPin = txPin; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,11 @@ | ||||||||||||||||
| #include "wled.h" | ||||||||||||||||
|
|
||||||||||||||||
| #include "dmx_output.h" | ||||||||||||||||
|
Comment on lines
1
to
+2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't pull in The 💡 Suggested change `#include` "wled.h"
-#include "dmx_output.h"
+#ifdef WLED_ENABLE_DMX
+#include "dmx_output.h"
+#endif📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| /* | ||||||||||||||||
| * Support for DMX output via serial (e.g. MAX485). | ||||||||||||||||
| * Change the output pin in src/dependencies/ESPDMX.cpp, if needed (ESP8266) | ||||||||||||||||
| * Change the output pin in src/dependencies/SparkFunDMX.cpp, if needed (ESP32) | ||||||||||||||||
| * Support for DMX output via serial (e.g. MAX485). | ||||||||||||||||
| * ESP8266 Library from: | ||||||||||||||||
| * https://github.com/Rickgg/ESP-Dmx | ||||||||||||||||
| * ESP32 Library from: | ||||||||||||||||
| * https://github.com/sparkfun/SparkFunDMX | ||||||||||||||||
| * https://github.com/someweisguy/esp_dmx | ||||||||||||||||
| */ | ||||||||||||||||
|
|
||||||||||||||||
| #ifdef WLED_ENABLE_DMX | ||||||||||||||||
|
|
@@ -68,13 +66,42 @@ void handleDMXOutput() | |||||||||||||||
| dmx.update(); // update the DMX bus | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| void initDMXOutput() { | ||||||||||||||||
| #if defined(ESP8266) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) | ||||||||||||||||
| dmx.init(512); // initialize with bus length | ||||||||||||||||
| #else | ||||||||||||||||
| dmx.initWrite(512); // initialize with bus length | ||||||||||||||||
| #endif | ||||||||||||||||
| void initDMXOutput(int outputPin) { | ||||||||||||||||
| if (outputPin < 1) return; | ||||||||||||||||
| const bool pinAllocated = PinManager::allocatePin(outputPin, true, PinOwner::DMX); | ||||||||||||||||
| if (!pinAllocated) { | ||||||||||||||||
| DEBUG_PRINTF("DMXOutput: Error: Failed to allocate pin for DMX_OUTPUT. Pin already in use:\n"); | ||||||||||||||||
| DEBUG_PRINTF("In use by: %s\n", PinManager::getPinOwner(outputPin)); | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
| DEBUG_PRINTF("DMXOutput: init: pin %d\n", outputPin); | ||||||||||||||||
| dmx.init(outputPin); // set output pin and initialize DMX output | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #if !defined(ESP8266) | ||||||||||||||||
| void DMXOutput::init(uint8_t outputPin) { | ||||||||||||||||
| dmx_config_t config = DMX_CONFIG_DEFAULT; | ||||||||||||||||
| const bool installOk = dmx_driver_install(dmxPort, &config, DMX_INTR_FLAGS_DEFAULT); | ||||||||||||||||
| if (!installOk) { | ||||||||||||||||
| DEBUG_PRINTF("DMXOutput: Error: Failed to install dmx driver\n"); | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
| const bool setPin = dmx_set_pin(dmxPort, outputPin, -1, -1); | ||||||||||||||||
| if (!setPin) { | ||||||||||||||||
| DEBUG_PRINTF("DMXOutput: Error: Failed to set DMX output pin\n"); | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+69
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Find the DMX output related files
find . -name "*dmx*" -type f | head -20Repository: wled/WLED Length of output: 198 🏁 Script executed: # Look at the full dmx_output.cpp file
wc -l wled00/dmx_output.cppRepository: wled/WLED Length of output: 78 🏁 Script executed: # Check if there's a dmx_output.h header file
find . -name "dmx_output.h" -type fRepository: wled/WLED Length of output: 74 🏁 Script executed: cat -n wled00/dmx_output.hRepository: wled/WLED Length of output: 1031 🏁 Script executed: cat -n wled00/dmx_output.cppRepository: wled/WLED Length of output: 4164 🏁 Script executed: # Search for esp_dmx library references or documentation in the repo
rg -i "esp_dmx" --type h --type cpp | head -20Repository: wled/WLED Length of output: 320 🏁 Script executed: # Check if esp_dmx is included as a dependency
find . -name "esp_dmx*" -type f | head -20Repository: wled/WLED Length of output: 35 🏁 Script executed: # Search for dmx_driver_install or dmx_set_pin usage/definition
rg "dmx_driver_install|dmx_set_pin" --type h --type cppRepository: wled/WLED Length of output: 414 🌐 Web query:
💡 Result: esp_dmx is an open-source ESP32 library by someweisguy (Mitch Weisbrod) for ANSI-ESTA E1.11 DMX-512A and E1.20 RDM over UART ports. Include "esp_dmx.h". dmx_driver_install(dmx_port_t dmx_num, const dmx_config_t *config, const dmx_personality_t *personalities, int personality_count) installs/configures the DMX driver for a UART port. No explicit return type shown in examples or code snippets; called without checking return value, suggesting void. dmx_set_pin(dmx_port_t dmx_num, int tx_pin, int rx_pin, int rts_pin) configures GPIO pins for TX/RX/RTS. Similarly, no explicit return type; used without return check, suggesting void. Usage example from README: const dmx_port_t dmx_num = DMX_NUM_1; dmx_config_t config = DMX_CONFIG_DEFAULT; dmx_personality_t personalities[] = {{1, "Default"}}; int personality_count = 1; dmx_driver_install(dmx_num, &config, personalities, personality_count); dmx_set_pin(dmx_num, 17, 16, -1); Citations:
🌐 Web query:
💡 Result: The function dmx_driver_install from the esp_dmx library (https://github.com/someweisguy/esp_dmx) returns esp_err_t, Espressif's standard error type used across ESP-IDF and Arduino-ESP32 APIs. This is evidenced by its usage in code examples where it is assigned to esp_err_t variables (e.g., esp_err_t dmxError = dmx_driver_install(...);) and consistent with ESP hardware driver patterns like uart_driver_install. Official documentation does not explicitly state the return type in READMEs, but source code patterns and error handling confirm it returns ESP_OK on success or an error code (e.g., ESP_ERR_INVALID_ARG) on failure. The library is compatible with ESP-IDF v4.4.1+ and Arduino-ESP32 v2.0.3+, supporting DMX-512A and RDM over ESP32 UARTs. Citations:
Fix pin allocation leak and correct error handling return types. Line 71 allocates the pin but Additionally, lines 84 and 89 incorrectly assign 🤖 Prompt for AI Agents |
||||||||||||||||
| } | ||||||||||||||||
| void DMXOutput::write(uint8_t channel, uint8_t value) { | ||||||||||||||||
| dmxdata[channel] = value; | ||||||||||||||||
| } | ||||||||||||||||
| void DMXOutput::update() { | ||||||||||||||||
| dmx_write(dmxPort, dmxdata, DMX_PACKET_SIZE); | ||||||||||||||||
| dmx_send(dmxPort, DMX_PACKET_SIZE); | ||||||||||||||||
| } | ||||||||||||||||
| #endif | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| #else | ||||||||||||||||
| void initDMXOutput(){} | ||||||||||||||||
| void handleDMXOutput() {} | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // Created by will on 1/10/26. | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #ifndef DMX_OUTPUT_H | ||||||||||||||||||||||
| #define DMX_OUTPUT_H | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #if defined(ESP8266) | ||||||||||||||||||||||
| #include "src/dependencies/dmx/ESPDMX.h" | ||||||||||||||||||||||
| #else | ||||||||||||||||||||||
| #include <esp_dmx.h> | ||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Support for DMX Output via serial (e.g. max485) on ESP32 | ||||||||||||||||||||||
| * ESP32 Library from: | ||||||||||||||||||||||
| * https://github.com/someweisguy/esp_dmx | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| class DMXOutput | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| public: | ||||||||||||||||||||||
| void init(uint8_t outputPin); | ||||||||||||||||||||||
| void write(uint8_t channel, uint8_t value); | ||||||||||||||||||||||
| void update(); | ||||||||||||||||||||||
| private: | ||||||||||||||||||||||
| byte dmxdata[DMX_PACKET_SIZE]; | ||||||||||||||||||||||
|
Comment on lines
+20
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a 16-bit channel index for DMX writes.
💡 Suggested change- void write(uint8_t channel, uint8_t value);
+ void write(uint16_t channel, uint8_t value);And in -void DMXOutput::write(uint8_t channel, uint8_t value) {
- dmxdata[channel] = value;
+void DMXOutput::write(uint16_t channel, uint8_t value) {
+ if (channel == 0 || channel >= DMX_PACKET_SIZE) return;
+ dmxdata[channel] = value;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| /* Next, lets decide which DMX port to use. The ESP32 has either 2 or 3 ports. | ||||||||||||||||||||||
| Port 0 is typically used to transmit serial data back to your Serial Monitor, | ||||||||||||||||||||||
| so we shouldn't use that port. Lets use port 1! */ | ||||||||||||||||||||||
| dmx_port_t dmxPort = 1; | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| #endif | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #endif //DMX_OUTPUT_H | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,11 +43,12 @@ enum struct PinOwner : uint8_t { | |
| Relay = 0x87, // 'Rly' == Relay pin from configuration | ||
| SPI_RAM = 0x88, // 'SpiR' == SPI RAM | ||
| DebugOut = 0x89, // 'Dbg' == debug output always IO1 | ||
| DMX = 0x8A, // 'DMX' == hard-coded to IO2 | ||
| DMX = 0x8A, // 'DMX' == DMX output via serial | ||
| HW_I2C = 0x8B, // 'I2C' == hardware I2C pins (4&5 on ESP8266, 21&22 on ESP32) | ||
| HW_SPI = 0x8C, // 'SPI' == hardware (V)SPI pins (13,14&15 on ESP8266, 5,18&23 on ESP32) | ||
| DMX_INPUT = 0x8D, // 'DMX_INPUT' == DMX input via serial | ||
| HUB75 = 0x8E, // 'Hub75' == Hub75 driver | ||
| DMX_OUTPUT = 0x8F, // 'DMX_OUTPUT' == DMX output via serial | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo: clean up |
||
| // Use UserMod IDs from const.h here | ||
| UM_Unspecified = USERMOD_ID_UNSPECIFIED, // 0x01 | ||
| UM_Example = USERMOD_ID_EXAMPLE, // 0x02 // Usermod "usermod_v2_example.h" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -473,7 +473,9 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) | |
| arlsDisableGammaCorrection = request->hasArg(F("RG")); | ||
| t = request->arg(F("WO")).toInt(); | ||
| if (t >= -255 && t <= 255) arlsOffset = t; | ||
|
|
||
| #ifdef WLED_ENABLE_DMX | ||
| dmxOutputPin = request->arg(F("IDMO")).toInt(); | ||
| #endif | ||
|
Comment on lines
+476
to
+478
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add server-side bounds validation for Line 477 trusts client input directly. Please clamp/validate the pin range before persisting to avoid invalid DMX output pin state from crafted requests. Suggested fix `#ifdef` WLED_ENABLE_DMX
- dmxOutputPin = request->arg(F("IDMO")).toInt();
+ t = request->arg(F("IDMO")).toInt();
+ if (t >= -1 && t < WLED_NUM_PINS) {
+ dmxOutputPin = t;
+ } else {
+ dmxOutputPin = -1;
+ }
`#endif` |
||
| #ifdef WLED_ENABLE_DMX_INPUT | ||
| dmxInputTransmitPin = request->arg(F("IDMT")).toInt(); | ||
| dmxInputReceivePin = request->arg(F("IDMR")).toInt(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,62 +18,19 @@ | |
| #include "ESPDMX.h" | ||
|
|
||
|
|
||
|
|
||
| #define dmxMaxChannel 512 | ||
| #define defaultMax 32 | ||
|
|
||
| #define DMXSPEED 250000 | ||
| #define DMXFORMAT SERIAL_8N2 | ||
| #define BREAKSPEED 83333 | ||
| #define BREAKFORMAT SERIAL_8N1 | ||
|
|
||
| bool dmxStarted = false; | ||
| int sendPin = 2; //default on ESP8266 | ||
|
|
||
| //DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements | ||
| uint8_t dmxDataStore[dmxMaxChannel+1] = {}; | ||
| int channelSize; | ||
|
|
||
|
|
||
| void DMXESPSerial::init() { | ||
| void DMXESPSerial::init(int sendPin) { | ||
| this->sendPin = sendPin; | ||
| channelSize = defaultMax; | ||
|
Comment on lines
+21
to
23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caps the ESP8266 backend at 32 DMX channels. Line 23 hardcodes 💡 Suggested change- channelSize = defaultMax;
+ channelSize = dmxMaxChannel;If you want shorter frames, plumb the actual highest-used slot into 🤖 Prompt for AI Agents |
||
|
|
||
| Serial1.begin(DMXSPEED); | ||
| pinMode(sendPin, OUTPUT); | ||
| dmxStarted = true; | ||
|
Comment on lines
25
to
27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n wled00/src/dependencies/dmx/ESPDMX.cpp | head -60Repository: wled/WLED Length of output: 1894 🏁 Script executed: cat -n wled00/src/dependencies/dmx/ESPDMX.cppRepository: wled/WLED Length of output: 1965 🏁 Script executed: fd ESPDMX.hRepository: wled/WLED Length of output: 89 🏁 Script executed: cat -n wled00/src/dependencies/dmx/ESPDMX.hRepository: wled/WLED Length of output: 1434 🏁 Script executed: rg "DMXESPSerial" -t cpp -t h -A 3 -B 3Repository: wled/WLED Length of output: 2234 🏁 Script executed: rg "dmx|DMX" -t cpp wled00/pin_manager.cpp -i -A 2 -B 2Repository: wled/WLED Length of output: 914 🏁 Script executed: rg "dmx\.init|DMX.*init" -t cpp -A 2 -B 2Repository: wled/WLED Length of output: 1111 🏁 Script executed: rg "allocatePin|PinOwner::DMX" -t cpp -A 2 -B 2Repository: wled/WLED Length of output: 32042 🏁 Script executed: rg "Serial1|SERIAL.*TX|GPIO.*2" -t cpp wled00/ -i -B 2 -A 2 | head -50Repository: wled/WLED Length of output: 3077 🏁 Script executed: rg "GPIO.?2|TX.*pin|Serial1.*pin" -t h -t cpp -i -B 2 -A 2 | head -80Repository: wled/WLED Length of output: 5090 🏁 Script executed: fd "pins.h|config.h|defaults.h" | head -20Repository: wled/WLED Length of output: 141 🏁 Script executed: rg "GPIO.?2|Serial1" wled00/ -t cpp -t h | grep -i "esp8266\|serial\|pin"Repository: wled/WLED Length of output: 1809 🏁 Script executed: cat -n wled00/src/dependencies/dmx/ESPDMX.cpp | sed -n '44,60p'Repository: wled/WLED Length of output: 534 🏁 Script executed: cat -n wled00/dmx_output.cppRepository: wled/WLED Length of output: 4164 🏁 Script executed: rg "Serial1|UART.*TX|GPIO.*2" wled00/ -t cpp -i -B 1 -A 1 | head -100Repository: wled/WLED Length of output: 7314 🏁 Script executed: rg "ESP8266.*Serial|Serial1.*pin" -t cpp -iRepository: wled/WLED Length of output: 152 🏁 Script executed: web_search
ESP8266 Serial1 TX pin hardware fixed GPIORepository: wled/WLED Length of output: 149 🌐 Web query:
💡 Result: The ESP8266 Serial1 (UART1) TX pin is fixed to GPIO2 by hardware. This is a dedicated hardware connection where UART1 TXD is hard-wired to GPIO2 pin. UART1 RX is not practically usable as its RXD pin is internally connected to the flash chip. In Arduino ESP8266 core, Serial1.begin uses this fixed GPIO2 for TX. Unlike UART0 (Serial), which defaults to GPIO1 (TX) and GPIO3 (RX) but can be swapped to other pins via software (e.g., Serial.swap to GPIO15 TX / GPIO13 RX), UART1 TX remains on GPIO2 and cannot be remapped to other GPIOs due to the fixed hardware mapping. To use Serial1 TX: Serial1.begin(115200); // TX on GPIO2 automatically Sources confirm this across official and technical documentation: - Arduino ESP8266 core reference: "Serial1 uses UART1, TX pin is GPIO2." - ESP8266EX datasheet: GPIO2 listed with UART TX function during flash programming, consistent with UART1 TX. - ESP8266 community wiki: Pin functions map SPECIAL to TX1 on pin 2 (GPIO2). - Espressif FAQ: UART1 TXD for logs/printing, RX occupied by flash. GPIO2 can be used as general GPIO when not using Serial1, but activating Serial1 configures it as TX. Citations:
On ESP8266, Serial1 TX is hard-wired to GPIO2 and cannot be remapped. The 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| // Set up the DMX-Protocol | ||
| void DMXESPSerial::init(int chanQuant) { | ||
|
|
||
| if (chanQuant > dmxMaxChannel || chanQuant <= 0) { | ||
| chanQuant = defaultMax; | ||
| } | ||
|
|
||
| channelSize = chanQuant; | ||
|
|
||
| Serial1.begin(DMXSPEED); | ||
| pinMode(sendPin, OUTPUT); | ||
| dmxStarted = true; | ||
| } | ||
|
|
||
| // Function to read DMX data | ||
| uint8_t DMXESPSerial::read(int Channel) { | ||
| if (dmxStarted == false) init(); | ||
|
|
||
| if (Channel < 1) Channel = 1; | ||
| if (Channel > dmxMaxChannel) Channel = dmxMaxChannel; | ||
| return(dmxDataStore[Channel]); | ||
| } | ||
|
|
||
| // Function to send DMX data | ||
| void DMXESPSerial::write(int Channel, uint8_t value) { | ||
| if (dmxStarted == false) init(); | ||
|
|
||
| if (Channel < 1) Channel = 1; | ||
| if (Channel > channelSize) Channel = channelSize; | ||
| if (value < 0) value = 0; | ||
| if (value > 255) value = 255; | ||
|
|
||
| dmxDataStore[Channel] = value; | ||
| } | ||
|
|
@@ -85,8 +42,6 @@ void DMXESPSerial::end() { | |
| } | ||
|
|
||
| void DMXESPSerial::update() { | ||
| if (dmxStarted == false) init(); | ||
|
|
||
| //Send break | ||
| digitalWrite(sendPin, HIGH); | ||
| Serial1.begin(BREAKSPEED, BREAKFORMAT); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo: remove before merge