NEO-6M GPS returns 整数而不是 NMEA 消息 (Arduino Uno)
NEO-6M GPS returns integers instead of NMEA message (Arduino Uno)
我已经将 NEO-6M GPS 模块与 Arduino Uno 连接起来,并在两者之间建立了串行通信。
问题是我只能从 GPS 获取整数,而不是预期的 NMEA 消息。
这似乎在 LED 闪烁时保持不变 - 因此建立了 GPS 连接 - 并且当它不闪烁时。
有人遇到过这个问题吗?知道我做错了什么吗?我看不到我错过了什么。
我也看到了一些关于这个模块的差评,说它非常脆弱,很容易损坏,但我不知道如何检查这个(除了订购一个新的......)
硬件设置
Arduino 5V with NEO VCC
Arduino GND with NEO GND
Arduino Pin 3 (RX) with NEO TX
Arduino Pin 4 (TX) with NEO RX
代码
#include <TinyGPS.h>
#include <SoftwareSerial.h>
float lat = 28.5458,lon = 77.1703; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(3,4);//rx,tx
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
Serial.println("running setup...");
Serial.println("waiting for serial port to connect...");
while (!Serial) {
Serial.print("."); // wait for serial port to connect. Needed for native USB port only
}
Serial.println("starting serial communication gps module...");
gpsSerial.begin(9600); // connect gps sensor
Serial.println("setup complete");
}
void loop(){
while(gpsSerial.available()){ // check for gps data
Serial.println("gpsSerial is available");
Serial.println(gpsSerial.read());
}
Serial.println("gpsSerial is not available");
String latitude = String(lat,6);
String longitude = String(lon,6);
Serial.println(latitude+";"+longitude);
delay(1000);
}
串行监视器输出
running setup...
waiting for serial port to connect...
starting serial communication gps module...
setup complete
gpsSerial is not available
28.545799;77.170303
gpsSerial is available
36
gpsSerial is available
71
gpsSerial is available
80
gpsSerial is available
82
gpsSerial is available
77
gpsSerial is available
67
gpsSerial is available
44
gpsSerial is available
44
非常感谢!
正如 Juraj 在对问题的评论中指出的那样,我使用了错误的打印命令。
// Serial.println("gpsSerial is available");
// Serial.write(gpsSerial.read());
Serial.print((char) gpsSerial.read());
这会生成正确的 NMEA 消息
running setup...
waiting for serial port to connect...
starting serial communication gps module...
setup complete
gpsSerial is not available
28.545799;77.170303
$GPRMC,085416.00,V,,,,,,,080520,,,N*7C
$GPVTG,,,,,,,,,N*30
$GgpsSerial is not available
28.545799;77.170303
$GPRMC,085417.00,V,,,,,,,080520,,,N*7D
$GPVTG,,,,,,,,,N*30
谢谢 Juraj!
我已经将 NEO-6M GPS 模块与 Arduino Uno 连接起来,并在两者之间建立了串行通信。 问题是我只能从 GPS 获取整数,而不是预期的 NMEA 消息。
这似乎在 LED 闪烁时保持不变 - 因此建立了 GPS 连接 - 并且当它不闪烁时。
有人遇到过这个问题吗?知道我做错了什么吗?我看不到我错过了什么。
我也看到了一些关于这个模块的差评,说它非常脆弱,很容易损坏,但我不知道如何检查这个(除了订购一个新的......)
硬件设置
Arduino 5V with NEO VCC
Arduino GND with NEO GND
Arduino Pin 3 (RX) with NEO TX
Arduino Pin 4 (TX) with NEO RX
代码
#include <TinyGPS.h>
#include <SoftwareSerial.h>
float lat = 28.5458,lon = 77.1703; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(3,4);//rx,tx
TinyGPS gps; // create gps object
void setup(){
Serial.begin(9600); // connect serial
Serial.println("running setup...");
Serial.println("waiting for serial port to connect...");
while (!Serial) {
Serial.print("."); // wait for serial port to connect. Needed for native USB port only
}
Serial.println("starting serial communication gps module...");
gpsSerial.begin(9600); // connect gps sensor
Serial.println("setup complete");
}
void loop(){
while(gpsSerial.available()){ // check for gps data
Serial.println("gpsSerial is available");
Serial.println(gpsSerial.read());
}
Serial.println("gpsSerial is not available");
String latitude = String(lat,6);
String longitude = String(lon,6);
Serial.println(latitude+";"+longitude);
delay(1000);
}
串行监视器输出
running setup...
waiting for serial port to connect...
starting serial communication gps module...
setup complete
gpsSerial is not available
28.545799;77.170303
gpsSerial is available
36
gpsSerial is available
71
gpsSerial is available
80
gpsSerial is available
82
gpsSerial is available
77
gpsSerial is available
67
gpsSerial is available
44
gpsSerial is available
44
非常感谢!
正如 Juraj 在对问题的评论中指出的那样,我使用了错误的打印命令。
// Serial.println("gpsSerial is available");
// Serial.write(gpsSerial.read());
Serial.print((char) gpsSerial.read());
这会生成正确的 NMEA 消息
running setup...
waiting for serial port to connect...
starting serial communication gps module...
setup complete
gpsSerial is not available
28.545799;77.170303
$GPRMC,085416.00,V,,,,,,,080520,,,N*7C
$GPVTG,,,,,,,,,N*30
$GgpsSerial is not available
28.545799;77.170303
$GPRMC,085417.00,V,,,,,,,080520,,,N*7D
$GPVTG,,,,,,,,,N*30
谢谢 Juraj!