#include #include #include #include /*Déclaration écran LCD*/ #define RS 8 // Register Select #define E 9 // Enable #define D4 4 // Ligne de données 4 #define D5 5 // Ligne de données 5 #define D6 6 // Ligne de données 6 #define D7 7 // Ligne de données 7 /*Déclaration port série pour connexion au GPS*/ #define RX 10 // Port software RX #define TX 11 // Port software TX /*Déclaration Ports reliés au Relais, LED, Fuseau horaire*/ #define PINRELAIS 3 #define PINLED 13 #define TIMEZONE 2 //GMT +2:00 /*Déclaration vitesse minimale*/ const int speedmini = 3; TinyGPS gps; SoftwareSerial ss(RX, TX); LiquidCrystal lcd(RS, E, D4, D5, D6, D7); //LCD driver pins long lat, lon; unsigned long fix_age, time, date, speed; unsigned short sentences, failed_checksum; int year; byte month, day, hour, minute, second, hundredths; long alt; int counter; String s_lat,s_long, s_speed, s_alt; float currentspeed = 0; long currentalt = 0; byte posrelais = 0; String formatcoord(long coord, byte typecoord) { char buff[16]; float x=(float) (coord/1000000.00); char str_val[14]; dtostrf(abs(x), 14, 4, str_val); if ((x>=0) and (typecoord==0)) { sprintf(buff, "N %s", str_val); } if ((x>=0) and (typecoord==1)) { sprintf(buff, "E %s", str_val); } if ((x<0) and (typecoord==0)) { sprintf(buff, "S %s", str_val); } if ((x<0) and (typecoord==1)) { sprintf(buff, "W %s", str_val); } return buff; } String formatval(float val) { char str_val[10]; dtostrf(val, 3, 1, str_val); return str_val; } void LAT(){ //Latitude state lcd.setCursor(0,0); // set the LCD cursor position lcd.print(s_lat); } void LON(){ //Longitude state lcd.setCursor(0,1); // set the LCD cursor position lcd.print(s_long); } void setup() { Serial.begin(115200); //vitesse sortie PC ss.begin(9600); //vitesse connexion GPS pinMode(PINLED, OUTPUT); //Led pinMode(PINRELAIS, OUTPUT); //Relais digitalWrite(PINRELAIS,LOW); lcd.begin(16, 2); // start the library lcd.setCursor(0,0); // set the LCD cursor position lcd.print("Christophe's GPS"); // print a simple message on the LCD lcd.setCursor(0,1); // set the LCD cursor position lcd.print("Aero Info - 2021"); // print a simple message on the LCD delay(2000); counter = -1; } String formatdatetime(int d,int m,int y,int hr,int mn, int sec) { char buff[19]; if (sec>=0) { sprintf(buff, "%02d/%02d/%04d %02d:%02d:%02d",d,m,y,hr,mn,sec); } else { sprintf(buff, "%02d/%02d/%04d %02d:%02d",d,m,y,hr,mn); } return buff; } void Date_Time() { lcd.setCursor(0,0); // set the LCD cursor position lcd.print(formatdatetime(day,month,year,hour + TIMEZONE,minute,-1)); } void Altitude(){ lcd.setCursor(0,1); // set the LCD cursor position lcd.print("Alt: "); if (currentalt<10000) { lcd.print("0"); } if (currentalt<1000) { lcd.print("0"); } if (currentalt<100) { lcd.print("0"); } if (currentalt<10) { lcd.print("0"); } lcd.print(currentalt); lcd.print(" m "); } void Satellites(){ lcd.setCursor(0,1); // set the LCD cursor position lcd.print("Satellites: "); lcd.print(gps.satellites()); lcd.print(" "); } void Speed(){ lcd.setCursor(0,0); // set the LCD cursor position lcd.print("Speed: "); if (currentspeed<100) { lcd.print("0"); } if (currentspeed<10) { lcd.print("0"); } lcd.print(currentspeed,1); lcd.print(" Kts"); } void DataInvalid() { lcd.setCursor(0,0); // set the LCD cursor position lcd.print("Christophe's GPS "); // print a simple message on the LCD lcd.setCursor(0,1); // set the LCD cursor position lcd.print("NO GPS DATA "); } void loop() { while (ss.available()) { digitalWrite(PINLED, HIGH); int c = ss.read(); // Read the GPS data if (gps.encode(c)) // Check the GPS data { // process new gps info here } } digitalWrite(PINLED, LOW); gps.get_position(&lat, &lon, &fix_age); // retrieves +/- lat/long in 100000ths of a degree gps.get_datetime(&date, &time, &fix_age); // time in hhmmsscc, date in ddmmyy gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &fix_age); byte nbsat=gps.satellites(); counter++; // arrondi de la vitesse currentspeed = (float) ((int) gps.f_speed_knots()*10) / 10; if (currentspeed3)) { posrelais = 1; digitalWrite(PINRELAIS,HIGH); } } // arrondi de l'altitude currentalt = (int)((int) gps.f_altitude() * 10) / 10; s_lat=formatcoord(lat,0); s_long=formatcoord(lon,1); if ((nbsat<0) or (nbsat==255)) { if (counter%10==0) { DataInvalid(); } } else { if (counter >= 0 && counter <=500) { LAT(); LON(); } if (counter >= 501 && counter <=1000) { Date_Time(); Satellites(); } if (counter >= 1001 && counter <=1500) { Speed(); Altitude(); } if ((counter == 1500 ) or (counter == 750 )) { s_lat.replace(" ", ""); s_lat.replace("N", "N-"); s_lat.replace("S", "S-"); s_long.replace(" ", ""); s_long.replace("W", "W-"); s_long.replace("E", "E-"); s_speed=formatval(currentspeed); s_speed.replace(" ", ""); s_alt=formatval(currentalt); s_alt.replace(" ", ""); Serial.print(formatdatetime(day,month,year,hour + TIMEZONE,minute,second)+";"); Serial.print(s_lat+";"+s_long+";"); Serial.print(s_speed+";kts;"+s_alt+";m;"); Serial.print(nbsat); Serial.print(";nbsat;"); Serial.println(posrelais); } } if (counter > 1500) { counter = 0; } }