Pin connections
Module - Arduino GND - GND RX - Pin 11 TX - Pin 10 VCC - 3.3VOutput is via UART, 9600 baud 8/none/1. Format is NMEA
$ ADDR ,VALUES *CHECKSUM CRLF
ADDR is GPxxx xxx = msg format ,VALUES are ‘,’ separated values *CHECKSUM (no prior ‘,’) is Hex exclusive OR $ to *Latitude and longitude
Latitude or Longitude min.decmin
e.g. Lat 5204.82093 = 52deg 04.82093min
e.g. Long 00120.77221 = 1deg 20.77221min
Typical module output and message formats
NMEA sentences
$Address ,[value] ... *[checksum]$GPRMC fields are
Field 1 UTC hhmmss.ss 2 A|V status 3 Lat ddmm.mmmm 4 N|S 5 Lon dddmm.mmmm 6 E|W 7 SOG knots 8 COG deg T 9 Date ddmmyy + some others $GPVTG fields are Field 1 True Track 2 T 3 Magnetic track 4 M 5 Ground Speed, knots 6 N 7 GroundSpeed, Km/h 8 K $GPGGA fields are Field 1 Time UTC 2 Latitude 3 NS 4 Longitude 5 EW 6 Fix quality 0 - invalid, 1 = GPS fix, 2-9 other 7 No of satellits tracked 8 Horix dilution 9 Altitude metres ASL 10 Height geoid abbove WSG84 metres + others $GPGSV fields are satellite positions and data $GPGLL fields are 1 Latitude 2 NS 3 Longitude 4 EW 5 Time 6 AV active or voidCode for 128 x 64 LCD display using U8glib LCD library
#include "SoftwareSerial.h" #include "U8glib.h" // GPS 11 RX, 10 TX SoftwareSerial gps(10, 11); // LCD 6 SCK(E), 5 MOSI(RW), 4 SS(RS) U8GLIB_ST7920_128X64_1X lcd(6, 5, 4); void setup() { gps.begin(9600); // start GPS serial } void loop() { char gpsbuf[200]; // GPS output line char pbuf[20]; // extract and printed buffer do { getline(gpsbuf); } while(strncmp(gpsbuf, "$GPRMC", 6) != 0); lcd.firstPage(); do { lcd.setFont(u8g_font_helvR08); // 1st line lcd.drawStr(2, 8, "Latitude"); lcd.drawStr(66, 8, "Longitude"); // Lat extfmt(3, "** ****", gpsbuf, pbuf); lcd.drawStr(2, 19, pbuf); // NS extfmt(4, "*", gpsbuf, pbuf); lcd.drawStr(40, 19, pbuf); // Lon extfmt(5, "*** ****", gpsbuf, pbuf); lcd.drawStr(66, 19, pbuf); // EW extfmt(6, "*", gpsbuf, pbuf); lcd.drawStr(110, 19, pbuf); // 2nd line lcd.drawStr(2, 40, "Time"); lcd.drawStr(66, 40, "Date"); // Time extfmt(1, "**:**", gpsbuf, pbuf); lcd.drawStr(2, 51, pbuf); // Date extfmt(9, "**-**-**", gpsbuf, pbuf); lcd.drawStr(66, 51, pbuf); } while(lcd.nextPage()); } // get a line from the GPS void getline(char *buf) { int bp = 0; char c; do { c = gps.read(); // -1 if no char available if(c == -1) continue; buf[bp++] = c; } while(c != '\n'); buf[bp] = '\0'; } // find field, extract in fmt from inbuf to outbuf // fmt * = copy inbuf to outbuf, else copy fmt to outbuf void extfmt(int field, char *fmt, char *inbuf, char *outbuf) { int f = 0; // field count and char pointers int fp = 0; int ip = 0; int op = 0; // find field and ip start while(f != field) { while(inbuf[ip++] != ','); f++; } // format from ip while(fmt[fp] !='\0') { if(fmt[fp] == '*') outbuf[op] = inbuf[ip++]; // outbuf = inbuf else outbuf[op] = fmt[fp]; // outbuf = fmt fp++; op++; } outbuf[op] = '\0'; // add end of string }
No comments:
Post a Comment