我目前正在从事一个项目,在该项目中,我想将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⸮⸮⸮Nrd`{⸮⸮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⸮⸮⸮Nrd`{⸮⸮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
发布评论
评论(1)
模拟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.