使用监视器和模拟刻板时的怪异行为(ESP32)

发布于 2025-01-23 21:02:23 字数 1169 浏览 0 评论 0 原文

我目前正在从事一个项目,在该项目中,我想将PWM更改为电动机的输入。但是,我似乎无法在同一程序中使用串行监视器和模拟文章。

当我运行此代码时,我会从串行监视器中获取此输出:

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  //analogWrite(1, 255);
}

void loop()
{
  
}
12:09:48.314 -> 
12:09:48.314 -> WORKING

但是,当我运行此代码时(唯一的区别是 AlalogWrite() line不再注释),串行监视器输出垃圾。

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  analogWrite(1, 255);
}

void loop()
{
  
}
{l$ܞ⸮⸮$⸮|⸮⸮l⸮#|⸮⸮⸮⸮{⸮#⸮"⸮⸮on⸮lon⸮⸮⸮#p⸮⸮bl`{lp⸮o⸮⸮l⸮⸮bo⸮|⸮⸮⸮#⸮⸮nN⸮$⸮⸮$`⸮on⸮{lor⸮⸮⸮⸮{r⸮ p⸮o⸮s⸮ܜ⸮⸮⸮#o⸮|⸮B⸮⸮on⸮⸮l ⸮No⸮{lor⸮⸮⸮Nrd`{⸮⸮N{d`⸮⸮⸮⸮⸮⸮$`⸮⸮N⸮l
⸮

有人知道为什么会发生这种情况以及如何解决吗?

不确定是否有帮助,但是我使用从这个惊人链接购买的ESP8266 nodemcu:

I'm currently working on a project where I want to vary the PWM to a motor given an input from a potentiometer. However, I cant seem to use the serial monitor and an analogWrite statement in the same program.

When I run this code I get this output from the serial monitor:

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  //analogWrite(1, 255);
}

void loop()
{
  
}
12:09:48.314 -> 
12:09:48.314 -> WORKING

However, when I run this code (the only difference is that the analogWrite() line is no longer commented out), the serial monitor outputs garbage.

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  analogWrite(1, 255);
}

void loop()
{
  
}
{l$ܞ⸮⸮$⸮|⸮⸮l⸮#|⸮⸮⸮⸮{⸮#⸮"⸮⸮on⸮lon⸮⸮⸮#p⸮⸮bl`{lp⸮o⸮⸮l⸮⸮bo⸮|⸮⸮⸮#⸮⸮nN⸮$⸮⸮

I'm currently working on a project where I want to vary the PWM to a motor given an input from a potentiometer. However, I cant seem to use the serial monitor and an analogWrite statement in the same program.

When I run this code I get this output from the serial monitor:

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  //analogWrite(1, 255);
}

void loop()
{
  
}
12:09:48.314 -> 
12:09:48.314 -> WORKING

However, when I run this code (the only difference is that the analogWrite() line is no longer commented out), the serial monitor outputs garbage.

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  analogWrite(1, 255);
}

void loop()
{
  
}
⸮on⸮{lor⸮⸮⸮⸮ {r⸮ p⸮o⸮ s⸮ܜ⸮⸮⸮ # o⸮| ⸮ B⸮⸮on⸮ ⸮l ⸮No⸮{lor⸮⸮⸮N rd`{⸮⸮N {d`⸮ ⸮⸮⸮⸮⸮

I'm currently working on a project where I want to vary the PWM to a motor given an input from a potentiometer. However, I cant seem to use the serial monitor and an analogWrite statement in the same program.

When I run this code I get this output from the serial monitor:

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  //analogWrite(1, 255);
}

void loop()
{
  
}
12:09:48.314 -> 
12:09:48.314 -> WORKING

However, when I run this code (the only difference is that the analogWrite() line is no longer commented out), the serial monitor outputs garbage.

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

  Serial.println();
  Serial.println();
  Serial.print("WORKING");

  analogWrite(1, 255);
}

void loop()
{
  
}
⸮⸮N⸮l ⸮

Does anyone know why this is happening and how to fix it?

Not sure if it helps but im using an ESP8266 NodeMCU purchased from this amazing link: https://www.amazon.com/gp/product/B081CSJV2V/ref=ppx_yo_dt_b_asin_title_o07_s00?ie=UTF8&th=1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

揪着可爱 2025-01-30 21:02:23

模拟Write(1,255)写入GPIO1。如果您查看ESP8266 nodemcu的引脚,则GPIO1是串行端口0的TXD线(它标记为TXD0)。我没有nodemcu示意图方便的方便,但是端口0通常用于串行显示器,并将其连接到USB-UART转换器为此目的。因此,通过写入GPIO1,您正在干扰监视器输出。

尝试将模拟Write 对其他GPIO进行,例如GPIO5。

analogWrite(1, 255) is writting to GPIO1. If you look at the pin-out for the ESP8266 NodeMCU, GPIO1 is the TXD line for serial port 0 (it's labeled TXD0). I don't have a NodeMCU schematic handy, but port 0 is typically used for the serial monitor and wired to the USB-UART converter for that purpose. So by writing to GPIO1, you are interfering with the monitor output.

Try doing an analogWrite to a different GPIO, for example, GPIO5.

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