Arduinoで作ろう(48) GPSのデータをAmbientに投げる
前回の装置をテザリングでスマホにつないで,GPSモジュールで得られた緯度・経度のデータを1分おきにAmbientに投げてみました。
上のがクルマに積んで近所を一周してできた地図。Ambientはこんなこともできるんですね。おもしろいなあ。
//ESP32 + GPSモジュール NEO-6M → Ambient
#include <WiFi.h>
#include "Ambient.h"
#include "TinyGPS++.h"
#include "HardwareSerial.h"
#include "Wire.h"
#include "SSD1306.h"
const char* ssid = "無線LANのSSID";
const char* password = "パスワード";
WiFiClient client;
unsigned int channelId = 20050; // あなたのチャネルID
const char* writeKey = "123456789abcde";//あなたのライトキー
Ambient ambient;
SSD1306 display(0x3c, 21, 22); //I2Cアドレス0x3c,SDA->GPIO21,SCL->GPIO22
TinyGPSPlus gps;
HardwareSerial serial2(2); //ESP32_GPIO16->GPS_TX , ESP32_GPIO17->GPS_RXvoid setup() {
display.init();
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
Serial.begin(9600);
Serial.println("Start GPS... ");
display.clear();
display.drawString(0,0,"Start GPS... ");
display.display();
serial2.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ambient.begin(channelId, writeKey, &client);
}void loop() {
if (serial2.available()){
char c = serial2.read();
gps.encode(c);
if (gps.location.isUpdated()) {
digitalWrite(2, HIGH);
Serial.print("LAT: "); Serial.println(gps.location.lat(), 9);
Serial.print("LONG: "); Serial.println(gps.location.lng(), 9);
display.clear();
display.drawString(0,0,String(gps.time.hour()+9)+":"+String(gps.time.minute())+":"+String(gps.time.second())+" JST");
display.drawString(0,20,"LAT : "+String(gps.location.lat(),9));
display.drawString(0,35,"LNG : "+String(gps.location.lng(),9));
display.drawString(0,50,"ALT : "+String(gps.altitude.meters())+"m");
display.display();
} else{
digitalWrite(2, LOW);
}
}
if (int(millis()/1000%60) == 0){ //1分ごとに
char buf[16];
ambient.set(1, gps.altitude.meters()); // 標高をデータ1に
dtostrf(gps.location.lat(), 12, 8, buf);
ambient.set(9, buf); // 緯度をデータ9に
dtostrf(gps.location.lng(), 12, 8, buf);
ambient.set(10, buf); //経度をデータ10に
ambient.send();
}
}
| 固定リンク | 0
「Arduino」カテゴリの記事
- WCH-LinkE とWCH-Link は別モノである(2023.12.02)
- Arduinoで作ろう(63) UNO R4 WiFiでスクロールNTP時計(2023.12.01)
- Arduinoで作ろう(62) ESP8266+SSD1306でNTP時計(2023.11.18)
- 新型 Arduino UNO R4 MINIMA を買った(2023.07.01)
「ESP8266 , ESP32」カテゴリの記事
- Arduinoで作ろう(62) ESP8266+SSD1306でNTP時計(2023.11.18)
- Arduinoで作ろう(51) パルスオキシメータ(2020.05.01)
- Arduinoで作ろう(50) 温度・湿度・気圧データをBlynkで見てみる(2020.04.27)
- Arduinoで作ろう(49) BLEでリモートLチカ(2020.04.25)
- Arduinoで作ろう(48) GPSのデータをAmbientに投げる(2020.04.22)
コメント