慢周期通信matlab-arduino

时间:2017-02-01 00:18:48

标签: matlab arduino serial-communication

首先我从Matlab向Arduino发送数据,然后arduino继续处理这些数据并向Matlab发送消息'Ready'给他发送一个新消息。但这种定期沟通非常缓慢。

这是我的Matlab代码:

Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
Serial.setTimeout(100);

我在Arduino中的设置是:

/*QuickReset*/ *{margin:0; box-sizing:border-box;} html,body{height:100%;}

/*
OP: -I am looking to create a website in which it has a
main div in which both the width and the height is
always the size of the screen
A: -let this be body!
*/
body{
  background: #0ae;
  display: flex;
  flex-flow: row nowrap;
  padding: 40px;
}

/*
OP: -My aim is for the navigation section to be
contained in the large blue part on the left
A: -Thanks to CSS3 flexbox on body all you need is a desired menu width:
*/
aside{
  width: 140px;      /* or any size you want, px, %, ... */
}

/*
OP: -and for the main page content to be displayed within
the white box and for this white div to only scroll sideways
A: -add overflow:auto; to make it scroll and flex:1 to grow to available size
*/
article{
  background: #fff;
  overflow: auto;    /* make element scrollable */
  flex: 1;           /* let the browser grow this element */
}

/* just to demonstrate sideways scroll */
article{
  display: flex;
  flex-flow: row nowrap;
}
section{
  min-width:100%;
}

还有另一种发送定期数据的方法吗?

谢谢

1 个答案:

答案 0 :(得分:0)

根据您的解释,我认为您的代码不合适。我已经理解Matlab等待准备好了#39;从arduino,然后它可以立即发送新消息。因此,您不必每次都关闭序列并重新打开它;这部分增加了至少1秒的延迟!

您必须在for循环之外放置开始和结束序列。

为了提高可靠性,您应该将sleep(1)增加到sleep(2)

此外,在打开它之前,arduino串行缓冲区中可能有垃圾;如果你遇到这个,那么你可以从arduino串口读取以清空缓冲区(就在sleep(2)指令之后)。