简体   繁体   English

如何优化大数据字符串的串行通信?

[英]How do I optimize serial communication for large data strings?

I'm working with an Arduino Uno and WS2812b LED stripes.我正在使用 Arduino Uno 和 WS2812b LED 灯条。

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.所以我有一个 12 x 10 的 LED 网格,我制作了一个软件,可以将这些 LED 映射到相同大小的纹理上,我可以绘制到该纹理上。 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.我现在想制作多个纹理并将它们一一发送到 arduino 以创建类似 animation 的东西,这样我就不必自己编码像素位置了。

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.如果我只是将此数据作为字符串中的数字发送,则缓冲区大小需要 120 * 12 字节 = 1440 字节。 I've tried to convert the numbers into hex values.我试图将数字转换为十六进制值。 But then I still need 960 Bytes for the buffer.但是我仍然需要 960 字节的缓冲区。 Any higher bases won't help here, because even with base36 I'd need 2 characters to represent 255.任何更高的基数在这里都无济于事,因为即使使用 base36,我也需要 2 个字符来表示 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.我可以将 Arduino 的缓冲区大小更改为 960,但随后 RAM 已用完 99%,arduino 软件告诉我可能会出现稳定性问题,我猜这正在发生,因为这种方法不起作用。
  • 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.另一种方法是对从 0 到 255 的每个值使用 ASCII 字符。这可以将字节总数减少到 480,但 Arduino 只知道 128,前 32 个由系统占用。
  • 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?我可以以某种方式扩展 ASCII 字符表或制作自己的字符表吗? Or can I send the raw byte data over to the arduino instead of using strings/char arrays?或者我可以将原始字节数据发送到 arduino 而不是使用字符串/字符 arrays?

Or do you have other approaches?或者你有其他方法吗? I'm really curious.我真的很好奇。

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.我只是将 LED 索引作为十六进制字符串发送,并结合一个字符告诉我它是打开还是关闭。 That reduces the total amount to 360 Bytes but I can only set the colors on the arduino side.这将总量减少到 360 字节,但我只能在 arduino 端设置 colors。

RGB has 3 bytes and addressing a single led of 120 takes 1 byte. RGB 有 3 个字节,寻址一个 120 的 LED 需要 1 个字节。 Why you believe that it takes 12 byte instead of 4?为什么您认为它需要 12 个字节而不是 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.使 360 字节 + 一些开始同步,这可能是串行线路上的“中断”。

At 115200 this will end by around 30 fps.在 115200 处,这将以 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. 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM