-dev:
No. Was there something wrong with the code I provided?gps.send_P( &gpsPort, (const __FlashStringHelper *) baud38400 );
Copy the
baud38400
variable declaration too:const char baud38400 [] PROGMEM = "PUBX,41,1,3,3,38400,0";
The problem was I didn't realize the first line you gave me also needed the 2nd line added to create the variable. I thought "baud38400" was the actual command, not a variable.
Regarding the rate change w/in Setup, nobody ever told me I could call functions in setup. Putting the void sendUBX code into Setup didn't work well. Whoops.
I just tested the revised code and it works GREAT! At 5Hz and 10Hz the 6m reports centiseconds of 00/20/40/60/80, at 1Hz it shows 00 and refreshes the serial monitor only once per sec as expected.
Here's what I'm sticking with, hopefully it helps provide other people with a shortcut along with the "NeoGPS for Dummies" provided above. Thanks again -dev, you're a great guy with great code. This will save me a lot of time dinking around with eeprom, batteries, and connecting the GPS separately.
#include <NMEAGPS.h>
#include <AltSoftSerial.h>
AltSoftSerial gpsPort; // GPS TX to pin 8, GPS RX to pin 9
NMEAGPS gps;
const unsigned char ubxRate1Hz[] PROGMEM =
{ 0x06,0x08,0x06,0x00,0xE8,0x03,0x01,0x00,0x01,0x00 };
const unsigned char ubxRate5Hz[] PROGMEM =
{ 0x06,0x08,0x06,0x00,200,0x00,0x01,0x00,0x01,0x00 };
const unsigned char ubxRate10Hz[] PROGMEM =
{ 0x06,0x08,0x06,0x00,100,0x00,0x01,0x00,0x01,0x00 };
const char baud38400 [] PROGMEM = "PUBX,41,1,3,3,38400,0";
int runoncevar = 0;
//size_t len;
//uint8_t a = 0, b = 0;
void setup()
{
Serial.begin(9600);
gpsPort.begin(9600);
gps.send_P( &gpsPort, (const __FlashStringHelper *) baud38400 );
gpsPort.flush(); // wait for the command to go out
delay( 100 ); // wait for the GPS device to change speeds
gpsPort.end(); // empty the input buffer, too
gpsPort.begin( 38400 ); // use the new baud rate
sendUBX( ubxRate5Hz, sizeof(ubxRate5Hz) ); // change both "ubxRate5Hz" to "ubxRate1Hz" or ubxRate10Hz" for different rates
Serial.println( F("GPS Start") ); // F macro saves RAM
}
void loop()
{
// if (runoncevar = 0)
// {
// runoncevar++;
// sendUBX( ubxRate5Hz, sizeof(ubxRate5Hz) );
// }
if (gps.available( gpsPort ))
{
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
gps_fix fix = gps.read();
Serial.print( F("Satellite Count:") );
if (fix.valid.satellites)
Serial.print( fix.satellites );
Serial.print( F("\nLatitude:") );
if (fix.valid.location)
Serial.print( fix.latitude(), 6 );
Serial.print( F("\nLongitude:") );
if (fix.valid.location)
Serial.print( fix.longitude(), 6 );
Serial.print( F("\nSpeed MPH:") );
if (fix.valid.speed)
Serial.print( fix.speed_mph() );
// Serial.print( F("\nAltitude Meters:") );
// if (fix.valid.altitude)
// Serial.print( fix.altitude());
Serial.print( F("\nHeading:") );
if (fix.valid.heading)
Serial.print( fix.heading() );
if (fix.valid.time){
Serial.print( F("\nMinutes:") );
Serial.print(fix.dateTime.minutes);
Serial.print( F("\nSeconds:") );
Serial.print(fix.dateTime.seconds);
Serial.print( F("\nCentiSeconds:") );
Serial.print( fix.dateTime_cs );
}
Serial.println();
}
}
void sendUBX( const unsigned char *progmemBytes, size_t len )
{
gpsPort.write( 0xB5 ); // SYNC1
gpsPort.write( 0x62 ); // SYNC2
uint8_t a = 0, b = 0;
while (len-- > 0) {
uint8_t c = pgm_read_byte( progmemBytes++ );
a += c;
b += a;
gpsPort.write( c );
}
gpsPort.write( a ); // CHECKSUM A
gpsPort.write( b ); // CHECKSUM B
}