Advertisement
pleasedontcode

**GPS Communication** rev_01

Nov 27th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **GPS Communication**
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-11-28 02:53:38
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Show real time gps on map */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SoftwareSerial.h>
  27. #include <Sim800L.h>    //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  28. #include <TinyGPS++.h> // Include TinyGPS++ library for GPS functionality
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs();
  34. void fetchGPSData(); // Function to fetch GPS data
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t Kkk_SIM800L_RING_PIN_D3       = 3;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t Kkk_SIM800L_RST_PIN_D2        = 2;
  41. const uint8_t Kkk_SIM800L_DTR_PIN_D4        = 4;
  42.  
  43. /***** DEFINITION OF Software Serial *****/
  44. const uint8_t Kkk_SIM800L_Serial_PIN_SERIAL_TX_A0       = A0;
  45. const uint8_t Kkk_SIM800L_Serial_PIN_SERIAL_RX_A1       = A1;
  46. SoftwareSerial Kkk_SIM800L_Serial(Kkk_SIM800L_Serial_PIN_SERIAL_RX_A1, Kkk_SIM800L_Serial_PIN_SERIAL_TX_A0);
  47.  
  48. // Define GPS Serial
  49. const uint8_t GPS_SERIAL_TX_PIN = A2; // TX pin for GPS
  50. const uint8_t GPS_SERIAL_RX_PIN = A3; // RX pin for GPS
  51. SoftwareSerial GPS_Serial(GPS_SERIAL_RX_PIN, GPS_SERIAL_TX_PIN); // Create a SoftwareSerial object for GPS
  52.  
  53. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  54. bool    Kkk_SIM800L_RST_PIN_D2_rawData      = 0;
  55. bool    Kkk_SIM800L_DTR_PIN_D4_rawData      = 0;
  56.  
  57. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  58. float   Kkk_SIM800L_RST_PIN_D2_phyData      = 0.0;
  59. float   Kkk_SIM800L_DTR_PIN_D4_phyData      = 0.0;
  60.  
  61. // Create a TinyGPS++ object
  62. TinyGPSPlus gps;
  63.  
  64. void setup(void)
  65. {
  66.     // put your setup code here, to run once:
  67.  
  68.     pinMode(Kkk_SIM800L_RING_PIN_D3,    INPUT_PULLUP);
  69.  
  70.     pinMode(Kkk_SIM800L_RST_PIN_D2,  OUTPUT);
  71.     pinMode(Kkk_SIM800L_DTR_PIN_D4,  OUTPUT);
  72.  
  73.     Kkk_SIM800L_Serial.begin(9600);
  74.     GPS_Serial.begin(9600); // Start GPS serial communication
  75.  
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // put your main code here, to run repeatedly:
  81.  
  82.     updateOutputs(); // Refresh output data
  83.     fetchGPSData(); // Fetch GPS data and update
  84.  
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.     digitalWrite(Kkk_SIM800L_RST_PIN_D2, Kkk_SIM800L_RST_PIN_D2_rawData);
  90.     digitalWrite(Kkk_SIM800L_DTR_PIN_D4, Kkk_SIM800L_DTR_PIN_D4_rawData);
  91. }
  92.  
  93. void fetchGPSData() {
  94.     while (GPS_Serial.available()) {
  95.         gps.encode(GPS_Serial.read()); // Read data from GPS
  96.     }
  97.  
  98.     if (gps.location.isUpdated()) {
  99.         // If GPS location is updated, you can now use gps.location.lat() and gps.location.lng()
  100.         float latitude = gps.location.lat();
  101.         float longitude = gps.location.lng();
  102.         // Here you can implement code to show the GPS coordinates on a map
  103.         // For example, you can send these coordinates via SIM800L to a server
  104.     }
  105. }
  106.  
  107. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement