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 Communication**
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2024-11-28 02:53:38
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Show real time gps on map */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- #include <Sim800L.h> //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
- #include <TinyGPS++.h> // Include TinyGPS++ library for GPS functionality
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void fetchGPSData(); // Function to fetch GPS data
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Kkk_SIM800L_RING_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Kkk_SIM800L_RST_PIN_D2 = 2;
- const uint8_t Kkk_SIM800L_DTR_PIN_D4 = 4;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t Kkk_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
- const uint8_t Kkk_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
- SoftwareSerial Kkk_SIM800L_Serial(Kkk_SIM800L_Serial_PIN_SERIAL_RX_A1, Kkk_SIM800L_Serial_PIN_SERIAL_TX_A0);
- // Define GPS Serial
- const uint8_t GPS_SERIAL_TX_PIN = A2; // TX pin for GPS
- const uint8_t GPS_SERIAL_RX_PIN = A3; // RX pin for GPS
- SoftwareSerial GPS_Serial(GPS_SERIAL_RX_PIN, GPS_SERIAL_TX_PIN); // Create a SoftwareSerial object for GPS
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool Kkk_SIM800L_RST_PIN_D2_rawData = 0;
- bool Kkk_SIM800L_DTR_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float Kkk_SIM800L_RST_PIN_D2_phyData = 0.0;
- float Kkk_SIM800L_DTR_PIN_D4_phyData = 0.0;
- // Create a TinyGPS++ object
- TinyGPSPlus gps;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Kkk_SIM800L_RING_PIN_D3, INPUT_PULLUP);
- pinMode(Kkk_SIM800L_RST_PIN_D2, OUTPUT);
- pinMode(Kkk_SIM800L_DTR_PIN_D4, OUTPUT);
- Kkk_SIM800L_Serial.begin(9600);
- GPS_Serial.begin(9600); // Start GPS serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- fetchGPSData(); // Fetch GPS data and update
- }
- void updateOutputs()
- {
- digitalWrite(Kkk_SIM800L_RST_PIN_D2, Kkk_SIM800L_RST_PIN_D2_rawData);
- digitalWrite(Kkk_SIM800L_DTR_PIN_D4, Kkk_SIM800L_DTR_PIN_D4_rawData);
- }
- void fetchGPSData() {
- while (GPS_Serial.available()) {
- gps.encode(GPS_Serial.read()); // Read data from GPS
- }
- if (gps.location.isUpdated()) {
- // If GPS location is updated, you can now use gps.location.lat() and gps.location.lng()
- float latitude = gps.location.lat();
- float longitude = gps.location.lng();
- // Here you can implement code to show the GPS coordinates on a map
- // For example, you can send these coordinates via SIM800L to a server
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement