Étape 3: Le codage
Faire le codage pour votre Arduino est simple, vous pouvez copier l’exemple de code et/ou le modifier pour votre propre usage.Ce code envoie toutes les chaînes reçues du GPS par le biais de série à votre ordinateur (Serial Monitor)
Remarque : voir les commentaires dans le codage pour le filtrage de certaines chaînes
#include // GPS Setup #define rxGPS 3 #define txGPS 5 SoftwareSerial serialGPS = SoftwareSerial(rxGPS, txGPS); String stringGPS = ""; void setup() { pinMode(rxGPS, INPUT); pinMode(txGPS, OUTPUT); Serial.begin(9600); Serial.println("Started"); // GPS Setup serialGPS.begin(4800); digitalWrite(txGPS,HIGH); // Cut first gibberish while(serialGPS.available()) if (serialGPS.read() == '\r') break; } void loop() { String s = checkGPS(); if(s && s.substring(0, 6) == "$GPGGA") { Serial.println(s); } } // Check GPS and returns string if full line recorded, else false String checkGPS() { if (serialGPS.available()) { char c = serialGPS.read(); if (c != '\n' && c != '\r') { stringGPS = c; } else { if (stringGPS != "") { String tmp = stringGPS; stringGPS = ""; return tmp; } } } return false; }