I have a lot of boards and usually need to re-use code even for different projects.

m5-gps-left.ino 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <TinyGPS++.h>
  2. #include <wiring_private.h>
  3. static const uint32_t GPSBaud = 115200;
  4. // The TinyGPS++ object
  5. TinyGPSPlus gps;
  6. // The serial connection to the GPS device - Left side Grove connector.
  7. // Left side Grove connector shares pins with I2C1 of 40 pin connector.
  8. static Uart Serial3(&sercom3, PIN_WIRE_SCL, PIN_WIRE_SDA, SERCOM_RX_PAD_1, UART_TX_PAD_0);
  9. void setup()
  10. {
  11. Serial.begin(115200);
  12. Serial3.begin(GPSBaud);
  13. pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
  14. pinPeripheral(PIN_WIRE_SCL, PIO_SERCOM_ALT);
  15. }
  16. void loop()
  17. {
  18. // This sketch displays information every time a new sentence is correctly encoded.
  19. while (Serial3.available() > 0)
  20. if (gps.encode(Serial3.read()))
  21. displayInfo();
  22. if (millis() > 5000 && gps.charsProcessed() < 10)
  23. {
  24. Serial.println(F("No GPS detected: check wiring."));
  25. while(true);
  26. }
  27. }
  28. void displayInfo()
  29. {
  30. Serial.print(F("Location: "));
  31. if (gps.location.isValid())
  32. {
  33. Serial.print(gps.location.lat(), 6);
  34. Serial.print(F(","));
  35. Serial.print(gps.location.lng(), 6);
  36. }
  37. else
  38. {
  39. Serial.print(F("INVALID"));
  40. }
  41. Serial.print(F(" Date/Time: "));
  42. if (gps.date.isValid())
  43. {
  44. Serial.print(gps.date.month());
  45. Serial.print(F("/"));
  46. Serial.print(gps.date.day());
  47. Serial.print(F("/"));
  48. Serial.print(gps.date.year());
  49. }
  50. else
  51. {
  52. Serial.print(F("INVALID"));
  53. }
  54. Serial.print(F(" "));
  55. if (gps.time.isValid())
  56. {
  57. if (gps.time.hour() < 10) Serial.print(F("0"));
  58. Serial.print(gps.time.hour());
  59. Serial.print(F(":"));
  60. if (gps.time.minute() < 10) Serial.print(F("0"));
  61. Serial.print(gps.time.minute());
  62. Serial.print(F(":"));
  63. if (gps.time.second() < 10) Serial.print(F("0"));
  64. Serial.print(gps.time.second());
  65. Serial.print(F("."));
  66. if (gps.time.centisecond() < 10) Serial.print(F("0"));
  67. Serial.print(gps.time.centisecond());
  68. }
  69. else
  70. {
  71. Serial.print(F("INVALID"));
  72. }
  73. Serial.println();
  74. }
  75. void SERCOM3_0_Handler()
  76. {
  77. Serial3.IrqHandler();
  78. }
  79. void SERCOM3_1_Handler()
  80. {
  81. Serial3.IrqHandler();
  82. }
  83. void SERCOM3_2_Handler()
  84. {
  85. Serial3.IrqHandler();
  86. }
  87. void SERCOM3_3_Handler()
  88. {
  89. Serial3.IrqHandler();
  90. }