Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "GPS Logging"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-02-11 13:59:07
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* log the position every 10 seconds and write to the */
- /* Micro SD card for offline loading into Google maps */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <SdFat.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- float getLatitude(); // Function declaration
- float getLongitude(); // Function declaration
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t GPS_SDCardModule_SPI_PIN_MOSI_D11 = 11;
- const uint8_t GPS_SDCardModule_SPI_PIN_MISO_D12 = 12;
- const uint8_t GPS_SDCardModule_SPI_PIN_SCLK_D13 = 13;
- const uint8_t GPS_SDCardModule_SPI_PIN_CS_D10 = 10;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- SdFat sd;
- SdFile file;
- // Variable to track time
- unsigned long lastLogTime = 0;
- const unsigned long logInterval = 10000; // Log position every 10 seconds
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(GPS_SDCardModule_SPI_PIN_CS_D10, OUTPUT);
- // start the SPI library:
- SPI.begin();
- // Initialize the SD card
- if (!sd.begin(GPS_SDCardModule_SPI_PIN_CS_D10, SPI_HALF_SPEED))
- {
- // SD card initialization failed
- while (1);
- }
- // Create a new file on the SD card
- if (!file.open("position_log.txt", O_WRITE | O_CREAT | O_TRUNC))
- {
- // File creation failed
- while (1);
- }
- // Write header to the file
- file.println("Latitude,Longitude");
- // Close the file
- file.close();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Check if it's time to log the position
- if (millis() - lastLogTime >= logInterval)
- {
- // Update the last log time
- lastLogTime = millis();
- // Get the GPS position
- float latitude = getLatitude();
- float longitude = getLongitude();
- // Open the file in append mode
- if (!file.open("position_log.txt", O_WRITE | O_APPEND))
- {
- // File opening failed
- while (1);
- }
- // Write the position to the file
- file.print(latitude);
- file.print(",");
- file.println(longitude);
- // Close the file
- file.close();
- }
- }
- // Function definition for getLatitude()
- float getLatitude()
- {
- // Your code to retrieve the latitude from the GPS module
- }
- // Function definition for getLongitude()
- float getLongitude()
- {
- // Your code to retrieve the longitude from the GPS module
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement