Buttermilch
Buttermilch

Reputation: 45

How do I optimize serial communication for large data strings?

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:

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.

Upvotes: 0

Views: 544

Answers (2)

Klaus
Klaus

Reputation: 25623

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.

Upvotes: 0

Buttermilch
Buttermilch

Reputation: 45

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.

Upvotes: 0

Related Questions