Tuesday 8 November 2016

Add ability to measure GPS data to the robot

For this I am using an item entitled "GY-NEO6MV2 GPS EEPROM MWC APM2.5 For Arduino" on ebay.

Having connected it to my USB to TTL converter and a 3.3V source I ran up the u-blox application u-center and got the following out in the text console:
15:21:06  $GPRMC,152106.00,A,5140.74757,N,00117.62006,W,0.342,,081116,,,A*6A
15:21:06  $GPVTG,,T,,M,0.342,N,0.633,K,A*20
15:21:06  $GPGGA,152106.00,5140.74757,N,00117.62006,W,1,03,4.08,64.0,M,47.1,M,,*73
15:21:06  $GPGSA,A,2,02,06,09,,,,,,,,,,4.20,4.08,1.00*05
15:21:06  $GPGSV,1,1,03,02,40,300,33,06,64,247,36,09,84,142,33*4D
15:21:06  $GPGLL,5140.74757,N,00117.62006,W,152106.00,A,A*79
Message Name Meaning
$GPRMC Recommended Minimum data
$GPVTG Course over ground and Ground speed
$GPGGA Global positioning system fix data
$GPGSA GNSS DOP and Active Satellites
$GPGSV GNSS Satellites in View
$GPGLL Latitude and longitude, with time of position fix and status
I need to use an esp specific version of SoftwareSerial as I do not want to use the main rx,tx pins of the esp-12f. To decode the messages from the gps device read on pin14 I use a TinyGPS object

//gps serial 
TinyGPS gps;
// rx 14, tx 12 - brown
SoftwareSerial gpsSer(14,12, false, 256);

loop{
...

while (gpsSer.available()){
    if(gps.encode(gpsSer.read())){
      long lat, lon;
      unsigned long fix_age, time, date, speed, course;
      unsigned long chars;
      unsigned short sentences, failed_checksum;
       
      // retrieves +/- lat/long in 100000ths of a degree
      gps.get_position(&lat, &lon, &fix_age);
       
      // time in hhmmsscc, date in ddmmyy
      gps.get_datetime(&date, &time, &fix_age);
       
      // returns speed in 100ths of a knot
      speed = gps.speed();
       
      // course in 100ths of a degree
      course = gps.course();

      Serial.print("Latitude:");
      Serial.print( lat);
      Serial.print(" Longitude:");
      Serial.println( lon);
      
      break;
    }
  }
...
}

No comments:

Post a Comment