Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

GPS-Code

GPS-Code

This example shows how to use the GPS, it just prints the GPS-Data to the serialport. The GPS-Data will be captures with the second serialport. The example uses the TinyGPS Library. I just made a wrapperclass 'GpsWrapper' around the library to simplify the access to the GPS-Data. Small Class Docu 'GpsWrapper'
bool start(HardwareSerial* serialPort,int baudRate)
To start the GPS-Communication call this function with the serialPort where the GPS is connected + the baudrate
bool isValid()
Returns if the data from the GPS is valid
long latitude()
float latitudef()
Returns the latitude as long or as float value.
long  longitude()
float longitudef()
Returns the longitued as long or as float value.
float   altitude()
Returns the current height over see as long or as float value.
float  course()
Returns the direction of movement in degrees
float  speedKmph()
Returns the current speed
float  distance(float lat1, float long1, float lat2, float long2, float unitsPerMeter)
Returns the distance from to locations
float   angle(float lat1, float long1, float lat2, float long2)
Returns the angle between to locations
Setup
Connections:
Type                    Controller                      GPS                                    Color
VCC,3.3v            VCC                                4,5  (VDD,VBAT)             Red
GND                     GND                              3 (GND)                                Black
Serial                    RX1(D10)                    2 (TXD)                                Brown
Serial                    TX1 (D11)                    1 (RXD)                                Green
#include <TinyGPS.h>
#include "gpsWrapper.h"

GpsWrapper  gpsWrapper;
unsigned long start = millis();

void setup()
{
  // output serial
  Serial.begin(9600);
  Serial.println("-----------------");
  Serial.println("Start gps reading");
  Serial.println("-----------------");

  // gps serial
  gpsWrapper.start(&Serial1,9600);
}

void loop()
{
  gpsWrapper.parseGps();

  if(millis() - start > 3000)
  {  // output data
    start = millis();

    // print out status
    gpsWrapper.dump(&Serial);
  }
}
If you run the code, be aware that you should have straight view to the sky. Also it will take around 30-60sec till the gps delivers valid data, if you do a coldstart. Download Source