我想測試lora/GPS shield的gps能不能用但serial monitor一直跳出亂碼想請問怎麼解決!]!
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define rxGPS 3
#define txGPS 2
long lat, lon;
SoftwareSerial gpsSerial(rxGPS, txGPS);
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
}
void loop()
{
while (gpsSerial.available()) // check for gps data
{
if (gps.encode(gpsSerial.read())) // encode gps data
{
Serial.print("SATS: ");
Serial.println(gps.satellites.value());
Serial.print("LAT: ");
Serial.println(gps.location.lat(), 6);
Serial.print("LONG: ");
Serial.println( gps.location.lng(), 6);
Serial.print("ALT: ");
Serial.println( gps.altitude.meters());
Serial.print("SPEED: ");
Serial.println(gps.speed.mps());
Serial.print("Date: ");
Serial.print(gps.date.day()); Serial.print("/");
Serial.print(gps.date.month()); Serial.print("/");
Serial.println( gps.date.year());
Serial.print("Hour: ");
Serial.print( gps.time.hour()); Serial.print(":");
Serial.print(gps.time.minute()); Serial.print(":");
Serial.println(gps.time.second());
Serial.println("---------------------------");
delay(4000);
}
}
}
是每次固定地方亂碼?
還是隨機亂碼?
因為你輸出都是ascii,
所以我偏向是線路接觸不良造成。