Description
The following methods allow to read the current (latest) positioning information from the GPS library. Call isPositionValid()
and available()
before using any of the read functions. This ensures that the new data is valid and up-to-date.
Syntax
GPS.latitude()
GPS.longitude()
GPS.speed()
GPS.course()
GPS.altitude()
GPS.satellites()
GPS.variation()GPS.isReceiverPresent()
GPS.isPositionValid()
– returns true if the latest position is valid (see GGA-Quality indicator and RMC frame details)GPS.available()
– returns true only once per received position. It indicates that new position data was received from the GPS module since the last time read. Calling available deletes the flag and will be set again by the next valid position NMEA info from the module.GPS.unValidPosition()
– manually deletes the ‘available’-flag. It will be set by the next reception of a valid NMEA sentence from the module
GPS.isReceiverPresent()
– checks if there is a dice-device on the CAN bus that is postulating positioning information (datapool) at all. This might be helpful in distributed systems where in some variant there is a dice-IoT, dice-GNSS etc. be part of the bus or not.
Parameters
none
Returns
float – holding the information for latitude, longitude, speed, course, altitude and magnetic variation
int – for the number of satellites
Example Code
The following example runs on any dice device. It either receives the GPS data with its embedded receiver or gets it from a capable node on the CAN bus (via data pool)
#include "DICE_GPS.h"
void setup()
{
GPS.begin();
while(!Serial);
Serial.println("Waiting for GPS reception");
}
void loop()
{
while(!GPS.isPositionValid() || !GPS.available()) { yield(); };
Serial.println("GPS data:");
Serial.println("- latitude: "+String(GPS.latitude()));
Serial.println("- longitude:"+String(GPS.longitude()));
GPS.end();
while(1) { yield(); };
}
Notes and Warnings
—
Examples can be found in the Arduino IDE menu:
File -> Examples -> DICE_GPS ->