Home > front end >  How do I optimize serial communication for large data strings?
How do I optimize serial communication for large data strings?

Time:12-26

I'm working with an Arduino Uno and WS2812b LED stripes.

What I'm trying to do:

So I've a 12 x 10 grid of LEDs and I've made a software that maps these LEDs to a texture of the same size, which I can draw to. I now want to make multiple textures and send them one by one to the arduino to create something like an animation, so that I don't have to code the pixel positions by myself.

The problem:

If I just sent this data over as numbers in a string, I'd need 120 * 12 Bytes = 1440 Bytes for the buffer size. I've tried to convert the numbers into hex values. But then I still need 960 Bytes for the buffer. Any higher bases won't help here, because even with base36 I'd need 2 characters to represent 255.

My approaches:

  • I can change the buffer size for the Arduino to 960 but then the RAM is 99% used up and the arduino software tells me that stability problems can occour and I guess that is happening, because this approach does not work.
  • Another approach was to use ASCII characters for each value from 0 to 255. That could reduce the total amount of bytes to 480 but the Arduino only knows 128 and the first 32 are taken by the system.
  • I've also tried to send the data sequentially with different buffer sizes but the serial communication is to slow. You can see how it "draws" the image from top to bottom. So I really want to draw it all at once.

Can I somehow extend the ASCII character table or make my own? Or can I send the raw byte data over to the arduino instead of using strings/char arrays?

Or do you have other approaches? I'm really curious.

CodePudding user response:

RGB has 3 bytes and addressing a single led of 120 takes 1 byte. Why you believe that it takes 12 byte instead of 4? Maybe you have to add some internal index to real address translation.

And if you send always all pixels, there is no need to send the address at all. Makes 360 bytes some start sync which can be a "break" on the serial line.

At 115200 this will end by around 30 fps.

In addition you can take some "packing" like sending a color map once before and select with 1 byte from a color map of 256 colors which ends in 90 fps.

CodePudding user response:

I have now a more or less good solution.

I just send over the LED index as a hex string combined with a char that tells me if it turns on or off. That reduces the total amount to 360 Bytes but I can only set the colors on the arduino side.

  • Related