Uniostar
Published © GPL3+

Send GPS Data to your Phone w/ ESP32 + Neo 6m GPS Module

Hey! Wanna know how to send GPS data to your phone anywhere? Learn more.

BeginnerProtip1 hour305
Send GPS Data to your Phone w/ ESP32 + Neo 6m GPS Module

Things used in this project

Hardware components

Espressif ESP32 Development Board - Developer Edition
Espressif ESP32 Development Board - Developer Edition
×1
GPS receiver (generic)
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino IoT Cloud
Arduino IoT Cloud

Story

Read more

Schematics

Schematic

Code

Main Code

Arduino
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include "thingProperties.h"

U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

float lat;
float lat_NEW;

float lon;
float lon_NEW;

float alt;
float alt_NEW;

float head;
float head_NEW;

float spd;
float spd_NEW;

int sat;
int sat_NEW;

long lastConnected;

#define RXD2 16
#define TXD2 17

#define GPS_BAUD 9600

TinyGPSPlus gps;
HardwareSerial gpsSerial(2);


void setup() 
{
  Serial.begin(9600);

  gpsSerial.begin(GPS_BAUD, SERIAL_8N1, RXD2, TXD2);
  
  u8g2.begin();
  u8g2.firstPage();

  do 
  {
    u8g2.setFont(u8g2_font_6x13_tf);
    u8g2.drawStr(5, 25, "GPS Interface 0.2");
    u8g2.drawStr(5, 40, "Connecting . . .");
  } while (u8g2.nextPage());

  
  delay(1500); 
  
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() 
{
  ArduinoCloud.update();

  if (gpsSerial.available() > 0)
  {
    lastConnected = millis();

    if (gps.encode(gpsSerial.read())) 
    {
      if (gps.course.isValid())
      {
        head_NEW = gps.course.deg();

        if (head_NEW != head)
        {
          head = head_NEW;
        }
      }

      if (gps.altitude.isValid())
      {
        alt_NEW = gps.altitude.meters();

        if (alt_NEW != alt)
        {
          alt = alt_NEW;
        }
      }

      if (gps.satellites.isValid())
      {
        sat_NEW = gps.satellites.value();

        if (sat_NEW != sat)
        {
          sat = sat_NEW;
        }
      }

      if (gps.location.isValid()) 
      {
        lat_NEW = gps.location.lat();
        lon_NEW = gps.location.lng();

        if (lat_NEW != lat || lon_NEW != lon) 
        {
          if (lat_NEW != lat)
          {
            lat = lat_NEW;
          }

          if (lon_NEW != lon)
          {
            lon = lon_NEW;
          }
        }
      }

      if (gps.speed.isValid()) 
      {
        spd_NEW = gps.speed.mps();

        if (spd_NEW != spd) 
        {
          spd = spd_NEW;
        }
      }

      printAll();
    }
  }

  if ((millis() - lastConnected) > 2000)
  {
    u8g2.firstPage();
    
    do 
    {
      u8g2.setFont(u8g2_font_6x13_tf);
      u8g2.drawStr(5, 25, "GPS Interface 0.2");
      u8g2.drawStr(5, 40, "Reconnecting . . .");
    } while (u8g2.nextPage());
  }
}

void printAll()
{
  location = {lat, lon};

  altitude = alt;
  
  satellites = sat;

  speed = spd;
    
  heading = gps.cardinal(head);
  
  u8g2.firstPage();

  do 
  {
    u8g2.setFont(u8g2_font_6x13_tf);

    u8g2.setCursor(3, 10);            
    u8g2.print("Lat: ");  
    
    u8g2.setCursor(3, 25);            
    u8g2.print(lat, 6);
    
    u8g2.setCursor(3, 40);            
    u8g2.print("Lon: ");   
    
    u8g2.setCursor(3, 55);            
    u8g2.print(lon, 6);    
    
    u8g2.setCursor(70, 10);            
    u8g2.print("# Sats:"); 
    
    u8g2.setCursor(70, 25);            
    u8g2.print(sat);    
  
    u8g2.setCursor(70, 40);            
    u8g2.print("Speed:");

    u8g2.setCursor(70, 55);          
    u8g2.print(spd, 3);

  } while (u8g2.nextPage());
}

Credits

Uniostar
10 projects • 8 followers
Electrical Engineering Undergrad Student specialized in low-level programming, IoT projects, and microcontroller electronics.

Comments