RichieHard

Untitled

Oct 30th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. //#define RESET 12
  2. #define FORCE_ON 13
  3.  
  4. String NMEA;
  5. int posizione_delimitatore = 0;
  6. int altro = 0;
  7. int campo = 0;
  8. String n, e;
  9. double mslm;
  10.  
  11. void setup() {
  12. // put your setup code here, to run once:
  13. //Initialize serial and wait for port to open:
  14.  
  15.  
  16. // Initialize serial devices at 9600 bauds
  17. Serial.begin(9600);
  18. Serial1.begin(9600);
  19.  
  20. // Wait for the serial device to be ready
  21. while (!Serial);
  22. while (!Serial1);
  23.  
  24.  
  25. // Set PIN direction
  26.  
  27. //pinMode(RESET, OUTPUT);
  28. pinMode(FORCE_ON, OUTPUT);
  29.  
  30. // Reset, at least 100ms
  31. //digitalWrite(RESET, HIGH);
  32. delay(50);
  33. //digitalWrite(RESET, LOW);
  34. delay(50);
  35. //digitalWrite(RESET, HIGH);
  36.  
  37. digitalWrite(FORCE_ON, HIGH);
  38.  
  39.  
  40. // prints title with ending line break
  41. Serial.println("Serial shifter initialized");
  42. }
  43.  
  44. void loop() {
  45. if (Serial1.available()) {
  46. char c = (char)Serial1.read(); // @@@ SE NON FUNZIONA QUESTO
  47. //char c = ((char)Serial1.read()); // @@@ PROVA ST'ALTRO
  48. if (c != '\n') {
  49. NMEA += c;
  50. }
  51. else {
  52. posizione_delimitatore = 0;
  53. altro = 0;
  54. campo = 0;
  55. //if (NMEA.substring(0, 6) == "$GPGGA") //@@@$GPGGA è la riga che ci interessa, contiene Latitudine, Longitudine e Altimetria (m slm)
  56. if (NMEA.substring(0) == "$GPGGA") //
  57. {
  58. Serial.println("RIGA COMPLETA DA CUI ESTRAPOLEREMO I DATI"); //@@@ RIGHE DI PROVA
  59. Serial.println(NMEA); //@@@ RIGHE DI PROVA
  60. Serial.println(); //@@@ RIGHE DI PROVA
  61. while (posizione_delimitatore != -1)
  62. {
  63. posizione_delimitatore = NMEA.indexOf(",", altro);
  64. switch (campo)
  65. {
  66. //@@@ adesso andiamo ad inserire i campi della stringa GPGGA che ci interessano; i campi sono separati da virgole e iniziano da zero quindi $GPGGA è il campo zero e così via...
  67. //@@@ case 3 significa quindi che sto cercando nel terzo campo. Se ho sbagliato ti basta modificare il numero con il n° di campo giusto
  68.  
  69. case 3: n = NMEA.substring(altro, posizione_delimitatore).c_str(); //@@@ CAMPO DELLA LATITUDINE
  70. Serial.println("DATI ESTRAPOLATI");
  71. Serial.print(n);
  72. Serial.println(" N");
  73. Serial.println();
  74. break;
  75.  
  76. case 5: e = NMEA.substring(altro, posizione_delimitatore).c_str(); //@@@ CAMPO DELLA LONGITUDINE
  77. Serial.print(e);
  78. Serial.println(" E");
  79. Serial.println();
  80. break;
  81.  
  82. case 10: mslm = ((atof((NMEA.substring(altro, posizione_delimitatore)).c_str())) / 10);//@@@ CAMPO DELL'ALTIMETRIA
  83. Serial.print(mslm);
  84. Serial.println(" m s.l.m.");
  85. Serial.println();
  86. break;
  87.  
  88. }
  89. altro = posizione_delimitatore;
  90. altro++;
  91. campo++;
  92. }
  93. delay(3000); //@@@ DELAY INSERITO PER LEGGERE PIù CHIARAMENTE IL MONITOR SERIALE, MAGARI RIDUCILO A 10 ms QUANDO LO CARICHI DEFINITIVAMENTE
  94. }
  95. NMEA = "";
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment