정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

esp8266, blynk, gps모듈을 연동해서 하고싶은데 자꾸 막혀서 부탁드립니다.
hcy333333333 | 2019-08-23

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

static const int RXPin = 3, TXPin = 4;
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;
WidgetMap myMap(V0);

SoftwareSerial ss(RXPin, TXPin);

BlynkTimer timer;

float spd;
float sats;
String bearing;

char auth[] = "NTEJT1fa-eOd8ub9VF0I6mYk1rHyIKGj";
char ssid[] = "Android7104";
char pass[] = "12345678";

unsigned int move_index = 1;

void setup()
{
  Serial.begin(115200);
  Serial.println();
  ss.begin(GPSBaud);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, checkGPS);
}

void checkGPS() {
  if (gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detacted: check wiring."));
    Blynk.virtualWrite(V4, "GPS ERROR");
  }
  }

  void loop()
  {
   
    while (ss.available() > 0)
    {
      if(gps.encode(ss.read()))
      displayInfo();
    }
    Blynk.run();
    timer.run();
    }

    void displayInfo()
    {
      if(gps.location.isValid())
      {
        float latitude = (gps.location.lat());
        float longitude = (gps.location.lng());

        Serial.print("LAT: ");
        Serial.println(latitude, 6);
        Serial.print("LONG: ");
        Serial.println(longitude, 6);
        Blynk.virtualWrite(V1, String(latitude, 6));
        Blynk.virtualWrite(V2, String(longitude, 6));
        myMap.location(move_index, latitude, longitude, "GPS_Location");
        spd = gps.speed.kmph();
         Blynk.virtualWrite(V3, spd);

         sats = gps.satellites.value();
         Blynk.virtualWrite(V4, sats);

         bearing = TinyGPSPlus::cardinal(gps.course.value());
         Blynk.virtualWrite(V5, bearing);
      }
    }

이전글   |    아두이노 와이파이 모듈 공유기연결 2019-08-22
다음글   |    nodeMCU랑 bylnk랑 gps랑 연동하는데 에러가 생깁니다.... 2019-08-23