在 Arduino IDE 中使用串行监视器(为什么可以工作?)
我在 Arduino 上写入串行数据时遇到一个特殊问题。我最近将项目中的板从 Duemilanove 更改为 Mega2560。我的部分代码从处理程序中执行非常简单的串行读取,例如:
if (Serial.available() > 0) {
byte c = Serial.read();
}
在设置方法中,我打开一个 115200 波特率连接:
Serial.begin(115200);
无论如何,这在 Duemilanove 上工作得很好,但现在我切换到 Mega2560,Arduino 就不行了似乎正在接收串行数据。然而,令我惊讶的是,当我在启动发送数据的处理程序之前打开串行监视器窗口时,所有数据都正确发送。
我的问题是,串行监视器发生了什么变化才能使一切正常工作,以及如何在我的处理程序中重新创建它?
I have a peculiar problem with writing to serial on an Arduino. I recently changed boards in a project from the Duemilanove to the Mega2560. Part of my code does very simple serial reading from a processing program, for example:
if (Serial.available() > 0) {
byte c = Serial.read();
}
In the setup method I open a 115200 Baud connection with:
Serial.begin(115200);
Anyhow, this worked fine with the Duemilanove but now that I switched to the Mega2560 the Arduino doesn't seem to be receiving serial data. However, to my amazement when I open the serial monitor window before launching the processing program that sends the data, all of the data is sent correctly.
My question is, what does the serial monitor change that makes everything work and how can I recreate that in my processing program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Arduino 软件重置意味着只要连接串行监视器,Arduino 就会自动重置。您是否注意到这种行为?这可能是原因吗?
要关闭自动重置,可以剪掉一条痕迹。如果您想重新打开该功能,重新焊接很容易。
这个 Arduino Wiki 页面可能会有所帮助。
The Arduino software reset means whenever a serial monitor is connected, the Arduino is auto-reset. Have you noticed this behavior and could this be the cause?
To turn off auto-reset there is a trace that can be cut. It is easy to resolder if you want to turn the feature back on.
This Arduino Wiki Page may be helpful.
串行监视器仅对板进行重置。只需在运行代码之前尝试重置mega即可。
The serial monitor only does RESET to the board. Just try and reset the mega before you run your code.