Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Libraries necessary for the board to function
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include <LiquidCrystal.h>
- #include <avr/wdt.h>
- //Setting the pins necessary for the LCD screen
- LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
- // Setting the pins for the GPS unit. When plugging these in to the Arduino, they should be swapped.
- // i.e, RXPin should go to 7, TXPin should go to 6
- static const int RXPin = 6, TXPin = 7;
- static const uint32_t GPSBaud = 9600;
- // Declaring GPS object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial ss(RXPin, TXPin);
- // Button pin
- int recordGPS = 5;
- void setup() {
- // Setting up the watchdog timer for two seconds
- wdt_enable(WDTO_2S);
- // Enabling the LCD screen
- lcd.begin(16, 2); //tell the lcd library that we are using a display that is 16 characters wide and 2 characters high
- lcd.clear();
- Serial.begin(9600);
- ss.begin(GPSBaud);
- pinMode(recordGPS, INPUT_PULLUP);
- // 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
- Serial.println(F("latitude,longitude"));
- }
- void loop() {
- // Checks to see if the button is being pressed
- if(digitalRead(recordGPS) == LOW){
- // Will run the code if the GPS unit is sending data
- while (ss.available() > 0){
- // Puts the incoming raw GPS data through the TinyGPS ++ method
- if (gps.encode(ss.read())){
- displayInfo();
- }
- }
- // If the GPS doesn't send any data for 5 seconds, it will run this code.
- if (millis() > 5000 && gps.charsProcessed() < 10){
- Serial.println(F("No GPS detected: check wiring."));
- lcd.setCursor(0,0);
- lcd.print("No GPS detected");
- }
- }
- // If the button hasn't been pressed, it will run this code.
- else if(digitalRead(recordGPS) == HIGH){
- lcd.setCursor(0,0);
- lcd.print("Press button to");
- lcd.setCursor(0,1);
- lcd.print("start drawing.");
- lcd.print(" ");
- }
- // Resets the code after 2 seconds
- wdt_reset();
- }
- void displayInfo(){
- // If the GPS data is valid, it will run this code
- if (gps.location.isValid()){
- // Prints the latitude and longitude to the Serial prompt
- Serial.print(gps.location.lat(), 6);
- Serial.print(",");
- Serial.print(gps.location.lng(), 6);
- // Prints the latitude and longitude to the LCD screen
- lcd.setCursor(0,0);
- lcd.print("Lat: "); lcd.print(gps.location.lat(), 6);
- lcd.setCursor(0,1);
- lcd.print("Long: "); lcd.print(gps.location.lng(), 6);
- }
- else{
- Serial.print(F("INVALID"));
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement