SHARE
TWEET

Untitled

a guest Jun 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Libraries necessary for the board to function
  2. #include <TinyGPS++.h>
  3. #include <SoftwareSerial.h>
  4. #include <LiquidCrystal.h>
  5. #include <avr/wdt.h>
  6.  
  7. //Setting the pins necessary for the LCD screen
  8. LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
  9.  
  10. // Setting the pins for the GPS unit. When plugging these in to the Arduino, they should be swapped.
  11. // i.e, RXPin should go to 7, TXPin should go to 6
  12. static const int RXPin = 6, TXPin = 7;
  13. static const uint32_t GPSBaud = 9600;
  14.  
  15. // Declaring GPS object
  16. TinyGPSPlus gps;
  17.  
  18. // The serial connection to the GPS device
  19. SoftwareSerial ss(RXPin, TXPin);
  20.  
  21. // Button pin
  22. int recordGPS = 5;
  23.  
  24. void setup() {
  25.    // Setting up the watchdog timer for two seconds
  26.    wdt_enable(WDTO_2S);
  27.  
  28.    // Enabling the LCD screen
  29.    lcd.begin(16, 2);                 //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high
  30.    lcd.clear();
  31.    
  32.    Serial.begin(9600);
  33.    ss.begin(GPSBaud);
  34.    
  35.    pinMode(recordGPS, INPUT_PULLUP);
  36.    
  37.    // Setting up the initial columns for the CSV file. This allows for the GPS visualizer site to read the file with no further user intervention
  38.    Serial.println(F("latitude,longitude"));
  39. }
  40.  
  41. void loop() {
  42.   // Checks to see if the button is being pressed
  43.   if(digitalRead(recordGPS) == LOW){
  44.     // Will run the code if the GPS unit is sending data
  45.     while (ss.available() > 0){
  46.     // Puts the incoming raw GPS data through the TinyGPS ++ method
  47.     if (gps.encode(ss.read())){
  48.       displayInfo();
  49.     }
  50.   }
  51.     // If the GPS doesn't send any data for 5 seconds, it will run this code.
  52.     if (millis() > 5000 && gps.charsProcessed() < 10){
  53.       Serial.println(F("No GPS detected: check wiring."));
  54.       lcd.setCursor(0,0);
  55.       lcd.print("No GPS detected");
  56.     }
  57.   }
  58.  
  59.   // If the button hasn't been pressed, it will run this code.
  60.   else if(digitalRead(recordGPS) == HIGH){
  61.     lcd.setCursor(0,0);
  62.     lcd.print("Press button to");
  63.     lcd.setCursor(0,1);
  64.     lcd.print("start drawing.");
  65.     lcd.print("        ");
  66.   }
  67.  
  68.   // Resets the code after 2 seconds
  69.   wdt_reset();
  70. }
  71.  
  72. void displayInfo(){
  73.   // If the GPS data is valid, it will run this code
  74.   if (gps.location.isValid()){
  75.     // Prints the latitude and longitude to the Serial prompt
  76.     Serial.print(gps.location.lat(), 6);
  77.     Serial.print(",");
  78.     Serial.print(gps.location.lng(), 6);
  79.  
  80.     // Prints the latitude and longitude to the LCD screen
  81.     lcd.setCursor(0,0);
  82.     lcd.print("Lat: "); lcd.print(gps.location.lat(), 6);
  83.     lcd.setCursor(0,1);
  84.     lcd.print("Long: "); lcd.print(gps.location.lng(), 6);
  85.   }
  86.   else{
  87.     Serial.print(F("INVALID"));
  88.   }
  89.   Serial.println();
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top