Using GPS

 HiLetgo GY-NEO6MV2 NEO-6M GPS Flight Controller Module 3V-5V with Super Strong Ceramic Antenna for Arduino EEPROM APM 2.5




------------------------------------------------------------------------------------------

Particle Boron + Adafruit Ultimate GPS:


HARDWARE CONNECTIONS:

  * Boron GND --> GPS GND
  * Boron 3.3V --> GPS 3.3V
  * Boron D10 --> GPS TX
  * Boron D9 --> GPS RX

Particle Library: Adafruit_GPS

Useful Particle Libraries:

Adafruit_GPS- See Leo_parsing sample code
https://build.particle.io/libs/ThingSpeak/1.5.1/tab/example/WriteMultipleVoltages.ino

 
DF Robot Pressure Monitor 

Code:
// Drone GPS Tracker with LTE Connectivity
// Author:  Scott Hatfield (aka Toglefritz)
// Published on Maker Pro

/* 
DESCRIPTION:  
  This sketch for the Particle Boron runs a GPS tracker intended for use
  on a quadcopter or other similar drone. The Boron has a cellular LTE 
  connection allowing it to publish GPS coordinates, obtained from a 
  GPS unit, to the Particle Cloud.

PARTS:
  * Particle Boron: < https://www.sparkfun.com/products/15069 >
  * Adafruit Ultimate GPS FeatherWing:  < https://www.adafruit.com/product/3133 >
  * UBEC Step-Down Converter:  < https://www.adafruit.com/product/1385 >

HARDWARE CONNECTIONS:
  * Boron GND --> GPS GND
  * Boron 3.3V --> GPS 3.3V
  * Boron D10 --> GPS TX
  * Boron D9 --> GPS RX
Particle Library: Adafruit_GPS
*/

// Add the Adafruit GPS library
#include <Adafruit_GPS.h>
#include <ThingSpeak.h>
TCPClient client;
unsigned long myChannelNumber = 31461;
const char * myWriteAPIKey = "LD79EOAAWRVYF04Y";


// Name the Serial port
#define GPSSerial Serial1

// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);

uint32_t timer = millis();


void setup() {
  // Publish a little welcome message
  Particle.publish("Drone GPS tracker online");
 ThingSpeak.begin(client);
  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  
  // Turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  delay(1000);
}

void loop() 
{
  // Read data from the GPS
  char c = GPS.read();
  
  // If a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA())) // This also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis()) timer = millis();

  // Approximately every one minute or so, print out the current stats
  // Since the drone will not be moving, we do not need to update its location
  // too often
  // Note that this statement also causes the first reading to take place 
  // one minute after the Boron powers on, which gives the GPS sensor time
  // to obtain a fix
  if (millis() - timer > 60000) {
    timer = millis(); // Reset the timer
    
    // Check if the GPS has a fix
    if (GPS.fix) {
      Particle.publish("Location: ", String(GPS.latitudeDegrees) + ", " + String(GPS.longitudeDegrees));   // Publish the physical location of the drone
                                                                                                    
ThingSpeak.writeField(myChannelNumber, 1, String(GPS.latitudeDegrees), myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber, 1, String(GPS.longitudeDegrees), myWriteAPIKey);

  delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}
    }
    
    else {
      Particle.publish("No GPS fix");
    }
  }
}

----------------------------------------------------------------
// Copyright � 2016-2017 Daniel Porrey. All Rights Reserved.
#include "Particle-GPS.h"

// ***
// *** Create a Gps instance. The RX an TX pins are connected to
// *** the TX and RX pins on the electron (Serial1).
// ***
Gps _gps = Gps(&Serial1);

// ***
// *** Create a timer that fires every 1 ms to capture
// *** incoming serial port data from the GPS.
// ***
Timer _timer = Timer(1, onSerialData);

void setup()
{
  delay(2000);

  // ***
  // *** Initialize the USB Serial for debugging.
  // ***
  Serial.begin();
  Serial.println("Initializing...");

  // ***
  // *** Initialize the GPS.
  // ***
  _gps.begin(9600);

  // ***
  // *** Start the timer.
  // ***
  _timer.start();
}

void onSerialData()
{
  _gps.onSerialData();
}

