SparkFunDMX icon indicating copy to clipboard operation
SparkFunDMX copied to clipboard

Alignment issue on ESP32-S2 Thing Plus

Open flupke opened this issue 1 year ago • 2 comments

Starting from Example2-DMXInput and after finding this comment I changed the example to dmxSerial(1) and enPin = 3 and started receiving values from my DMX controller.

However the values read on channel 1 was changing constantly in a seemingly random way.

I tried to display 192 channels with this code from another comment in the same issue:

#include <SparkFunDMX.h>

SparkFunDMX dmx;
HardwareSerial dmxSerial(1);
uint8_t enPin = 3;
uint16_t numChannels = 192;

void setup()
{
    Serial.begin(115200);
    Serial.println("SparkFun DMX Example 2 - Input");

    dmxSerial.begin(DMX_BAUD, DMX_FORMAT);
    dmx.begin(dmxSerial, enPin, numChannels);
    dmx.setComDir(DMX_READ_DIR);

    Serial.println("DMX initialized!");
}

void loop()
{
    while(dmx.dataAvailable() == false)
    {
        dmx.update();
    }

    uint8_t data[numChannels];
    dmx.readBytes(data, numChannels, 1);
    
    for (int i=0; i < numChannels; i++) {
      if (i%32 == 0) {
        Serial.printf("\n(%3d)   ", i+1);
      }

      Serial.printf("%3d ", data[i]);
    }
    Serial.printf("\n");

    delay(1000);
}

I see values are "shifted" after each read, for example look at how the 134 89 22 sequence moves around between two reads:

  1)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0 
( 33)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0 
( 65)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0 
( 97)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0 
(129)     0   0   0   0   0   0   0   0   0   0   0   0   0 255 247   0 134  89  22   0   0   0   0   0   0   0   0   0 255 255 160 244 
(161)     0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244 

(  1)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0 
( 33)     0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160   0 255 255 
( 65)   160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0   0   0 
( 97)     0 255 247   0 134  89  22   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 
(129)   255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 
(161)   255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 255 255 160 244   0   0   0   0   0   0   0   0   0   0   0   0 

Does that ring a bell?

flupke avatar May 01 '24 12:05 flupke

Hi there, apologies for the long response time!

This looks like a synchronization issue, which is probably caused by the large percentage of zeros sent by your controller. Could you please try removing the delay from your loop()? I suspect dmx.update(); isn't being called frequently enough, causing the RX buffer to be overflowed by a random amount before dmx.update(); is called again.

sfe-SparkFro avatar Jun 24 '24 22:06 sfe-SparkFro

Hi there, apologies for the long response time!

This looks like a synchronization issue, which is probably caused by the large percentage of zeros sent by your controller. Could you please try removing the delay from your loop()? I suspect dmx.update(); isn't being called frequently enough, causing the RX buffer to be overflowed by a random amount before dmx.update(); is called again.

The result is the same without sleep, and the amount of zeros is not something we can control.

It's too late now unfortunately, for my next project (actually the same one but hopefully we'll get it to work this time), I think I'll just use another protocol, dmx seems very hacky and unreliable 🙂

flupke avatar Jul 25 '24 21:07 flupke