我在处理和Arduino在同一个串行端口上交谈时遇到了问题。为了简化我的问题,我编写了一个简单的程序,其中处理发送" Processing : Hello!“每一秒,Arduino都会发送"Arduino:你好!“每一秒,都到同一个串口。以下是代码:
处理代码:
import processing.serial.*; //import the Serial library
Serial mySerial; //the Serial port object
void delay(int time)
{
int start = millis();
while (millis() - start < time){}
}
void setup()
{
size(200, 200);
println(Serial.list());
mySerial = new Serial(this, Serial.list()[9], 9600);
println(Serial.list()[9]);
mySerial.bufferUntil('\n');
}
void serialEvent( Serial mySerial)
{
mySerial.write("Processing: Hello!");
delay(1000);
}ARUDINO代码:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Arduino: Hello there!");
delay(1000);
}我认为我应该在Arduino草图上的串行监视器上看到的是:
"Arduino: Hello there!"
"Processing: Hello!"
"Arduino: Hello there!"
"Processing: Hello!"
"Arduino: Hello there!"
"Processing: Hello!"
...我真正看到的是:
"Arduino: Hello there!"
"Arduino: Hello there!"
"Arduino: Hello there!"
"Arduino: Hello there!"
...好吧,也许串行监视器只监视Arduino输出。那么,有没有其他方法可以查看Arduino端的处理输出?
发布于 2014-06-29 17:13:36
Arduino中的串行监视器就像一个单独的终端程序,因此它和您的处理草图都在竞争与Arduino的相同的串行连接(看起来串行监视器正在获胜。
Arduino的“示例”包括一个名为“SerialCallResponse”的示例。它包括处理代码来演示您想要做的事情。与Arduino一起提供的示例对于这些基本内容是非常完整的;绝对值得一看。
(此外,在处理草图中,调用serialEvent时不会读取串行输入,因此即使没有串行监视器冲突,也不会看到任何Arduino响应。参见上面引用的示例。)
发布于 2019-02-02 07:33:29
我以前也经历过这种事。如果您有来自arduino网站的zip版本,您可以重新安装IDE。
https://stackoverflow.com/questions/24477459
复制相似问题