Skip to content

Commit

Permalink
GPS_test
Browse files Browse the repository at this point in the history
  • Loading branch information
iori3662 committed Jan 5, 2024
1 parent d686b65 commit 4b4dd90
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions GPS_test/GPS_test.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;

void setup() {
Serial.begin(115200); //シリアルモニターに表示させるシリアル通信
Serial1.begin(9600); //GPSと通信するシリアル通信
}

void loop() { // run over and over
while (Serial1.available() > 0){ //GPSと通信ができたとき
char c = Serial1.read(); //UART通信で情報を読み取って変数cに代入
//Serial.print(c);
gps.encode(c); //座標を数値に変換
if (gps.location.isUpdated()){
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()); //高度
}
}
}

0 comments on commit 4b4dd90

Please sign in to comment.