GPStest.ino
1 // SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 // Test code for Adafruit GPS modules using MTK driver 6 // such as www.adafruit.com/products/660 (discontinued) 7 // For new use see www.adafruit.com/products/746 (needs different code) 8 // help support open source hardware & software! -adafruit 9 10 #include <SoftwareSerial.h> 11 SoftwareSerial mySerial(2, 3); 12 13 // Connect the GPS Power pin to 3.3V 14 // Connect the GPS Ground pin to ground 15 // Connect the GPS VBAT pin to 3.3V if no battery is used 16 // Connect the GPS TX (transmit) pin to Digital 2 17 // Connect the GPS RX (receive) pin to Digital 3 18 // For 3.3V only modules such as the UP501, connect a 10K 19 // resistor between digital 3 and GPS RX and a 10K resistor 20 // from GPS RX to ground. 21 22 // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz) 23 #define PMTK_SET_NMEA_UPDATE_1HZ "$PMTK220,1000*1F" 24 #define PMTK_SET_NMEA_UPDATE_5HZ "$PMTK220,200*2C" 25 #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F" 26 27 // turn on only the second sentence (GPRMC) 28 #define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" 29 // turn on ALL THE DATA 30 #define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28" 31 32 // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator 33 // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html 34 35 void setup() 36 { 37 Serial.begin(57600); 38 Serial.println("Adafruit MTK3329 NMEA test!"); 39 40 // 9600 NMEA is the default baud rate 41 mySerial.begin(9600); 42 43 // uncomment this line to turn on only the "minimum recommended" data for high update rates! 44 //mySerial.println(PMTK_SET_NMEA_OUTPUT_RMCONLY); 45 46 // uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate 47 mySerial.println(PMTK_SET_NMEA_OUTPUT_ALLDATA); 48 49 // Set the update rate 50 // 1 Hz update rate 51 mySerial.println(PMTK_SET_NMEA_UPDATE_1HZ); 52 // 5 Hz update rate- for 9600 baud you'll have to set the output to RMC only (see above) 53 //mySerial.println(PMTK_SET_NMEA_UPDATE_5HZ); 54 // 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above) 55 //mySerial.println(PMTK_SET_NMEA_UPDATE_10HZ); 56 57 } 58 59 void loop() // run over and over again 60 { 61 62 if (mySerial.available()) { 63 Serial.print((char)mySerial.read()); 64 } 65 if (Serial.available()) { 66 mySerial.print((char)Serial.read()); 67 } 68 }