3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M5StackシリーズのAtomic GPSで現在位置をAmbentに表示する

Last updated at Posted at 2021-02-05

##M5StackシリーズのAtomic GPSで現在位置をAmbentに表示する
スクリーンショット 2021-02-05 10.26.36_01.png
スクリーンショット 2021-02-05 9.33.28.png

https://www.switch-science.com/catalog/6474/
##元ネタ
https://ambidata.io/blog/2017/08/04/gps-2/
##必要なライブラリ
M5Stackの開発環境は公式を見てインストールしてください。

・Ambient
スクリーンショット 2021-02-05 10.15.29.png
・M5Atom
スクリーンショット 2021-02-05 10.22.32.png

・TinyGPS++
http://arduiniana.org/libraries/tinygpsplus/

##ソース

M5Atomic_GPS
M5AtomicGPS_Ambient.ino

#include "M5Atom.h"
#include <TinyGPS++.h>
#include "Ambient.h"
unsigned long seconds = 1000L; // !!! SEE THE CAPITAL "L" USED!!!
unsigned long minutes = seconds * 60;
unsigned long hours = minutes * 60; 
unsigned long ambient_refresh_rate = 1 * minutes;

// Ambient Settings
unsigned int channelId = 100;
const char* writeKey = "ライトキー";

// WiFi Settings
const char* ssid = "...ssid...";
const char* password = "...password...";

TinyGPSPlus gps;

WiFiClient client;
Ambient ambient;

void setup()
{
    M5.begin(true,false,true); 
    Serial1.begin(9600,SERIAL_8N1,22,-1);
    Serial.begin(115200);

    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(100);
        Serial.println(WiFi.localIP());
    }
    void sendInfo2Ambient();
    ambient.begin(channelId, writeKey, &client);
}


    
void loop()
{
  while (Serial1.available() > 0) {
    if (gps.encode(Serial1.read())) {
       if (gps.location.isValid()) {
       ambient.clear(1);
       ambient.clear(2);
       ambient.clear(9);
       ambient.clear(10);
       
       char buf[16];
       char buffer_lat[16];
       char buffer_lng[16];
       dtostrf(gps.location.lat(),10,8,buffer_lat);
       ambient.set(9,buffer_lat);
       Serial.print(buffer_lat);
       Serial.print(":");
       dtostrf(gps.location.lng(),10,8,buffer_lng);
       ambient.set(10,buffer_lng);
       Serial.print(buffer_lng);
       Serial.print(":");
       Serial.print(gps.altitude.meters());   
       Serial.print(":");
       Serial.println(gps.hdop.hdop());
       ambient.set(1,gps.altitude.meters());
       ambient.set(2,gps.hdop.hdop());
       }
    }
 }
  sendInfo2Ambient();
  Serial.println("refresh!");
  delay(ambient_refresh_rate);
  Serial.println("Reload");
}


void sendInfo2Ambient()
{
 if (gps.location.isValid()) {
   ambient.send();
  }
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?