Arduino串行输出删除字符 [英] Arduino Serial Output Dropping Characters
问题描述
在尝试为Arduino Uno编写一些代码时,我在这里有一个奇怪的串行输出.
I have a bizarre one here with the serial output when trying to write some code for my Arduino Uno.
我有这个原始代码:
MyClass myclass;
void setup()
{
Serial.Begin(9600);
Serial.println("Starting...");
}
void loop()
{
int status = myclass.DoWork();
Serial.println("Status: " + status);
}
class MyClass
{
int DoWork()
{
Serial.println("Doing some work...");
return 1;
}
}
现在,当它运行时,我得到以下输出:
Now when this runs I get the following output:
开始...
做些工作...
atus:1
因此,奇怪的部分是状态:1"缺少前几个字符.这是因为我在对象中不正确地使用了串行还是什么?
So the strange part is the "Status: 1" missing the first few characters. Is this because I am using serial in an object improperly or something?
当我引用另一个像MyClass这样也使用串行接口的库时,我注意到我得到了其他奇怪的输出行为...所以我以为我做错了事.
I have noticed when I reference another library that also uses serial like MyClass does that I get other strange output behavior... so I assume that I am doing something wrong.
编辑:最后,这实际上是内存问题.我包括的一个库非常大,它正在消耗可用的内存.我通过添加更多调试语句发现了这一点,并发现损坏根据字符串的长度和位置而转移.通过使用F()函数,我将字符串移动到了闪存中(例如,我现在运行Serial.println(F("Starting ..."));它已经纠正了奇怪的输出.
In the end this turned out to actually be a memory issue. A library I was including was quite large and it was consuming the available memory. I found this by adding a few more debugging statements and found the corruption shifted around based on the string lengths and positions. By using the F() function I moved the strings to flash memory (e.g. I now run Serial.println(F("Starting...")); and it has corrected the strange output.
推荐答案
最后,这实际上是内存问题.我包括的一个库非常大,它正在消耗可用的内存.我通过添加更多调试语句发现了这一点,并发现损坏根据字符串的长度和位置而转移.通过使用F()函数,我将字符串移动到了闪存中(例如,我现在运行Serial.println(F("Starting ..."));它已经纠正了奇怪的输出.
In the end this turned out to actually be a memory issue. A library I was including was quite large and it was consuming the available memory. I found this by adding a few more debugging statements and found the corruption shifted around based on the string lengths and positions. By using the F() function I moved the strings to flash memory (e.g. I now run Serial.println(F("Starting...")); and it has corrected the strange output.
这篇关于Arduino串行输出删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!