我有一个 NEO-6M GPS 模块,我想用它来获取日期、位置和时间。 现在,当 NEO-6M 默认设置为 115200 波特率并且当我使用 ttl 转换器从 GPS 模块获取信号时,它工作得很好,但当我尝试使用 Arduino Uno 并从中读取信号时,它会发送垃圾值。
$GNGGA,114213.000,2238.34233,N,07549.90950,E,1,17,0.8,535.6,M,0.0,M,,*78
$GNGLL,2238.343,595,4.0@6$SA00,6,4,,88.E$SA00169,,,,,8.0$SA779,,,88.D$S410,,,2,,,,,3314
G,,,12,0,,9,96,62
GS,419,255373,2557
G44,,0,1,0,*
D,1,,3,050218736,54
BV,89,4,,1,,33235728$S207,.32,8837202
LV25,,9*
NC430,843041000439,*GT.,M.N.K*
NA430,,200
GT11,TAK
$GNGGA,114214.000,2238.34233,N,07449.91952,E,0,17,0.8,535.6,M,0.0,M,,*7D
$GNGLL,2238.343,595,4.0,3"SA0066,4,,88.E$SA,0169,3,,,860GSA779,,,8,.D$S411,,,2,,2,,73,4
G,1,1286409016127$G4,292,,0,234,,0,
GV,,1,6746,8
BV,06312,,,,31,13328$S2,17520566,,7,,226
G,1,,93,2,,2,,06*
LV2,,,9*
N,440,843049200409,*
N,4,,0,0,2$Z120,,24,*GX11,T K
$GNGGA,114315.000,2238.34260,N,07549.91955,E,1,17,0.8,535.9,M,0.0,M,,+72
$GNGLL,2238.3460595110A4
A,34,,1,,.,,6
BA369,,,26,18,*
LA,,9,,,1016
GV,412011,6210,25F$S41005007,,3,,,,*
PV34,,,6,1,,,,8,4A$S4,33379262D$S2,0432931,3,56854
BV,89746,,,233,,2,6
L,1,,03,2,,2,9,6*
LV259,9*
N,450,34,041509.09,*
N,4,08,6,2$D12.,,24,*$P,,,AEO*
我想将GPS模块的波特率降低到9600,但我似乎找不到任何方法来做到这一点。 与 rx 和 tx 引脚的连接非常非常短,因此我认为这不会导致问题。
代码
#include <SoftwareSerial.h>
void setup() {
Serial.begin(115200); // Begin serial communication with the PC
Serial1.begin(115200); // Start software serial for GPS module at 9600
}
void loop() {
while (Serial1.available()) {
Serial.write(Serial1.read()); // Forward GPS data to the Serial Monitor
}
}
我通过阅读文档和这段代码让它工作了
#include <SoftwareSerial.h>
// Create a software serial port on pins 10 (RX) and 11 (TX)
SoftwareSerial gpsSerial(10, 11);
void setup() {
// Start the software serial communication with the GPS module at 9600 baud (default for NEO-6M)
Serial.begin(115200);
gpsSerial.begin(115200);
delay(1000); // Allow some time for the GPS module to initialize
// Send the PUBX command to change the baud rate to 19200
gpsSerial.println("$PUBX,41,1,0007,0003,19200,0*25");
// Wait a moment for the command to take effect
delay(1000);
// Update the software serial to communicate at the new baud rate
gpsSerial.begin(19200);
}
void loop() {
// You can now communicate with the GPS module at 19200 baud
if (gpsSerial.available()) {
Serial.write(gpsSerial.read()); // Forward GPS data to Serial Monitor
}
}