initial commit
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
// Test code for Ultimate GPS Using Hardware Serial
|
||||
// (e.g. GPS for Leonardo, Flora or FeatherWing)
|
||||
//
|
||||
// This code shows how to test a passthru between USB and hardware serial
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
|
||||
void setup() {
|
||||
// make this baud rate fast enough to we aren't waiting on it
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for hardware serial to appear
|
||||
while (!Serial) delay(10);
|
||||
|
||||
// 9600 baud is the default rate for the Ultimate GPS
|
||||
GPSSerial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
GPSSerial.write(c);
|
||||
}
|
||||
if (GPSSerial.available()) {
|
||||
char c = GPSSerial.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Adafruit GPS logging data dump!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
||||
|
||||
while (GPSSerial.available())
|
||||
GPSSerial.read();
|
||||
|
||||
delay(1000);
|
||||
GPS.sendCommand("$PMTK622,1*29");
|
||||
Serial.println("----------------------------------------------------");
|
||||
}
|
||||
|
||||
uint32_t updateTime = 1000;
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
GPSSerial.write(c);
|
||||
}
|
||||
if (GPSSerial.available()) {
|
||||
char c = GPSSerial.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}//loop
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code erases the LOCUS built-in datalogger storage
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
//This code is intended for use with Arduino Leonardo and other ATmega32U4-based Arduinos
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// If using software serial (sketch example default):
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
// If using hardware serial:
|
||||
// Connect the GPS TX (transmit) pin to Arduino RX1 (Digital 0)
|
||||
// Connect the GPS RX (receive) pin to matching TX1 (Digital 1)
|
||||
|
||||
// If using software serial, keep these lines enabled
|
||||
// (you can change the pin numbers to match your wiring):
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
while (!Serial) ; //wait for serial port on Leonardo
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enuf and
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS erase FLASH!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK
|
||||
GPS.begin(9600);
|
||||
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
||||
|
||||
Serial.println("This code will ERASE the data log stored in the FLASH - Permanently!");
|
||||
Serial.print("Are you sure you want to do this? [Y/N]: ");
|
||||
while (Serial.read() != 'Y') delay(10);
|
||||
Serial.println("\nERASING! UNPLUG YOUR ARDUINO WITHIN 5 SECONDS IF YOU DIDNT MEAN TO!");
|
||||
delay(5000);
|
||||
GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH);
|
||||
Serial.println("Erased");
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
if (GPSSerial.available()) {
|
||||
char c = GPSSerial.read();
|
||||
if (GPSECHO)
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Adafruit GPS logging start test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
// You can adjust which sentences to have the module emit, below
|
||||
// Default is RMC + GGA
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// Default is 1 Hz update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
// Ask for firmware version
|
||||
GPS.sendCommand(PMTK_Q_RELEASE);
|
||||
|
||||
Serial.print("\nSTARTING LOGGING....");
|
||||
if (GPS.LOCUS_StartLogger())
|
||||
Serial.println(" STARTED!");
|
||||
else
|
||||
Serial.println(" no response :(");
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
if (GPSSerial.available()) {
|
||||
char c = GPSSerial.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// Do other things here....
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("Adafruit GPS logging start test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
// You can adjust which sentences to have the module emit, below
|
||||
// Default is RMC + GGA
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// Default is 1 Hz update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
// Ask for firmware version
|
||||
GPS.sendCommand(PMTK_Q_RELEASE);
|
||||
|
||||
Serial.print("\nSTARTING LOGGING....");
|
||||
if (GPS.LOCUS_StartLogger())
|
||||
Serial.println(" STARTED!");
|
||||
else
|
||||
Serial.println(" no response :(");
|
||||
}
|
||||
|
||||
uint32_t timer = 0;
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if ((c) && (GPSECHO))
|
||||
Serial.write(c);
|
||||
|
||||
if (millis() - timer > 1000)
|
||||
{
|
||||
timer = millis();
|
||||
if (GPS.LOCUS_ReadStatus()) {
|
||||
Serial.print("\n\nLog #");
|
||||
Serial.print(GPS.LOCUS_serial, DEC);
|
||||
if (GPS.LOCUS_type == LOCUS_OVERLAP)
|
||||
Serial.print(", Overlap, ");
|
||||
else if (GPS.LOCUS_type == LOCUS_FULLSTOP)
|
||||
Serial.print(", Full Stop, Logging");
|
||||
|
||||
if (GPS.LOCUS_mode & 0x1) Serial.print(" AlwaysLocate");
|
||||
if (GPS.LOCUS_mode & 0x2) Serial.print(" FixOnly");
|
||||
if (GPS.LOCUS_mode & 0x4) Serial.print(" Normal");
|
||||
if (GPS.LOCUS_mode & 0x8) Serial.print(" Interval");
|
||||
if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance");
|
||||
if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed");
|
||||
|
||||
Serial.print(", Content "); Serial.print((int)GPS.LOCUS_config);
|
||||
Serial.print(", Interval "); Serial.print((int)GPS.LOCUS_interval);
|
||||
Serial.print(" sec, Distance "); Serial.print((int)GPS.LOCUS_distance);
|
||||
Serial.print(" m, Speed "); Serial.print((int)GPS.LOCUS_speed);
|
||||
Serial.print(" m/s, Status ");
|
||||
if (GPS.LOCUS_status)
|
||||
Serial.print("LOGGING, ");
|
||||
else
|
||||
Serial.print("OFF, ");
|
||||
Serial.print((int)GPS.LOCUS_records); Serial.print(" Records, ");
|
||||
Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used ");
|
||||
|
||||
}//if (GPS.LOCUS_ReadStatus())
|
||||
}//if (millis() - timer > 1000)
|
||||
}//loop
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
|
||||
//
|
||||
// This code shows how to listen to the GPS module via polling. Best used with
|
||||
// Feathers or Flora where you have hardware Serial and no interrupt
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO false
|
||||
|
||||
uint32_t timer = millis();
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS library basic parsing test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
|
||||
GPS.begin(9600);
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
|
||||
// the parser doesn't care about other sentences at this time
|
||||
// Set the update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
|
||||
// For the parsing code to work nicely and have time to sort thru the data, and
|
||||
// print it out we don't suggest using anything higher than 1 Hz
|
||||
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Ask for firmware version
|
||||
GPSSerial.println(PMTK_Q_RELEASE);
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
// read data from the GPS in the 'main loop'
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO)
|
||||
if (c) Serial.print(c);
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
|
||||
Serial.print(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
|
||||
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
|
||||
}
|
||||
|
||||
// approximately every 2 seconds or so, print out the current stats
|
||||
if (millis() - timer > 2000) {
|
||||
timer = millis(); // reset the timer
|
||||
Serial.print("\nTime: ");
|
||||
if (GPS.hour < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.hour, DEC); Serial.print(':');
|
||||
if (GPS.minute < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.minute, DEC); Serial.print(':');
|
||||
if (GPS.seconds < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.seconds, DEC); Serial.print('.');
|
||||
if (GPS.milliseconds < 10) {
|
||||
Serial.print("00");
|
||||
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(GPS.milliseconds);
|
||||
Serial.print("Date: ");
|
||||
Serial.print(GPS.day, DEC); Serial.print('/');
|
||||
Serial.print(GPS.month, DEC); Serial.print("/20");
|
||||
Serial.println(GPS.year, DEC);
|
||||
Serial.print("Fix: "); Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
|
||||
if (GPS.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
|
||||
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
||||
Serial.print("Angle: "); Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
|
||||
Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
|
||||
}
|
||||
}
|
||||
}
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or
|
||||
// FeatherWing)
|
||||
//
|
||||
// This code is similar to GPS_HardwareSerial_Parsing, except for the additional
|
||||
// elements to keep track of how long it has been since time and fix data have
|
||||
// been received. This approach lets you keep an up to date clock based on GPS
|
||||
// time at any time in between GPS fixes.
|
||||
//
|
||||
// It also shows how to take advantage of the build() function to generate test
|
||||
// sentences. The additional code is within #ifdef NMEA_EXTENSIONS and #endif
|
||||
// tags.
|
||||
//
|
||||
// This code shows how to listen to the GPS module via polling. Best used with
|
||||
// Feathers or Flora where you have hardware Serial and no interrupt
|
||||
//
|
||||
// Tested and works great with the Adafruit GPS FeatherWing
|
||||
// ------> https://www.adafruit.com/products/3133
|
||||
// or Flora GPS
|
||||
// ------> https://www.adafruit.com/products/1059
|
||||
// but also works with the shield, breakout
|
||||
// ------> https://www.adafruit.com/products/1272
|
||||
// ------> https://www.adafruit.com/products/746
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// what's the name of the hardware serial port?
|
||||
#define GPSSerial Serial1
|
||||
|
||||
// Connect to the GPS on the hardware port
|
||||
Adafruit_GPS GPS(&GPSSerial);
|
||||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
// Create another GPS object to hold the state of the boat, with no
|
||||
// communications, so you don't need to call Boat.begin() in setup.
|
||||
// We will build some fake sentences from the Boat data to feed to
|
||||
// GPS for testing.
|
||||
Adafruit_GPS Boat;
|
||||
#endif
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
uint32_t timer = millis();
|
||||
|
||||
void setup() {
|
||||
// while (!Serial); // uncomment to have the sketch wait until Serial is
|
||||
// ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without
|
||||
// dropping chars also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS library basic test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
|
||||
GPS.begin(9600);
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data)
|
||||
// including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For parsing data, we don't suggest using anything but either RMC only or
|
||||
// RMC+GGA since the parser doesn't care about other sentences at this time
|
||||
// Set the update rate (uncomment the one you want.)
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
|
||||
// GPS.sendCommand(PMTK_SET_NMEA_UPDATE_200_MILLIHERTZ); // 5 second update
|
||||
// time
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_100_MILLIHERTZ); // 10 second update time
|
||||
// For the parsing code to work nicely and have time to sort thru the data,
|
||||
// and print it out we don't suggest using anything higher than 1 Hz
|
||||
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Ask for firmware version
|
||||
GPSSerial.println(PMTK_Q_RELEASE);
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
// read data from the GPS in the 'main loop'
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO)
|
||||
if (c)
|
||||
Serial.print(c);
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
|
||||
// Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived()
|
||||
// flag to false
|
||||
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
|
||||
}
|
||||
|
||||
// approximately every 2 seconds or so, random intervals, print out the
|
||||
// current stats
|
||||
static unsigned nextInterval = 2000;
|
||||
if (millis() - timer > nextInterval) {
|
||||
timer = millis(); // reset the timer
|
||||
nextInterval = 1500 + random(1000);
|
||||
// Time in seconds keeps increasing after we get the NMEA sentence.
|
||||
// This estimate will lag real time due to transmission and parsing delays,
|
||||
// but the lag should be small and should also be consistent.
|
||||
float s = GPS.seconds + GPS.milliseconds / 1000. + GPS.secondsSinceTime();
|
||||
int m = GPS.minute;
|
||||
int h = GPS.hour;
|
||||
int d = GPS.day;
|
||||
// Adjust time and day forward to account for elapsed time.
|
||||
// This will break at month boundaries!!! Humans will have to cope with
|
||||
// April 31,32 etc.
|
||||
while (s > 60) {
|
||||
s -= 60;
|
||||
m++;
|
||||
}
|
||||
while (m > 60) {
|
||||
m -= 60;
|
||||
h++;
|
||||
}
|
||||
while (h > 24) {
|
||||
h -= 24;
|
||||
d++;
|
||||
}
|
||||
// ISO Standard Date Format, with leading zeros https://xkcd.com/1179/
|
||||
Serial.print("\nDate: ");
|
||||
Serial.print(GPS.year + 2000, DEC);
|
||||
Serial.print("-");
|
||||
if (GPS.month < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(GPS.month, DEC);
|
||||
Serial.print("-");
|
||||
if (d < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(d, DEC);
|
||||
Serial.print(" Time: ");
|
||||
if (h < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(h, DEC);
|
||||
Serial.print(':');
|
||||
if (m < 10)
|
||||
Serial.print("0");
|
||||
Serial.print(m, DEC);
|
||||
Serial.print(':');
|
||||
if (s < 10)
|
||||
Serial.print("0");
|
||||
Serial.println(s, 3);
|
||||
Serial.print("Fix: ");
|
||||
Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: ");
|
||||
Serial.println((int)GPS.fixquality);
|
||||
Serial.print("Time [s] since last fix: ");
|
||||
Serial.println(GPS.secondsSinceFix(), 3);
|
||||
Serial.print(" since last GPS time: ");
|
||||
Serial.println(GPS.secondsSinceTime(), 3);
|
||||
Serial.print(" since last GPS date: ");
|
||||
Serial.println(GPS.secondsSinceDate(), 3);
|
||||
if (GPS.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(GPS.latitude, 4);
|
||||
Serial.print(GPS.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(GPS.longitude, 4);
|
||||
Serial.println(GPS.lon);
|
||||
Serial.print("Speed (knots): ");
|
||||
Serial.println(GPS.speed);
|
||||
Serial.print("Angle: ");
|
||||
Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: ");
|
||||
Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: ");
|
||||
Serial.println((int)GPS.satellites);
|
||||
}
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
char latestBoat[200] = "";
|
||||
updateBoat(); // create some test data in Boat
|
||||
Boat.build(latestBoat, "GN", "RMC"); // make a sentence from Boat data
|
||||
Serial.print("\nbuild() test output -->"); //
|
||||
Serial.print(latestBoat); //
|
||||
GPS.resetSentTime(); // make timing look like it came in on GPS
|
||||
GPS.parse(latestBoat); // parse the test data and store in GPS
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
void updateBoat() { // fill up the boat values with some test data to use in
|
||||
// build()
|
||||
double t = millis() / 1000.;
|
||||
double theta = t / 100.; // slow
|
||||
double gamma = theta * 10; // faster
|
||||
Boat.latitude = 4400 + sin(theta) * 60;
|
||||
Boat.lat = 'N';
|
||||
Boat.longitude = 7600 + cos(theta) * 60;
|
||||
Boat.lon = 'W';
|
||||
Boat.fixquality = 2;
|
||||
Boat.speed = 3 + sin(gamma);
|
||||
Boat.hour = abs(cos(theta)) * 24;
|
||||
Boat.minute = 30 + sin(theta / 2) * 30;
|
||||
Boat.seconds = 30 + sin(gamma) * 30;
|
||||
Boat.milliseconds = 500 + sin(gamma) * 500;
|
||||
Boat.year = 1 + abs(sin(theta)) * 25;
|
||||
Boat.month = 1 + abs(sin(gamma)) * 11;
|
||||
Boat.day = 1 + abs(sin(gamma)) * 26;
|
||||
Boat.satellites = abs(cos(gamma)) * 10;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
// Test code for Adafruit GPS That Support Using I2C
|
||||
//
|
||||
// This code shows how to test a passthru between USB and I2C
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// Connect to the GPS on the hardware I2C port
|
||||
Adafruit_GPS GPS(&Wire);
|
||||
|
||||
|
||||
void setup() {
|
||||
// wait for hardware serial to appear
|
||||
while (!Serial);
|
||||
|
||||
// make this baud rate fast enough to we aren't waiting on it
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Adafruit GPS library basic I2C test!");
|
||||
GPS.begin(0x10); // The I2C address to use is 0x10
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
GPS.write(c);
|
||||
}
|
||||
if (GPS.available()) {
|
||||
char c = GPS.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Test code for Adafruit GPS That Support Using I2C
|
||||
//
|
||||
// This code shows how to test a passthru between USB and I2C
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// Connect to the GPS on the hardware I2C port
|
||||
Adafruit_GPS GPS(&Wire);
|
||||
|
||||
|
||||
void setup() {
|
||||
// wait for hardware serial to appear
|
||||
while (!Serial);
|
||||
|
||||
// make this baud rate fast enough to we aren't waiting on it
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Adafruit GPS library basic I2C test!");
|
||||
GPS.begin(0x10); // The I2C address to use is 0x10
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
GPS.write(c);
|
||||
}
|
||||
if (GPS.available()) {
|
||||
char c = GPS.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Test code for Adafruit GPS That Support Using I2C
|
||||
//
|
||||
// This code shows how to parse data from the I2C GPS
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// Connect to the GPS on the hardware I2C port
|
||||
Adafruit_GPS GPS(&Wire);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO false
|
||||
|
||||
uint32_t timer = millis();
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit I2C GPS library basic test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
|
||||
GPS.begin(0x10); // The I2C address to use is 0x10
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
|
||||
// the parser doesn't care about other sentences at this time
|
||||
// Set the update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
|
||||
// For the parsing code to work nicely and have time to sort thru the data, and
|
||||
// print it out we don't suggest using anything higher than 1 Hz
|
||||
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Ask for firmware version
|
||||
GPS.println(PMTK_Q_RELEASE);
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
// read data from the GPS in the 'main loop'
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO)
|
||||
if (c) Serial.print(c);
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
|
||||
Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
|
||||
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
|
||||
}
|
||||
|
||||
// approximately every 2 seconds or so, print out the current stats
|
||||
if (millis() - timer > 2000) {
|
||||
timer = millis(); // reset the timer
|
||||
Serial.print("\nTime: ");
|
||||
if (GPS.hour < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.hour, DEC); Serial.print(':');
|
||||
if (GPS.minute < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.minute, DEC); Serial.print(':');
|
||||
if (GPS.seconds < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.seconds, DEC); Serial.print('.');
|
||||
if (GPS.milliseconds < 10) {
|
||||
Serial.print("00");
|
||||
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(GPS.milliseconds);
|
||||
Serial.print("Date: ");
|
||||
Serial.print(GPS.day, DEC); Serial.print('/');
|
||||
Serial.print(GPS.month, DEC); Serial.print("/20");
|
||||
Serial.println(GPS.year, DEC);
|
||||
Serial.print("Fix: "); Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
|
||||
if (GPS.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
|
||||
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
||||
Serial.print("Angle: "); Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Test code for Adafruit GPS That Support Using SPI
|
||||
//
|
||||
// This code shows how to test a passthru between USB and SPI
|
||||
//
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
|
||||
// Connect to the GPS on the hardware SPI port
|
||||
// with CS on pin #10
|
||||
Adafruit_GPS GPS(&SPI, 10);
|
||||
#define RESET_PIN 9
|
||||
|
||||
void setup() {
|
||||
// wait for hardware serial to appear
|
||||
while (!Serial);
|
||||
|
||||
// make this baud rate fast enough to we aren't waiting on it
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Adafruit GPS library basic SPI test!");
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
digitalWrite(RESET_PIN, LOW);
|
||||
delay(10);
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
delay(100);
|
||||
GPS.begin(100000); // use 100kHz for SPI data rate
|
||||
GPS.println(PMTK_SET_NMEA_UPDATE_10HZ);
|
||||
GPS.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
GPS.write(c);
|
||||
}
|
||||
if (GPS.available()) {
|
||||
char c = GPS.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code just echos whatever is coming from the GPS unit to the
|
||||
// serial monitor, handy for debugging!
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// You can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
|
||||
#define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F"
|
||||
#define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C"
|
||||
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
|
||||
|
||||
// turn on only the second sentence (GPRMC)
|
||||
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
|
||||
// turn on GPRMC and GGA
|
||||
#define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
|
||||
// turn on ALL THE DATA
|
||||
#define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
|
||||
// turn off output
|
||||
#define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
|
||||
|
||||
#define PMTK_Q_RELEASE "$PMTK605*31"
|
||||
|
||||
void setup() {
|
||||
while (!Serial); // wait for Serial to be ready
|
||||
|
||||
Serial.begin(115200); // The serial port for the Arduino IDE port output
|
||||
mySerial.begin(9600);
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Software Serial GPS Test Echo Test");
|
||||
// you can send various commands to get it started
|
||||
//mySerial.println(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA);
|
||||
|
||||
mySerial.println(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
|
||||
Serial.println("Get version!");
|
||||
mySerial.println(PMTK_Q_RELEASE);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
Serial.write(c);
|
||||
mySerial.write(c);
|
||||
}
|
||||
if (mySerial.available()) {
|
||||
char c = mySerial.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// you can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
void setup()
|
||||
{
|
||||
while (!Serial); // Leonardo will wait till serial connects
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enuf and
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS logging start test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
||||
|
||||
while (mySerial.available())
|
||||
mySerial.read();
|
||||
|
||||
delay(1000);
|
||||
GPS.sendCommand("$PMTK622,1*29");
|
||||
Serial.println("----------------------------------------------------");
|
||||
}
|
||||
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
if (mySerial.available()) {
|
||||
char c = mySerial.read();
|
||||
if (c) {
|
||||
#ifdef UDR0
|
||||
UDR0 = c;
|
||||
#else
|
||||
Serial.print(c);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code erases the LOCUS built-in datalogger storage
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// you can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO false
|
||||
|
||||
// this keeps track of whether we're using the interrupt
|
||||
// off by default!
|
||||
#ifndef ESP8266 // Sadly not on ESP8266
|
||||
bool usingInterrupt = false;
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
while (!Serial) ; //wait for serial port on Leonardo
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enuf and
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS erase FLASH!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK
|
||||
GPS.begin(9600);
|
||||
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);
|
||||
|
||||
// the nice thing about this code is you can have a timer0 interrupt go off
|
||||
// every 1 millisecond, and read data from the GPS for you. that makes the
|
||||
// loop code a heck of a lot easier!
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
useInterrupt(true);
|
||||
#endif
|
||||
|
||||
Serial.println("This code will ERASE the data log stored in the FLASH - Permanently!");
|
||||
Serial.print("Are you sure you want to do this? [Y/N]: ");
|
||||
while (Serial.read() != 'Y') delay(10);
|
||||
Serial.println("\nERASING! UNPLUG YOUR ARDUINO WITHIN 5 SECONDS IF YOU DIDNT MEAN TO!");
|
||||
delay(5000);
|
||||
GPS.sendCommand(PMTK_LOCUS_ERASE_FLASH);
|
||||
Serial.println("Erased");
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
if (mySerial.available()) {
|
||||
Serial.write(mySerial.read());
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
ISR(TIMER0_COMPA_vect) {
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO && c) {
|
||||
#ifdef UDR0
|
||||
UDR0 = c;
|
||||
// writing direct to UDR0 is much much faster than Serial.print
|
||||
// but only one character can be written at a time.
|
||||
#else
|
||||
Serial.write(c);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void useInterrupt(bool v) {
|
||||
if (v) {
|
||||
// Timer0 is already used for millis() - we'll just interrupt somewhere
|
||||
// in the middle and call the "Compare A" function above
|
||||
OCR0A = 0xAF;
|
||||
TIMSK0 |= _BV(OCIE0A);
|
||||
usingInterrupt = true;
|
||||
} else {
|
||||
// do not call the interrupt function COMPA anymore
|
||||
TIMSK0 &= ~_BV(OCIE0A);
|
||||
usingInterrupt = false;
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// you can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
// this keeps track of whether we're using the interrupt
|
||||
// off by default!
|
||||
#ifndef ESP8266 // Sadly not on ESP8266
|
||||
bool usingInterrupt = false;
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
// connect at 115200 so we can read the GPS fast enuf and
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
delay(1000);
|
||||
Serial.println("Adafruit GPS logging start test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
// You can adjust which sentences to have the module emit, below
|
||||
// Default is RMC + GGA
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// Default is 1 Hz update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
|
||||
// the nice thing about this code is you can have a timer0 interrupt go off
|
||||
// every 1 millisecond, and read data from the GPS for you. that makes the
|
||||
// loop code a heck of a lot easier!
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
useInterrupt(true);
|
||||
#endif
|
||||
|
||||
delay(500);
|
||||
Serial.print("\nSTARTING LOGGING....");
|
||||
if (GPS.LOCUS_StartLogger())
|
||||
Serial.println(" STARTED!");
|
||||
else
|
||||
Serial.println(" no response :(");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
// do nothing! all reading and printing is done in the interrupt
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
ISR(TIMER0_COMPA_vect) {
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO && c) {
|
||||
#ifdef UDR0
|
||||
UDR0 = c;
|
||||
// writing direct to UDR0 is much much faster than Serial.print
|
||||
// but only one character can be written at a time.
|
||||
#else
|
||||
Serial.write(c);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void useInterrupt(bool v) {
|
||||
if (v) {
|
||||
// Timer0 is already used for millis() - we'll just interrupt somewhere
|
||||
// in the middle and call the "Compare A" function above
|
||||
OCR0A = 0xAF;
|
||||
TIMSK0 |= _BV(OCIE0A);
|
||||
usingInterrupt = true;
|
||||
} else {
|
||||
// do not call the interrupt function COMPA anymore
|
||||
TIMSK0 &= ~_BV(OCIE0A);
|
||||
usingInterrupt = false;
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code turns on the LOCUS built-in datalogger. The datalogger
|
||||
// turns off when power is lost, so you MUST turn it on every time
|
||||
// you want to use it!
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// you can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO false
|
||||
|
||||
// this keeps track of whether we're using the interrupt
|
||||
// off by default!
|
||||
#ifndef ESP8266 // Sadly not on ESP8266
|
||||
bool usingInterrupt = false;
|
||||
#endif
|
||||
|
||||
void setup()
|
||||
{
|
||||
while (!Serial); // the Leonardo will 'wait' until the USB plug is connected
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enuf and
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit GPS logging start test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for MTK - some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
// You can adjust which sentences to have the module emit, below
|
||||
// Default is RMC + GGA
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// Default is 1 Hz update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
|
||||
|
||||
// the nice thing about this code is you can have a timer0 interrupt go off
|
||||
// every 1 millisecond, and read data from the GPS for you. that makes the
|
||||
// loop code a heck of a lot easier!
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
useInterrupt(true);
|
||||
#endif
|
||||
|
||||
while (true) {
|
||||
Serial.print("Starting logging....");
|
||||
if (GPS.LOCUS_StartLogger()) {
|
||||
Serial.println(" STARTED!");
|
||||
break;
|
||||
} else {
|
||||
Serial.println(" no response :(");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t timer = 0;
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if ((c) && (GPSECHO))
|
||||
Serial.write(c);
|
||||
|
||||
if (millis() - timer > 1000)
|
||||
{
|
||||
timer = millis();
|
||||
if (GPS.LOCUS_ReadStatus()) {
|
||||
Serial.print("\n\nLog #");
|
||||
Serial.print(GPS.LOCUS_serial, DEC);
|
||||
if (GPS.LOCUS_type == LOCUS_OVERLAP)
|
||||
Serial.print(", Overlap, ");
|
||||
else if (GPS.LOCUS_type == LOCUS_FULLSTOP)
|
||||
Serial.print(", Full Stop, Logging");
|
||||
|
||||
if (GPS.LOCUS_mode & 0x1) Serial.print(" AlwaysLocate");
|
||||
if (GPS.LOCUS_mode & 0x2) Serial.print(" FixOnly");
|
||||
if (GPS.LOCUS_mode & 0x4) Serial.print(" Normal");
|
||||
if (GPS.LOCUS_mode & 0x8) Serial.print(" Interval");
|
||||
if (GPS.LOCUS_mode & 0x10) Serial.print(" Distance");
|
||||
if (GPS.LOCUS_mode & 0x20) Serial.print(" Speed");
|
||||
|
||||
Serial.print(", Content "); Serial.print((int)GPS.LOCUS_config);
|
||||
Serial.print(", Interval "); Serial.print((int)GPS.LOCUS_interval);
|
||||
Serial.print(" sec, Distance "); Serial.print((int)GPS.LOCUS_distance);
|
||||
Serial.print(" m, Speed "); Serial.print((int)GPS.LOCUS_speed);
|
||||
Serial.print(" m/s, Status ");
|
||||
if (GPS.LOCUS_status)
|
||||
Serial.print("LOGGING, ");
|
||||
else
|
||||
Serial.print("OFF, ");
|
||||
Serial.print((int)GPS.LOCUS_records); Serial.print(" Records, ");
|
||||
Serial.print((int)GPS.LOCUS_percent); Serial.print("% Used ");
|
||||
|
||||
}//if (GPS.LOCUS_ReadStatus())
|
||||
}//if (millis() - timer > 1000)
|
||||
}//loop
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
ISR(TIMER0_COMPA_vect) {
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
#ifdef UDR0
|
||||
// writing direct to UDR0 is much much faster than Serial.print
|
||||
// but only one character can be written at a time.
|
||||
UDR0 = c;
|
||||
#else
|
||||
Serial.print(c);
|
||||
#endif
|
||||
}
|
||||
|
||||
void useInterrupt(bool v) {
|
||||
if (v) {
|
||||
// Timer0 is already used for millis() - we'll just interrupt somewhere
|
||||
// in the middle and call the "Compare A" function above
|
||||
OCR0A = 0xAF;
|
||||
TIMSK0 |= _BV(OCIE0A);
|
||||
usingInterrupt = true;
|
||||
} else {
|
||||
// do not call the interrupt function COMPA anymore
|
||||
TIMSK0 &= ~_BV(OCIE0A);
|
||||
usingInterrupt = false;
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
|
||||
//
|
||||
// This code shows how to listen to the GPS module in an interrupt
|
||||
// which allows the program to have more 'freedom' - just parse
|
||||
// when a new NMEA sentence is available! Then access data when
|
||||
// desired.
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS module
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/746
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// Connect the GPS Power pin to 5V
|
||||
// Connect the GPS Ground pin to ground
|
||||
// Connect the GPS TX (transmit) pin to Digital 8
|
||||
// Connect the GPS RX (receive) pin to Digital 7
|
||||
|
||||
// you can change the pin numbers to match your wiring:
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
delay(5000);
|
||||
Serial.println("Adafruit GPS library basic parsing test!");
|
||||
|
||||
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
|
||||
GPS.begin(9600);
|
||||
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
|
||||
// the parser doesn't care about other sentences at this time
|
||||
|
||||
// Set the update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
|
||||
// For the parsing code to work nicely and have time to sort thru the data, and
|
||||
// print it out we don't suggest using anything higher than 1 Hz
|
||||
|
||||
// Request updates on antenna status, comment out to keep quiet
|
||||
GPS.sendCommand(PGCMD_ANTENNA);
|
||||
|
||||
delay(1000);
|
||||
// Ask for firmware version
|
||||
mySerial.println(PMTK_Q_RELEASE);
|
||||
}
|
||||
|
||||
uint32_t timer = millis();
|
||||
void loop() // run over and over again
|
||||
{
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if ((c) && (GPSECHO))
|
||||
Serial.write(c);
|
||||
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
|
||||
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// approximately every 2 seconds or so, print out the current stats
|
||||
if (millis() - timer > 2000) {
|
||||
timer = millis(); // reset the timer
|
||||
|
||||
Serial.print("\nTime: ");
|
||||
if (GPS.hour < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.hour, DEC); Serial.print(':');
|
||||
if (GPS.minute < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.minute, DEC); Serial.print(':');
|
||||
if (GPS.seconds < 10) { Serial.print('0'); }
|
||||
Serial.print(GPS.seconds, DEC); Serial.print('.');
|
||||
if (GPS.milliseconds < 10) {
|
||||
Serial.print("00");
|
||||
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.println(GPS.milliseconds);
|
||||
Serial.print("Date: ");
|
||||
Serial.print(GPS.day, DEC); Serial.print('/');
|
||||
Serial.print(GPS.month, DEC); Serial.print("/20");
|
||||
Serial.println(GPS.year, DEC);
|
||||
Serial.print("Fix: "); Serial.print((int)GPS.fix);
|
||||
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
|
||||
if (GPS.fix) {
|
||||
Serial.print("Location: ");
|
||||
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
|
||||
Serial.print(", ");
|
||||
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
|
||||
|
||||
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
|
||||
Serial.print("Angle: "); Serial.println(GPS.angle);
|
||||
Serial.print("Altitude: "); Serial.println(GPS.altitude);
|
||||
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
|
||||
Serial.print("Antenna status: "); Serial.println((int)GPS.antenna);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file NMEA_EXTENSIONS.ino
|
||||
|
||||
@section intro Introduction
|
||||
|
||||
An Arduino sketch for testing the NMEA_EXTENSIONS to the library. Does
|
||||
not require any GPS hardware. Boat is a data only object we can use to
|
||||
represent the actual data and build sentences from. GPS is a data only
|
||||
object that parses the sentences and saves the results, the same way you
|
||||
would with a communicating GPS object
|
||||
|
||||
Only some of the data values will have added history. Note that history
|
||||
is stored as integers, scaled and offset from the float values to save
|
||||
memory. The AWA (Apparent Wind Angle) is recorded as three components,
|
||||
so that sin and cos parts can be accurately time averaged. onList() allows
|
||||
testing sentences against a list to see if they should be passed on to
|
||||
another listener, allowing your sketch to act as an NMEA multiplexer.
|
||||
|
||||
Although it will just barely compile for an UNO with the NMEA_EXTENSIONS,
|
||||
defining two GPS objects pushes the limits of the UNO data space and
|
||||
should probably be avoided.
|
||||
|
||||
@section author Author
|
||||
|
||||
Written by Rick Sellens.
|
||||
|
||||
@section license License
|
||||
|
||||
CCBY license
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#include "Adafruit_GPS.h"
|
||||
Adafruit_GPS GPS; // The results obtained from the instruments -- no comms
|
||||
Adafruit_GPS Boat; // The state of the boat used to create some simulated sentences
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial && millis() < 10000); // Wait for monitor to be ready.
|
||||
Serial.print("\n\nNMEA_EXTENSIONS Example v 0.1.1\n\n");
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
addHistory(&GPS);
|
||||
#else
|
||||
Serial.print("NMEA_EXTENSIONS not #defined, so there will be no action.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
char latestBoat[200] = "";
|
||||
|
||||
const char *senList[] = {"GGA", "GLL", "DBT", "HDM", "MWV", "ZZ"}; // sentence list
|
||||
const char *passList[] = {"GGA", "DBT", "ZZ"}; // short list
|
||||
|
||||
void loop() {
|
||||
static unsigned long lastPrint = 0;
|
||||
updateBoat();
|
||||
// stop keeping AWA history after 30 seconds, just as a demonstration
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
if(millis() > 30000) GPS.removeHistory(NMEA_AWA);
|
||||
#endif
|
||||
if (millis() - lastPrint > 300 || lastPrint == 0) {
|
||||
lastPrint = millis();
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
Serial.print("\nSentences built from Boat and parsed by GPS ");
|
||||
Serial.print("(Only a few get passed on to the ST network.):\n\n");
|
||||
for (int i = 0;strncmp(senList[i],"ZZ",2);i++){
|
||||
if (GPS.parse(Boat.build(latestBoat, "II", senList[i]))){
|
||||
if (GPS.onList(latestBoat,passList))
|
||||
Serial.print("Pass to ST: ");
|
||||
else Serial.print(" No Pass: ");
|
||||
Serial.print(latestBoat);
|
||||
} else {
|
||||
Serial.print("Couldn't build and parse a ");
|
||||
Serial.print(senList[i]);
|
||||
Serial.print(" sentence, maybe because sprintf() doesn't work with %f.");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print("\nSome of the resulting data stored in GPS:\n\n");
|
||||
GPS.showDataValue(NMEA_LAT);
|
||||
GPS.showDataValue(NMEA_LON);
|
||||
GPS.showDataValue(NMEA_AWA, 20); // show more history values, if history on
|
||||
GPS.showDataValue(NMEA_AWA_SIN);
|
||||
GPS.showDataValue(NMEA_AWA_COS);
|
||||
GPS.showDataValue(NMEA_AWS);
|
||||
GPS.showDataValue(NMEA_HDG);
|
||||
GPS.showDataValue(NMEA_DEPTH);
|
||||
|
||||
Serial.print("\nThe AWA is: ");
|
||||
Serial.print(GPS.get(NMEA_AWA));
|
||||
Serial.print(" while the smoothed value is: ");
|
||||
Serial.println(GPS.getSmoothed(NMEA_AWA));
|
||||
|
||||
#endif // NMEA_Extensions
|
||||
}
|
||||
}
|
||||
|
||||
void updateBoat() { // Fill up the boat values with
|
||||
// some test data to use in build()
|
||||
nmea_float_t t = millis() / 1000.;
|
||||
nmea_float_t theta = t / 100.; // slow
|
||||
nmea_float_t gamma = theta * 10; // faster
|
||||
|
||||
// add some data to the old Adafruit_GPS variables
|
||||
Boat.latitude = 4400 + sin(theta) * 60;
|
||||
Boat.lat = 'N';
|
||||
Boat.longitude = 7600 + cos(theta) * 60;
|
||||
Boat.lon = 'W';
|
||||
Boat.fixquality = 2;
|
||||
Boat.speed = 3 + sin(gamma);
|
||||
Boat.hour = abs(cos(theta)) * 24;
|
||||
Boat.minute = 30 + sin(theta / 2) * 30;
|
||||
Boat.seconds = 30 + sin(gamma) * 30;
|
||||
Boat.milliseconds = 500 + sin(gamma) * 500;
|
||||
Boat.year = 1 + abs(sin(theta)) * 25;
|
||||
Boat.month = 1 + abs(sin(gamma)) * 11;
|
||||
Boat.day = 1 + abs(sin(gamma)) * 26;
|
||||
Boat.satellites = abs(cos(gamma)) * 10;
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
// add some data to the new NMEA data values
|
||||
Boat.newDataValue(NMEA_AWS, 10 + cos(theta));
|
||||
Boat.newDataValue(NMEA_AWA, 180 * sin(gamma));
|
||||
Boat.newDataValue(NMEA_VTW, Boat.speed + cos(gamma) / 3);
|
||||
Boat.newDataValue(NMEA_DEPTH, 10 + cos(gamma) * 5);
|
||||
Boat.newDataValue(NMEA_HDG, 180 * sin(gamma) + 180);
|
||||
Boat.newDataValue(NMEA_HDT, 180 * cos(gamma) + 180);
|
||||
Boat.newDataValue(NMEA_VMG, sin(gamma) * 3);
|
||||
Boat.newDataValue(NMEA_VMGWP, cos(gamma) * 5);
|
||||
#endif // NMEA_EXTENSIONS
|
||||
}
|
||||
|
||||
#ifdef NMEA_EXTENSIONS
|
||||
void addHistory(Adafruit_GPS *nmea) {
|
||||
// Record integer history for HDOP, scaled by 10.0, offset by 0.0,
|
||||
// every 15 seconds for the most recent 20 values.
|
||||
nmea->initHistory(NMEA_HDOP, 10.0, 0.0, 15, 20);
|
||||
nmea->initHistory(NMEA_COG, 10.0, 0.0, 1);
|
||||
nmea->initHistory(NMEA_AWA, 10.0, 0.0, 1);
|
||||
nmea->initHistory(NMEA_HDG, 10.0, 0.0, 3);
|
||||
// Record pressure every 10 minutes, in Pa relative to 1 bar
|
||||
nmea->initHistory(NMEA_BAROMETER, 1.0, -100000.0, 600);
|
||||
nmea->initHistory(NMEA_DEPTH, 10.0, 0.0, 3);
|
||||
}
|
||||
#endif // NMEA_EXTENSIONS
|
||||
@@ -0,0 +1,11 @@
|
||||
// this sketch will allow you to bypass the Atmega chip
|
||||
// and connect the GPS sensor directly to the USB/Serial
|
||||
// chip converter.
|
||||
|
||||
// Connect VIN to +5V
|
||||
// Connect GND to Ground
|
||||
// Connect GPS RX (data into GPS) to Digital 0
|
||||
// Connect GPS TX (data out from GPS) to Digital 1
|
||||
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
@@ -0,0 +1,210 @@
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_GPS.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include <SD.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
// Ladyada's logger modified by Bill Greiman to use the SdFat library
|
||||
//
|
||||
// This code shows how to listen to the GPS module in an interrupt
|
||||
// which allows the program to have more 'freedom' - just parse
|
||||
// when a new NMEA sentence is available! Then access data when
|
||||
// desired.
|
||||
//
|
||||
// Tested and works great with the Adafruit Ultimate GPS Shield
|
||||
// using MTK33x9 chipset
|
||||
// ------> http://www.adafruit.com/products/
|
||||
// Pick one up today at the Adafruit electronics shop
|
||||
// and help support open source hardware & software! -ada
|
||||
// Fllybob added 10 sec logging option
|
||||
SoftwareSerial mySerial(8, 7);
|
||||
Adafruit_GPS GPS(&mySerial);
|
||||
|
||||
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
|
||||
// Set to 'true' if you want to debug and listen to the raw GPS sentences
|
||||
#define GPSECHO true
|
||||
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
|
||||
#define LOG_FIXONLY false
|
||||
|
||||
// this keeps track of whether we're using the interrupt
|
||||
// off by default!
|
||||
#ifndef ESP8266 // Sadly not on ESP8266
|
||||
bool usingInterrupt = false;
|
||||
#endif
|
||||
|
||||
// Set the pins used
|
||||
#define chipSelect 10
|
||||
#define ledPin 13
|
||||
|
||||
File logfile;
|
||||
|
||||
// read a Hex value and return the decimal equivalent
|
||||
uint8_t parseHex(char c) {
|
||||
if (c < '0')
|
||||
return 0;
|
||||
if (c <= '9')
|
||||
return c - '0';
|
||||
if (c < 'A')
|
||||
return 0;
|
||||
if (c <= 'F')
|
||||
return (c - 'A')+10;
|
||||
}
|
||||
|
||||
// blink out an error code
|
||||
void error(uint8_t errno) {
|
||||
/*
|
||||
if (SD.errorCode()) {
|
||||
putstring("SD error: ");
|
||||
Serial.print(card.errorCode(), HEX);
|
||||
Serial.print(',');
|
||||
Serial.println(card.errorData(), HEX);
|
||||
}
|
||||
*/
|
||||
while(1) {
|
||||
uint8_t i;
|
||||
for (i=0; i<errno; i++) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(ledPin, LOW);
|
||||
delay(100);
|
||||
}
|
||||
for (i=errno; i<10; i++) {
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// for Leonardos, if you want to debug SD issues, uncomment this line
|
||||
// to see serial output
|
||||
//while (!Serial);
|
||||
|
||||
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
|
||||
// also spit it out
|
||||
Serial.begin(115200);
|
||||
Serial.println("\r\nUltimate GPSlogger Shield");
|
||||
pinMode(ledPin, OUTPUT);
|
||||
|
||||
// make sure that the default chip select pin is set to
|
||||
// output, even if you don't use it:
|
||||
pinMode(10, OUTPUT);
|
||||
|
||||
if (!SD.begin(chipSelect)) {
|
||||
Serial.println("Card init. failed!");
|
||||
error(2);
|
||||
}
|
||||
char filename[15];
|
||||
strcpy(filename, "GPSLOG00.TXT");
|
||||
for (uint8_t i = 0; i < 100; i++) {
|
||||
filename[6] = '0' + i/10;
|
||||
filename[7] = '0' + i%10;
|
||||
// create if does not exist, do not open existing, write, sync after write
|
||||
if (! SD.exists(filename)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logfile = SD.open(filename, FILE_WRITE);
|
||||
if( ! logfile ) {
|
||||
Serial.print("Couldnt create ");
|
||||
Serial.println(filename);
|
||||
error(3);
|
||||
}
|
||||
Serial.print("Writing to ");
|
||||
Serial.println(filename);
|
||||
|
||||
// connect to the GPS at the desired rate
|
||||
GPS.begin(9600);
|
||||
|
||||
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
|
||||
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
|
||||
// uncomment this line to turn on only the "minimum recommended" data
|
||||
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
|
||||
// For logging data, we don't suggest using anything but either RMC only or RMC+GGA
|
||||
// to keep the log files at a reasonable size
|
||||
// Set the update rate
|
||||
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 100 millihertz (once every 10 seconds), 1Hz or 5Hz update rate
|
||||
|
||||
// Turn off updates on antenna status, if the firmware permits it
|
||||
GPS.sendCommand(PGCMD_NOANTENNA);
|
||||
|
||||
// the nice thing about this code is you can have a timer0 interrupt go off
|
||||
// every 1 millisecond, and read data from the GPS for you. that makes the
|
||||
// loop code a heck of a lot easier!
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
useInterrupt(true);
|
||||
#endif
|
||||
|
||||
Serial.println("Ready!");
|
||||
}
|
||||
|
||||
|
||||
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
|
||||
#ifndef ESP8266 // Not on ESP8266
|
||||
ISR(TIMER0_COMPA_vect) {
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
#ifdef UDR0
|
||||
if (GPSECHO)
|
||||
if (c) UDR0 = c;
|
||||
// writing direct to UDR0 is much much faster than Serial.print
|
||||
// but only one character can be written at a time.
|
||||
#endif
|
||||
}
|
||||
|
||||
void useInterrupt(bool v) {
|
||||
if (v) {
|
||||
// Timer0 is already used for millis() - we'll just interrupt somewhere
|
||||
// in the middle and call the "Compare A" function above
|
||||
OCR0A = 0xAF;
|
||||
TIMSK0 |= _BV(OCIE0A);
|
||||
usingInterrupt = true;
|
||||
}
|
||||
else {
|
||||
// do not call the interrupt function COMPA anymore
|
||||
TIMSK0 &= ~_BV(OCIE0A);
|
||||
usingInterrupt = false;
|
||||
}
|
||||
}
|
||||
#endif // ESP8266
|
||||
|
||||
void loop() {
|
||||
if (! usingInterrupt) {
|
||||
// read data from the GPS in the 'main loop'
|
||||
char c = GPS.read();
|
||||
// if you want to debug, this is a good time to do it!
|
||||
if (GPSECHO)
|
||||
if (c) Serial.print(c);
|
||||
}
|
||||
|
||||
// if a sentence is received, we can check the checksum, parse it...
|
||||
if (GPS.newNMEAreceived()) {
|
||||
// a tricky thing here is if we print the NMEA sentence, or data
|
||||
// we end up not listening and catching other sentences!
|
||||
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
|
||||
|
||||
// Don't call lastNMEA more than once between parse calls! Calling lastNMEA
|
||||
// will clear the received flag and can cause very subtle race conditions if
|
||||
// new data comes in before parse is called again.
|
||||
char *stringptr = GPS.lastNMEA();
|
||||
|
||||
if (!GPS.parse(stringptr)) // 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
|
||||
|
||||
// Sentence parsed!
|
||||
Serial.println("OK");
|
||||
if (LOG_FIXONLY && !GPS.fix) {
|
||||
Serial.print("No Fix");
|
||||
return;
|
||||
}
|
||||
|
||||
// Rad. lets log it!
|
||||
Serial.println("Log");
|
||||
|
||||
uint8_t stringsize = strlen(stringptr);
|
||||
if (stringsize != logfile.write((uint8_t *)stringptr, stringsize)) //write the string to the SD file
|
||||
error(4);
|
||||
if (strstr(stringptr, "RMC") || strstr(stringptr, "GGA")) logfile.flush();
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user