Hi,
I'm using an Arduino Nano (pins 0 and 1) and GPS 6MU2 and am building a program to track a motorbike drive. TinyGPS++ works, but not quickly enough (1 second at 70 mph = 40 meters between positions, I'd like to aim for 4 meters). I've found neoGPS and have spent days reading some cracking, if complex, code and examples.
I am an Engineer with good visual basic coding skills, but limited Arduino skills. I mainly learn by modifying existing code and searching forums, which I have done BUT cannot answer my current issues.
Question 1
The below code runs well but latitude (and longitude) report as 50123, not 50.123.
I'm using fix.latitudeL for maximum accuracy.
Also, fix.altitude_cm() reports as 10880, not 108.80 which I would prefer. I guess both these issues have one solution. I have tried sprintf and a variety of other functions but nothing that works so far.
Question 2
There are several very detailed notes on running the system at 5Hz or 10Hz, instead of the 1Hz I think it is running now but all WAY above my knowledge to interpret. Does anyone have some simple example of how I can achieve this?
Question 3
My code (scroll down to doSomeWork, I've included everything as I notice some folk ask for that) feels a bit lengthy - I've used 1/3 of the program space just to log the GPS without adding the code of the SD card etc. Am I making some newbie mistakes and can it be streamlined?
#include <NMEAGPS.h>
//======================================================================
// Program: NMEA_Paul.ino v1.4
//
// Description: This program is a cut-down of NMEA.ino to suit a Nano.
//
// License: Copyright (C) 2014-2017, SlashDevin
//======================================================================
// Next actions;
// Code runs, but how to normalise Lat and Long? i.e. 50.123 not 50123
// Same question for altitude 108.80 not 10880
// GPS running at 1Hz, it can run at 10Hz - How?
//======================================================================
//White wire - GPS Tx to Nano Rx pin 0 (DISCONNECT (0) to upload a new Sketch)
//Blue wire - GPS Rx to Nano Tx pin 1
// To get the examples working the GPSport.h file has been edited to the below.
// When testing finished this note and the next line can be deleted and the
// following three lines uncommented.
#include <GPSport.h>
//#define gpsPort Serial
//#define GPS_PORT_NAME "Serial"
//#define DEBUG_PORT Serial
// **WARNING:
// ERROR: LAST_SENTENCE_IN_INTERVAL is incorrectly set to NMEAGPS::NMEA_RMC!
// You must change this line in NMEAGPS_cfg.h:
// #define LAST_SENTENCE_IN_INTERVAL NMEAGPS::NMEA_GLL <<<< Changed
//
// There are 7 instances of NMEAGPS_cfg.h The one you want is libraries/NeoGPS/extras/configs/Nominal
// GGA has altitude and satellite fixes
// RMC has status, date, time, lat/long, speed and heading
// therefore no other words are needed. Comment out in NMEAGPS_cfg.h
//------------------------------------------------------------
// This object parses received characters into the gps.fix() data structure
static NMEAGPS gps;
//------------------------------------------------------------
// Define a set of GPS fix information. It will hold on to the various pieces
// as they are received from an RMC sentence. It can be used anywhere in your sketch.
static gps_fix fix;
//----------------------------------------------------------------
// This function gets called about once per second, during the GPS
// quiet time. By doing the "hard" work during the quiet time, the CPU can get back to
// reading the GPS chars as they come in, so that no chars are lost.
String s_SD_Card; // Storage to build up the CSV word to be written to the SD card
String s_header = ("Date,Time,Lat,Long,Height,Speed,Fixes");
void setup()
{
Serial.println (s_header);
gpsPort.begin( 9600 );
} // end setup
//--------------------------
void loop()
{
GPSloop();
} // end loop
//---------------------------
// This is the main GPS parsing loop.
static void GPSloop()
{
while (gps.available( gpsPort )) {
fix = gps.read();
doSomeWork();
}
} // end GPSloop
//-------------------------
static void doSomeWork()
{
// Create a string to write CSV data to an SD card
s_SD_Card = ""; //Empty any previous data
if (fix.valid.date) {
s_SD_Card = String(fix.dateTime.full_year() ) + "-";
s_SD_Card = s_SD_Card + String(fix.dateTime.month) + "-";
s_SD_Card = s_SD_Card + String(fix.dateTime.date) + ",";
}
else {
s_SD_Card = ", ";
} //end if valid date
if (fix.valid.time) {
if ( fix.dateTime.hours < 10 ) {s_SD_Card = s_SD_Card + "0";}
s_SD_Card = s_SD_Card + String(fix.dateTime.hours) + ":" ;
if ( fix.dateTime.minutes < 10 ) {s_SD_Card = s_SD_Card + "0";}
s_SD_Card = s_SD_Card + String(fix.dateTime.minutes) + ":";
if ( fix.dateTime.seconds < 10 ) {s_SD_Card = s_SD_Card + "0";}
s_SD_Card = s_SD_Card + String(fix.dateTime.seconds) + ".";
if ( fix.dateTime_cs < 10 ) {s_SD_Card = s_SD_Card + "0";}
s_SD_Card = s_SD_Card + String(fix.dateTime_cs) + ", ";
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid time
if (fix.valid.location) {
s_SD_Card = s_SD_Card + String(fix.latitudeL()) + ", ";
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid lat
if (fix.valid.location) {
s_SD_Card = s_SD_Card + String(fix.longitudeL()) + ", ";
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid lat
if (fix.valid.altitude) {
s_SD_Card = s_SD_Card + String( fix.altitude_cm() ) + ", "; //in integer centimeters
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid height in cm
if (fix.valid.speed) {
s_SD_Card = s_SD_Card + String( fix.speed_mph() ) + ", "; //in floating-point miles per hour
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid speed
if (fix.valid.satellites) {
s_SD_Card = s_SD_Card + String( fix.satellites ) + ", ";
}
else {
s_SD_Card = s_SD_Card + ", ";
} //end if valid fixes
//This will be saved to an SD card, printing for now to debug
Serial.print (s_SD_Card );
//Section break
Serial.println(" ");
} // enddoSomeWork