PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

simple_test.ino 2.7KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <TinyGPS.h>
  2. #include <SoftwareSerial.h>
  3. /* This sample code demonstrates the normal use of a TinyGPS object.
  4. It assumes that you have a 4800-baud serial GPS device hooked up
  5. to a serial port, or SoftwareSerial on pins 4(rx) and 3(tx).
  6. */
  7. TinyGPS gps;
  8. // Use one of these to connect your GPS
  9. // ------------------------------------
  10. #define gpsPort Serial1
  11. //SoftwareSerial gpsPort(4, 3);
  12. char buf[32];
  13. void setup()
  14. {
  15. Serial.begin(115200);
  16. gpsPort.begin(4800);
  17. Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  18. Serial.println("by Mikal Hart");
  19. Serial.println();
  20. }
  21. void loop()
  22. {
  23. bool newData = false;
  24. unsigned long chars;
  25. unsigned short sentences, failed;
  26. // For one second we parse GPS data and report some key values
  27. for (unsigned long start = millis(); millis() - start < 1000;) {
  28. while (gpsPort.available()) {
  29. char c = gpsPort.read();
  30. // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
  31. if (gps.encode(c)) // Did a new valid sentence come in?
  32. newData = true;
  33. }
  34. }
  35. unsigned long age;
  36. if (newData) {
  37. float flat, flon;
  38. gps.f_get_position(&flat, &flon, &age);
  39. Serial.print("LAT=");
  40. Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
  41. Serial.print(" LON=");
  42. Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
  43. Serial.print(" SAT=");
  44. Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
  45. Serial.print(" PREC=");
  46. Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  47. //GPS mode
  48. Serial.print(" Constellations=");
  49. Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0 : gps.constellations());
  50. }
  51. //satellites in view
  52. uint32_t* satz = gps.trackedSatellites();
  53. uint8_t sat_count = 0;
  54. for(int i=0;i<24;i++) {
  55. if(satz[i] != 0) { //exclude zero SNR sats
  56. sat_count++;
  57. byte strength = (satz[i]&0xFF)>>1;
  58. byte prn = satz[i]>>8;
  59. sprintf(buf, "PRN %d: ", prn);
  60. Serial.print(buf);
  61. Serial.print(strength);
  62. Serial.println("dB");
  63. }
  64. }
  65. //date time
  66. int year;
  67. uint8_t month, day, hour, minutes, second, hundredths;
  68. gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &age);
  69. sprintf(buf,"GPS time: %d/%02d/%02d %02d:%02d:%02d", year, month, day, hour, minutes, second);
  70. Serial.println(buf);
  71. gps.stats(&chars, &sentences, &failed);
  72. Serial.print(" CHARS=");
  73. Serial.print(chars);
  74. Serial.print(" SENTENCES=");
  75. Serial.print(sentences);
  76. Serial.print(" CSUM ERR=");
  77. Serial.println(failed);
  78. if (chars == 0)
  79. Serial.println("** No characters received from GPS: check wiring **");
  80. }