Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- #include <SPI.h>
- #include <SD.h>
- #include <TinyGPS.h>
- TinyGPS gps;
- // The jumpers on the shield set to work with
- // these pins, and can be changed if needed.
- // create gps object
- SoftwareSerial ss(2, 3);
- // File for logging data
- File rawdata;
- const int buttonPin = 2; // the number of the pushbutton pin
- const int ledPin = 8; // the number of the LED pin
- int buttonState = 0; // variable for reading the pushbutton status
- /**************************************************************
- Function: setup
- Purpose: set up Arduino
- Args: none
- Returns: nothing
- Notes: This function is required by the Arduino
- ***************************************************************/
- void setup()
- {
- pinMode(buttonPin, INPUT);
- // initialize the push button pin as an input
- pinMode(buttonPin, OUTPUT);
- // initialize the LED as an output
- // Serial monitor
- Serial.begin(9600);
- // baud rate for GPS - 38400 is prefered, but 4800 can also be used
- ss.begin(38400);
- // Comments from TinyGPS simple_test example
- Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
- Serial.println("by Mikal Hart");
- Serial.println();
- // Initialize card
- Serial.print("Initializing SD card...");
- pinMode(10, OUTPUT);
- if (!SD.begin(10)) {
- Serial.println("...initialization failed!");
- }
- else
- Serial.println("...initialization done.");
- }
- /**************************************************************
- Function: loop
- Purpose: loop funtion for Arduino
- Args: none
- Returns: nothing
- Notes: This function is required by the Arduino, and the
- Arduino will loop through this function indefinately.
- ***************************************************************/
- void loop(){
- bool newData = false;
- unsigned long chars;
- unsigned short sentences, failed;
- // Open data file
- File rawdata = SD.open("rawdata.txt", FILE_WRITE);
- // For one second we parse GPS data and report some key values
- buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
- for (unsigned long start = millis(); millis() - start < 1000;)
- {
- if(buttonState == HIGH){
- // turn LED on
- delay(500);
- digitalWrite(ledPin, HIGH);
- while (ss.available())
- {
- char c = ss.read(); //GPS data flowing
- // Send raw data to the terminal window
- Serial.write(c);
- // Send raw data to the SD card
- if(rawdata)
- rawdata.write(c);
- if (gps.encode(c)) // if there is a new valid sentence
- newData = true;
- }
- }
- // Send manipulate data to the terminal window.
- /*
- if (newData)
- {
- float flat, flon;
- unsigned long age;
- gps.f_get_position(&flat, &flon, &age);
- Serial.print("LAT=");
- Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
- Serial.print(" LON=");
- Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
- Serial.print(" SAT=");
- Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
- Serial.print(" PREC=");
- Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
- }
- */
- // Send a carriage return and close the file
- Serial.println("");
- rawdata.write("\r");
- rawdata.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement