快速串行端口写从加工到Arduino的 [英] Rapid Serial Port writing to Arduino from Processing

查看:109
本文介绍了快速串行端口写从加工到Arduino的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助加快写连载。我发现这个,但没有什么处理的处理语言或Java,所以我希望有人可以帮我这个问题,我有几个类似的问题。

I need some help speeding up writing to serial. I found a few similar questions to this but nothing that dealt with the Processing language or Java so I'm hoping someone can help me with this issue I have.

修改

正如约翰低于所指出的,它出现串行只是没有足够快,在我想要的速度发送这么多的数据。有谁知道可用其他的Arduino接口?

As John points out below, it appears serial just isn't fast enough to send this much data at the speed I want. Does anyone know of other arduino interfaces that are available?

年底修改

我使用一个Arduino控制400 RGB LED的我已经迷上了网格。将命令发送到Arduino我写在处理一个小程序,操作一个大的阵列重新presents的LED。我再试图通过115200波特通过串口发送800字节的数据,到Arduino每20ms更新电网。该处理code,它被称为每20ms是:

I am using an arduino to control a grid of 400 RGB LEDs I have hooked up. To send commands to the arduino I wrote a small program in Processing that manipulates a large array that represents the LEDs. I am then attempting to update the grid by sending 800 bytes of data to the arduino every 20ms at 115200 baud over serial. The Processing code that is called every 20ms is:

  noStroke();
  int dataPos = 0; // position in LED data array
  byte[] dataLedGrid = new byte[400*2]; // array for bytes to send
  for(int j=0; j<LEDS_TALL; j++) {
    for(int i=0; i<LEDS_WIDE; i++) {
      int pos = j*20+i;
      int r = ledGrid[LEDS_WIDE-i-1][LEDS_TALL-j-1][0], g = ledGrid[LEDS_WIDE-i-1][LEDS_TALL-j-1][1] ,b = ledGrid[LEDS_WIDE-i-1][LEDS_TALL-j-1][2];
      int colorData = ((g & 0x1F) << 10) | ((b & 0x1F) << 5) | (r & 0x1F);
      dataLedGrid[dataPos] = byte(colorData & 0x00FF);
      dataLedGrid[dataPos+1] = byte(colorData & 0xFF00);
      dataPos+=2;

      // draw LED squares on gui
      fill(ledGrid[i][j][0], ledGrid[i][j][1], ledGrid[i][j][2]);
      rect(SIDE_PANEL_WIDTH+(LED_SQUARE_SIDE+LED_SQUARE_SPACING)*i+HORIZONTAL_MARGIN,
      (LED_SQUARE_SIDE+LED_SQUARE_SPACING)*j+VERTICAL_MARGIN, 
      LED_SQUARE_SIDE, LED_SQUARE_SIDE);
    }
  }
  myPort.write(dataLedGrid); // write to serial

在Arduino的我有一维数组(显示屏)重新presents Arduino上侧的电网。循环code是:

On the arduino I have a 1D array (Display) that represents the grid on the arduino side. The loop code is:

void loop() {

  unsigned int pos, c1, c2;

  if (Serial.available() > 0) {
    for(byte j=0; j<20; ++j) {
        for(byte i=0; i<20; ++i) {
          c1 = Serial.read();
          c2 = Serial.read();

          pos = i+20*j;
          if(j % 2 != 0)         // it's a square of leds created by a zigzaging line
            pos = 20*(j+1)-i-1;  // so I have to reverse every other line

          Display[pos] = (unsigned int)(c1<<8 | c2);
        }
    }
    show();
  }
}

现在的code本身工作正常,但是当串行编程减缓都记录下来。当我运行处理code,而不串写一切都很好,在预定的速度运行。然而,当我在加串行编程,一切都变得有些不稳定。该CPU没有最大输出或任何东西,所以我假设它的serial.write方法我打电话。我能做些什么来加快这一code或串行编程删除滞后?

Now the code itself works fine but when the serial writing slows everything down. When I run the Processing code without the serial writing everything is fine an runs at the intended speed. However, when I add the serial writing in, everything becomes slightly choppy. The CPU doesn't max out or anything so I'm assuming it's the serial.write method I am calling. What can I do to speed up this code or remove the lag from serial writing?

感谢您的帮助!

推荐答案

你算算。

115200波特,8-N-1,每秒11,520字节,或86.8微秒/字节。

115200 baud is, at 8-N-1, 11,520 bytes per second, or 86.8 usec/byte.

在20毫秒,可以发送230.4个字节。发送800字节大约需要70毫秒。

In 20 msec, you can send 230.4 bytes. Sending 800 bytes will take about 70 msec.

试图115200波特率每20毫秒是行不通发送800字节。

Trying to send 800 bytes at 115200 baud every 20 msec isn't going to work.

这篇关于快速串行端口写从加工到Arduino的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