1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
   | // TEST GPS AVEC ARDUINO UNO ET MODULE GPS //
//
#include <TinyGPS.h>
#include <SoftwareSerial.h>/   
SoftwareSerial GPS(2,3); // configure software serial port ( tx,rx )
// Create an instance of the TinyGPS object
TinyGPS shield;
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,2);
void setup()
{
  lcd.begin(16, 2);
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   *JEAN-MARC*");
  lcd.setCursor(0,1);
  lcd.print("     test GPS");  
  GPS.begin(9600);
  delay(5000);
}
// The getgps function will interpret data from GPS and display on serial monitor
void getgps(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  shield.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
  lcd.clear();
  // Print data and time
  lcd.setCursor(0,0);
  lcd.print("GMT- : ");
  lcd.print(hour+1, DEC);
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
    lcd.print(minute, DEC);
  } 
  else if (minute>=10)
  {
    lcd.print(minute, DEC);
  }
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
    lcd.print(second, DEC);
  } 
  else if (second>=10)
  {
    lcd.print(second, DEC);
  }
  lcd.setCursor(0,1);
  lcd.print("DATE : ");  
  lcd.print(day, DEC);
  lcd.print("/");
  lcd.print(month, DEC);
  lcd.print("/");
  lcd.print(year, DEC);
  delay(5000);
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  lcd.clear();
  shield.f_get_position(&latitude, &longitude);
  lcd.setCursor(0,0);
  lcd.print("Lat : "); 
  lcd.print(latitude,5); 
  lcd.print("  ");
  lcd.setCursor(0,1);
  lcd.print("Long: "); 
  lcd.print(longitude,5);
  lcd.print(" ");
  delay(5000);  
}
void loop()
{
  byte a;
  if ( GPS.available() > 0 ) // if there is data coming from the GPS shield
  {
    a = GPS.read(); // get the byte of data
    if(shield.encode(a)) // if there is valid GPS data...
    {
      getgps(shield); // then grab the data and display it on the LCD
    }
  }
} | 
Partager