void loop()
{
  // ***
  // *** Get the Antenna Status ($PGTOP).
  // ***
  Pgtop pgtop = Pgtop(_gps);
  if (pgtop.parse())
  {
    Serial.println("1) Antenna Status ($PGTOP)");
    Serial.println("======================================================");
    Serial.print("Command ID: "); Serial.println(pgtop.commandId);
    Serial.print("Antenna Status: "); Serial.println(pgtop.reference);
    Serial.println("");
  }

  // ***
  // *** Get the Global Positioning System Fixed Data ($GPGGA).
  // ***
  Gga gga = Gga(_gps);
  if (gga.parse())
  {
    Serial.println("2) Global Positioning System Fixed Data ($GPGGA)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(gga.utcTime);
    Serial.print("Latitude: "); Serial.println(gga.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(gga.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(gga.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(gga.eastWestIndicator);
    Serial.print("Position Fix Indicator: "); Serial.println(gga.positionFixIndicator);
    Serial.print("Satellites Used: "); Serial.println(gga.satellitesUsed);
    Serial.print("Horizontal Dilution of Precision: "); Serial.println(gga.hdop);
    Serial.print("Altitude: "); Serial.print(gga.altitude); Serial.print(" "); Serial.println(gga.altitudeUnit);
    Serial.print("Geoidal Separation: "); Serial.print(gga.geoidalSeparation); Serial.print(" "); Serial.println(gga.geoidalSeparationUnit);
    Serial.print("Age of Diff. Corr.: "); Serial.println(gga.ageOfDiffCorr);
    Serial.println("");
  }

  // ***
  // *** Get the Recommended Minimum Navigation Information ($GPRMC).
  // ***
  Rmc rmc = Rmc(_gps);
  if (rmc.parse())
  {
    Serial.println("3) Recommended Minimum Navigation Information ($GPRMC)");
    Serial.println("======================================================");
    Serial.print("UTC Time: "); Serial.println(rmc.utcTime);
    Serial.print("Latitude: "); Serial.println(rmc.latitude);
    Serial.print("North/SouthIndicator: "); Serial.println(rmc.northSouthIndicator);
    Serial.print("Longitude: "); Serial.println(rmc.longitude);
    Serial.print("East/WestIndicator: "); Serial.println(rmc.eastWestIndicator);
    Serial.print("Speed Over Ground: "); Serial.println(rmc.speedOverGround);
    Serial.print("Course Over Ground: "); Serial.println(rmc.courseOverGround);
    Serial.print("Date: "); Serial.println(rmc.date);
    Serial.print("Magnetic Variation: "); Serial.print(rmc.magneticVariation); Serial.print(" "); Serial.println(rmc.magneticVariationDirection);
    Serial.print("Mode: "); Serial.println(rmc.mode);
    Serial.println("");
  }

  delay(1000);
}

---------------------------------------------------------------------------------------------
Uses Tiny GPS Plus Library

include <TinyGPS++.h>
#include <SoftwareSerial.h>
/* #include <ParticleSoftSerial.h>
#define SENDER Serial1
#define RECEIVER SoftSer
#define PROTOCOL SERIAL_8N1
*/

// Choose two Arduino pins to use for software serial
int RXPin = 2;
int TXPin = 3;
/*
#define PSS_RX D2 // RX must be interrupt enabled (on Photon/Electron D0/A5 are not)
#define PSS_TX D3
ParticleSoftSerial SoftSer(PSS_RX, PSS_TX); 
*/

int GPSBaud = 9600;

// Create a TinyGPS++ object
TinyGPSPlus gps;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

void setup()
{
  // Start the Arduino hardware serial port at 9600 baud
  Serial.begin(9600);

  // Start the software serial port at the GPS's default baud
  gpsSerial.begin(GPSBaud);
}

void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read()))
      displayInfo();

  // If 5000 milliseconds pass and there are no characters coming in
  // over the software serial port, show a "No GPS detected" error
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println("No GPS detected");
    while(true);
  }
}

void displayInfo()
{
  if (gps.location.isValid())
  {
    Serial.print("Latitude: ");
    Serial.println(gps.location.lat(), 6);
    Serial.print("Longitude: ");
    Serial.println(gps.location.lng(), 6);
    Serial.print("Altitude: ");
    Serial.println(gps.altitude.meters());
  }
  else
  {
    Serial.println("Location: Not Available");
  }
  
  Serial.print("Date: ");
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print("/");
    Serial.print(gps.date.day());
    Serial.print("/");
    Serial.println(gps.date.year());
  }
  else
  {
    Serial.println("Not Available");
  }

Serial.print("Time: ");
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(":");
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(":");
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(".");
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.println(gps.time.centisecond());
  }
  else
  {
    Serial.println("Not Available");
  }

  Serial.println();
  Serial.println();
  delay(1000);
}
 




----------------------------------

#define SENDER Serial1
#define RECEIVER SoftSer
#define PROTOCOL SERIAL_8N1

const uint32_t baud = 19200;

#if (SYSTEM_VERSION >= 0x00060000)

SerialLogHandler logHandler;

#endif

#define PSS_RX D2 // RX must be interrupt enabled (on Photon/Electron D0/A5 are not)


#define PSS_TX D3


ParticleSoftSerial SoftSer(PSS_RX, PSS_TX); 

No comments:

Post a Comment

EDW August 4th- Cleanup, Reflections, and Farewells

         Zoom Presentation with students in Mexico, Spain, and Italy: