再来月あたりにニキシー管を使ったGPS時計を作ってみようかなと思い、AliexpressにてGPSモジュールBN-280とBN-357を買ってみました。
電源を入れると赤色のLED(PPS=pulse per second信号)がひかり、受信すると?青色のLEDが点滅します。
ピンアサインは写真の端子部に小さくか書かれた文字通りの、手前からP(PPS)、G(グランド)、T(Tx)、R(Rx)、V(Vin 3.3-5.5V)、B(Boot)
ppsとbootピンは使いませんでした。
プログラムは下のものを使い、座標変換してもらうためにTinyGPS++ライブラリを使用しました。
arduiniana.org
#include <TinyGPS++.h> #include <SoftwareSerial.h> TinyGPSPlus gps; SoftwareSerial mySerial(2,3); // RX, TX //TinyGPSCustom magneticVariation(gps, "GPRMC", 10); void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.println("Hello,GPS"); // set the data rate for the SoftwareSerial port mySerial.begin(9600); mySerial.println("Hello, world?"); } void loop() { // run over and over while (mySerial.available() > 0){ char c = mySerial.read(); //Serial.print(c); gps.encode(c); if (gps.location.isUpdated()){ Serial.print("IDO="); Serial.println(gps.location.lat(), 6); Serial.print("KEIDO="); Serial.println(gps.location.lng(), 6); Serial.print("KOUDO="); Serial.println(gps.altitude.meters()); } } }
室内で実験してみましたが、かなり精度よく測位できていました。
次に時刻を表示してみました。
GPS衛生内蔵の超精密原子時計の時刻データを利用できるので電波時計より精度がいいです!
ちなみにGPS衛星の時刻は世界標準時になっていますので変換が必要です。
#include <TinyGPS++.h> #include <SoftwareSerial.h> TinyGPSPlus gps; SoftwareSerial mySerial(2,3); // RX, TX //TinyGPSCustom magneticVariation(gps, "GPRMC", 10); void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.println("Hello,GPS"); // set the data rate for the SoftwareSerial port mySerial.begin(9600); mySerial.println("Hello, world?"); } void loop() { // run over and over while (mySerial.available() > 0){ char c = mySerial.read(); //Serial.print(c); gps.encode(c); if (gps.location.isUpdated()){ char x = (gps.time.hour()); x = x-3; char y = (gps.location.lat()); //Serial.print("IDO="); Serial.println(gps.location.lat(), 6); //Serial.print("KEIDO="); Serial.println(gps.location.lng(), 6); //Serial.print("KOUDO="); Serial.println(gps.altitude.meters()); Serial.println(); Serial.print(x , DEC); // Hour (0-23) (u8) Serial.print(":"); Serial.print(gps.time.minute()); // Minute (0-59) (u8) Serial.print(":"); Serial.print(gps.time.second()); // Second (0-59) (u8) Serial.println(); } } }