Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define RESET 12
- #define FORCE_ON 13
- String NMEA;
- int posizione_delimitatore = 0;
- int altro = 0;
- int campo = 0;
- String n, e;
- double mslm;
- void setup() {
- // put your setup code here, to run once:
- //Initialize serial and wait for port to open:
- // Initialize serial devices at 9600 bauds
- Serial.begin(9600);
- Serial1.begin(9600);
- // Wait for the serial device to be ready
- while (!Serial);
- while (!Serial1);
- // Set PIN direction
- //pinMode(RESET, OUTPUT);
- pinMode(FORCE_ON, OUTPUT);
- // Reset, at least 100ms
- //digitalWrite(RESET, HIGH);
- delay(50);
- //digitalWrite(RESET, LOW);
- delay(50);
- //digitalWrite(RESET, HIGH);
- digitalWrite(FORCE_ON, HIGH);
- // prints title with ending line break
- Serial.println("Serial shifter initialized");
- }
- void loop() {
- if (Serial1.available()) {
- char c = (char)Serial1.read(); // @@@ SE NON FUNZIONA QUESTO
- //char c = ((char)Serial1.read()); // @@@ PROVA ST'ALTRO
- if (c != '\n') {
- NMEA += c;
- }
- else {
- posizione_delimitatore = 0;
- altro = 0;
- campo = 0;
- //if (NMEA.substring(0, 6) == "$GPGGA") //@@@$GPGGA è la riga che ci interessa, contiene Latitudine, Longitudine e Altimetria (m slm)
- if (NMEA.substring(0) == "$GPGGA") //
- {
- Serial.println("RIGA COMPLETA DA CUI ESTRAPOLEREMO I DATI"); //@@@ RIGHE DI PROVA
- Serial.println(NMEA); //@@@ RIGHE DI PROVA
- Serial.println(); //@@@ RIGHE DI PROVA
- while (posizione_delimitatore != -1)
- {
- posizione_delimitatore = NMEA.indexOf(",", altro);
- switch (campo)
- {
- //@@@ 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...
- //@@@ case 3 significa quindi che sto cercando nel terzo campo. Se ho sbagliato ti basta modificare il numero con il n° di campo giusto
- case 3: n = NMEA.substring(altro, posizione_delimitatore).c_str(); //@@@ CAMPO DELLA LATITUDINE
- Serial.println("DATI ESTRAPOLATI");
- Serial.print(n);
- Serial.println(" N");
- Serial.println();
- break;
- case 5: e = NMEA.substring(altro, posizione_delimitatore).c_str(); //@@@ CAMPO DELLA LONGITUDINE
- Serial.print(e);
- Serial.println(" E");
- Serial.println();
- break;
- case 10: mslm = ((atof((NMEA.substring(altro, posizione_delimitatore)).c_str())) / 10);//@@@ CAMPO DELL'ALTIMETRIA
- Serial.print(mslm);
- Serial.println(" m s.l.m.");
- Serial.println();
- break;
- }
- altro = posizione_delimitatore;
- altro++;
- campo++;
- }
- delay(3000); //@@@ DELAY INSERITO PER LEGGERE PIù CHIARAMENTE IL MONITOR SERIALE, MAGARI RIDUCILO A 10 ms QUANDO LO CARICHI DEFINITIVAMENTE
- }
- NMEA = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment