someweisguy / esp_dmx

Espressif ESP32 implementation of ANSI-ESTA E1.11 DMX-512A and E1.20 RDM
MIT License
335 stars 35 forks source link

dmx timing #101

Closed DeverosTV closed 12 months ago

DeverosTV commented 1 year ago

greetings. i have been working with this library (using connox project) and it has been working so far.

but i run into an issue with a chinese hazer, someone on facebook brought the issue it could be dmx timing going bad on the hazer. i read that we can manually configurate the dmx timing with this library, i found the code you use to mention this, but i do not know for sure where and what numbers to use to try this. can i ask some pointers please?

i have an issue connected later to this hazer and it does not work either. if i use another kind of dmx controller, all works as intended (but i love using qlc so far)

someweisguy commented 1 year ago

Absolutely - there are two pairs of getters/setters that is used for updating the DMX timing in this library: dmx_set_break_len() and dmx_set_mab_len(). There are getters for these functions as well. Just replace the _set_ with _get_. The setters will set the break or MAB length to a specified value in microseconds. The getters will return a value in microseconds.

The DMX break length can be set to any value between 92 micros (DMX_BREAK_LEN_MIN_US) and 1,000,000 micros (DMX_BREAK_LEN_MAX_US). The default break length is 176 micros (DMX_BREAK_LEN_US). The DMX MAB length can be set to any value between 12 micros (DMX_MAB_LEN_MIN_US) and 999,999 micros (DMX_MAB_LEN_MAX_US). The default MAB length is 12 micros (DMX_MAB_LEN_US).

If you're using RDM, there are RDM-specific constants that should be used instead, e.g. RDM_BREAK_LEN_MAX_US or RDM_MAB_LEN_MAX_US.

You can also update the DMX framerate. I suspect this is what needs to be done to fix the issue with your hazer. There isn't a function used to update the framerate. You would need to update the framerate in your own code. To do this, you would have to add a delay to your code before calling dmx_send(). An easy way to accomplish this would be to add a call to delay() if you're using Arduino or vTaskDelay() if you're using ESP-IDF.

Here's a somewhat naive example DMX loop with the delay for Arduino:

void loop() {
  dmx_write(dmxPort, data, DMX_PACKET_SIZE);
  dmx_send(dmxPort, DMX_PACKET_SIZE);

  dmx_wait_sent(dmxPort, DMX_TIMEOUT_TICK);

  delay(20);  // Wait 20ms before sending the next packet
}

Hopefully this is helpful! Let me know if you have any other questions!