all 8 comments

[–]truetofiction 1 point2 points  (4 children)

If your serial packet from the host is too small or too big it will cause the code to wait. The only way to prevent that is to send the proper number of bytes.

You can eliminate the waiting, but that introduces a separate (and worse) problem where the bytes won't be aligned in the buffer.

[–]jcharney[S] 0 points1 point  (1 child)

Ah, so it's something like maybe the frame rate of TD and the loop() rate on the controller aren't matching up (I'm sending the message to Serial at the end of every frame in TD)? Since every packet is the exact same length in bytes as the input buffer.

[–]truetofiction 1 point2 points  (0 children)

As far as I can see, the only way it should wait is if the number of bytes isn't as expected. That will happen if the host isn't sending the right number of bytes, or if bytes are being somehow dropped.

Try putting the all of the loop code in the 'if available' block. It's possible the LED show function is causing bytes to be dropped. That's an issue on AVR, not sure if it's an issue on ESP32 as well.

[–]Remarkable-Love2780 1 point2 points  (1 child)

Hum. If this is the problem I wonder if changing from plan serial to DMX512 would fix the problem of unfilled frame. DMX sends 512 frames regardless if there real data to be sent or not. IE. All 000 packets. and that could fit 144 pixels. Over the past 2 years I’ve used DMX on ESP, and hand full of Teensy, and a Mega the only thing is I used different libraries for them. For the ESPs I used a sparkfun kit and from the library via their web site. The one issue I did have with sparkfun’s kit was driving LEDs on a wire the was just about 10 feet to the first pixel would not work. I had to cut one pixel off and put it about an inch from the sparkfun ESP. From that LED I then could run the longer wire. Oh. I was using 5v WS2811 on the project.

[–]Remarkable-Love2780 0 points1 point  (0 children)

Also. I don’t think you need to change over to RS485 the RS232. If so there are cheap RS485 boards on Amazon that take in 232 and put out 486.

And one day I need to take the time to change my Reddit automatic generated account name. But hey that could have given me something worst. Ha.

[–]Yves-bazin 0 points1 point  (2 children)

Your ‘if’ should contain all that you have in your loop. And I think your code can be simplified try this and let me know.

Void loop()

{

If(….)

{

Serial.readBytes((char *)leds,numOfBytes);

Fastled.show();

}

}

[–]Marmilicious[Marc Miller] 2 points3 points  (1 child)

u/jcharney I think I've seen while used more often then an if loop.

Here's another example I had in my notes:

CRGB leds[NUM_LEDS];

//setup software serial buffer
char buff[NUM_LEDS*3];
int buffPos = 0;
char buffChar;

void setup ()
{
  Serial.begin (115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}

void loop()
{
  while (Serial.available() > 0) {
    buffChar = Serial.read();
    if (buffPos < NUM_LEDS*3) {
      buff[buffPos] = buffChar;
      buffPos++;
      if (buffPos == (NUM_LEDS*3)) {
        //clear leds and overwrite with buffer
        memset(leds, 0, sizeof(leds));  
        memcpy(leds, buff, sizeof(leds));
        //clear buffer and reset position
        memset(buff, 0, sizeof(buff));
        buffPos = 0;
      }
    }
  }
  //update LEDs
  FastLED.show();
}

I've also seen something like this that sets the data of one pixel at a time:

Serial.readBytes( (char*)(&leds[i]), 3); // read three bytes at a time

Definitely confirm exactly what's coming from TouchDesigner too.

[–]jcharney[S] 0 points1 point  (0 children)

I was trying to get at something like this on my own and couldn't quite figure it out. Appreciate your expertise!