在 Arduino IDE 中使用串行监视器(为什么可以工作?)

发布于 2024-10-03 17:24:51 字数 606 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮萍、无处依 2024-10-10 17:24:51

Arduino 软件重置意味着只要连接串行监视器,Arduino 就会自动重置。您是否注意到这种行为?这可能是原因吗?

要关闭自动重置,可以剪掉一条痕迹。如果您想重新打开该功能,重新焊接很容易。

这个 Arduino Wiki 页面可能会有所帮助。

S

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.

S

靖瑶 2024-10-10 17:24:51

串行监视器仅对板进行重置。只需在运行代码之前尝试重置mega即可。

The serial monitor only does RESET to the board. Just try and reset the mega before you run your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文