Advertisement
microrobotics

ATGM336H GPS module

May 4th, 2023
4,525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The ATGM336H GPS module is a compact GPS module that communicates via UART. You can use it with an Arduino board and the TinyGPS++ library to read GPS data. Here's a simple example:
  3.  
  4. First, download and install the TinyGPS++ library from https://github.com/mikalhart/TinyGPSPlus/releases
  5.  
  6. Connect your ATGM336H GPS module to the Arduino board as follows:
  7.  
  8. GPS module VCC to Arduino 3.3V
  9. GPS module GND to Arduino GND
  10. GPS module TX to Arduino pin 8 (RX)
  11. GPS module RX to Arduino pin 7 (TX)
  12.  
  13. Open the Serial Monitor in the Arduino IDE and set the baud rate to 9600. You should see the GPS coordinates displayed when new data is received from the GPS module.
  14. */
  15.  
  16. #include <SoftwareSerial.h>
  17. #include <TinyGPS++.h>
  18.  
  19. #define RX_PIN 8
  20. #define TX_PIN 7
  21. #define BAUD_RATE 9600
  22.  
  23. SoftwareSerial gpsSerial(RX_PIN, TX_PIN);
  24. TinyGPSPlus gps;
  25.  
  26. void setup() {
  27.   Serial.begin(BAUD_RATE);
  28.   gpsSerial.begin(BAUD_RATE);
  29.   Serial.println("GPS module initialized.");
  30. }
  31.  
  32. void loop() {
  33.   while (gpsSerial.available()) {
  34.     gps.encode(gpsSerial.read());
  35.   }
  36.  
  37.   if (gps.location.isUpdated()) {
  38.     float latitude = gps.location.lat();
  39.     float longitude = gps.location.lng();
  40.    
  41.     Serial.print("Latitude: ");
  42.     Serial.println(latitude, 6);
  43.     Serial.print("Longitude: ");
  44.     Serial.println(longitude, 6);
  45.   }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement