使用 Serial.print 的奇怪初始输出 [英] Strange initial output using Serial.print

查看:28
本文介绍了使用 Serial.print 的奇怪初始输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向串行接口写入数据时,我的草图第一次运行时会出现奇怪且意外的输出.输出似乎是应该打印的内容的变体:

When I'm writing to the serial interface, I'm getting strange and unexpected output when my sketches first run. The output seems to be a variant of what should be printed:

例如:

String text1 = "foobar";

void setup() {
  Serial.begin(9600);

  Serial.print("\n");
  Serial.print(text1);
}

void loop() {
}

输出结果:

fo
foobar

(新行出现在fo"之前,但我不知道如何包含它).

(the new line appears before "fo" but I couldn't work out how to include it).

因此,应该打印的任何变体都会在应该打印的实际文本之前打印.改变输出,改变异常文本(有时是两个字符,有时是三个).进行不影响输出和重新编译的更改对异常文本没有影响.

So some variant of whatever is supposed to be printed, gets printed before the actual text that is supposed to be printed. Changing the output, changes the anomalous text (sometimes it'll be two characters, sometimes three). Making changes that don't affect the output and recompiling has no effect on the anomalous text.

我完全是 Arduino 新手(我今天才开始编写自己的代码),但我只能假设这不正常.我使用的是 Freetronics EtherTen 和 1.0 IDE

I'm a total Arduino newbie (I only started writing my own code today), but I can only assume this isn't normal. I'm using a Freetronics EtherTen and the 1.0 IDE

提前致谢

推荐答案

这很可能是 Eran W 指出的串行通信重置问题.在此处查看我之前的回答.

This is most likely a Serial communication Reset issue as Eran W pointed out. See my previous answer here.

当 Arduino 收到来自除 Arduino IDE 以外的大多数事物的串行通信时,它会自动重置.这就是为什么您可以从 IDE 发送但不能从其他任何内容发送的原因.

The Arduino automatically resets when it receives serial communication from most things other than the Arduino IDE. This is why you can send from the IDE but not anything else.

我有一个 Uno 并在复位和接地之间放置了一个电容器.这是一个页面,其中包含有关该主题的一些很好的信息.
祝你好运.http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

I have an Uno and put a capacitor between Reset and Ground.Here's a page with some good info on the subject.
Good luck. http://arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection

这篇关于使用 Serial.print 的奇怪初始输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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