英文:
ESP32 Connected to GPS module. No serial out unless holding down reset button
问题
我是新手使用Arduino,遇到了一些问题。我将一个16E TTL GPS模块连接到我的NodeMCU ESP32开发板的RX和TX引脚上,并编写了一个简单的Arduino程序,用于将数据输出到串行监视器。
String data = "";
void setup() {
// 放置设置代码在这里,只运行一次:
Serial.begin(9600);
}
void loop() {
data = Serial.read();
Serial.print(data);
delay(500);
}
只有在我按住开发板上的RST按钮时,我才能在串行监视器中看到GPS数据,并且在每个循环中都会输出"-1"。
我尝试过查找问题,但似乎找不到解决方案,我也尝试详细了解如何使用串行通信,但我承认我感到困惑。我原本期望数据会在每个循环中打印出来。
英文:
I'm new to Arduino and I'm having some trouble. I have a 16E TTL GPS module connected to the RX and TX pins on my NodeMCU ESP32 board and have a simple Arduino sketch i wrote to output the data to the serial monitor.
String data = "";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
data = Serial.read();
Serial.print(data);
delay(500);
}
I am only getting the GPS data in the serial monitor while I am holding down the RST button on the board and an output of "-1" every cycle otherwise.
I have tried looking up the problem but I cant seem to find a solution and I have tried figuring out how to use serial in detail but I'm admittedly confused.
I expected the data to just be printed every loop.
答案1
得分: 1
你现在正在同时使用Serial
来输出调试信息和与GPS通信。
你连接GPS的RX和TX引脚与USB串口芯片连接的串口是相同的。每次你写入Serial
时,它会同时发送到USB端口和GPS。因此,当你从GPS读取任何内容时,你会立即将其写回。
串口一次只能用于一种用途。由于它连接到USB串口芯片,你最好使用第二个串口来与GPS通信。
例如:
#define RX1_PIN 9
#define TX1_PIN 10
String data = "";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, RX1_PIN, TX1_PIN);
}
void loop() {
data = Serial1.read();
Serial.print(data);
delay(500);
}
你应该将RX1_PIN和TX1_PIN设置为对你方便的引脚号码;只需确保它们是你的开发板上可用的引脚,并且没有被用于其他用途。
英文:
You're using Serial
both to output debugging messages and to talk to the GPS.
The RX and TX pins that you connected the GPS to are the same serial port as the USB serial chip connects to. Every time you write something Serial
it goes to both the USB port and the GPS. So when you read anything from the GPS, you immediately write it back to it.
You can only use the serial port for one thing at a time. Since it's connected to a USB serial chip, your best bet is to use a second serial port for the GPS.
For instance:
#define RX1_PIN 9
#define TX1_PIN 10
String data = "";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(9600, SERIAL_8N1, RX1_PIN, TX1_PIN);
}
void loop() {
data = Serial1.read();
Serial.print(data);
delay(500);
}
You should set RX_1PIN and TX1_PIN to be whatever pin numbers are convenient for you; just be sure that they're pins that are available on your board and aren't being used for something else.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论